|
1 | 1 | import {Callout} from "nextra-theme-docs"; |
2 | 2 | import {OptionTable} from "../../components/env-table"; |
| 3 | +import AsciinemaPlayer from "../../components/asciinema-player/player"; |
3 | 4 |
|
4 | 5 | # ORM Commands |
5 | 6 |
|
6 | | -The following commands are available for managing the ORM. |
| 7 | +ORM commands facilitate the management of the Object-Relational Mapping layer, allowing for the initialization and updating of schemas, migration generation, schema visualization, and direct synchronization with the database. |
7 | 8 |
|
8 | 9 | ### Command Reference Table |
9 | 10 |
|
@@ -36,3 +37,105 @@ export const commands = [ |
36 | 37 | }))} |
37 | 38 | columns={columns} |
38 | 39 | /> |
| 40 | + |
| 41 | +### Initializing or Updating ORM Schema |
| 42 | + |
| 43 | +`cycle:orm` |
| 44 | + |
| 45 | +This command initializes or updates the Cycle ORM schema by analyzing the database structure and annotated classes. |
| 46 | + |
| 47 | +#### Usage |
| 48 | + |
| 49 | +```bash |
| 50 | +php artisan cycle:orm |
| 51 | +``` |
| 52 | + |
| 53 | +### Generating ORM Schema Migrations |
| 54 | + |
| 55 | +`cycle:orm:migrate` |
| 56 | + |
| 57 | +Use this command to generate migrations based on the current ORM schema. It's a crucial step for evolving the database schema in a controlled manner. |
| 58 | + |
| 59 | +#### Usage |
| 60 | + |
| 61 | +```bash |
| 62 | +php artisan cycle:orm:migrate |
| 63 | +``` |
| 64 | + |
| 65 | +#### Options |
| 66 | + |
| 67 | +- `--r|run` - Automatically run generated migration. |
| 68 | +- `--s|split` - Split migration into multiple files (one per table). |
| 69 | + |
| 70 | +#### Example |
| 71 | + |
| 72 | +Recording shows migration file generation on existing Domain Entities and their relationships. |
| 73 | + |
| 74 | +<br/> |
| 75 | + |
| 76 | +<AsciinemaPlayer |
| 77 | + src="https://asciinema.org/a/Q7uli4kvEkbbzqt4LBLNlCCkE.cast" |
| 78 | + options={{ |
| 79 | + idleTimeLimit: 2, |
| 80 | + preload: true, |
| 81 | + loop: 0, |
| 82 | + speed: 1.0, |
| 83 | + theme: 'monokai', |
| 84 | + rows: 28, |
| 85 | + cols: 120, |
| 86 | + poster: "npt:0:04" |
| 87 | + }} |
| 88 | +/> |
| 89 | + |
| 90 | +### Displaying ORM Schema |
| 91 | + |
| 92 | +`cycle:orm:render` |
| 93 | + |
| 94 | +To visualize the current ORM schema directly in your console, use the `cycle:orm:render` command. This can help with understanding the structure and relationships defined in your ORM. |
| 95 | + |
| 96 | +#### Usage |
| 97 | + |
| 98 | +```bash |
| 99 | +php artisan cycle:orm:render |
| 100 | +``` |
| 101 | + |
| 102 | +#### Options |
| 103 | + |
| 104 | +- `--nc|no-color` - Display output without colors. |
| 105 | +- `--p|php` - Display output as PHP code. |
| 106 | + |
| 107 | +#### Example |
| 108 | + |
| 109 | +Recording shows the visualization of the ORM schema in the console for existing `App/Entities/Post` entity. |
| 110 | + |
| 111 | +<br/> |
| 112 | + |
| 113 | +<AsciinemaPlayer |
| 114 | + src="https://asciinema.org/a/0ZTAlr5EWbVlll86A4EKm35N1.cast" |
| 115 | + options={{ |
| 116 | + idleTimeLimit: 2, |
| 117 | + preload: true, |
| 118 | + loop: 0, |
| 119 | + speed: 1.0, |
| 120 | + theme: 'monokai', |
| 121 | + rows: 28, |
| 122 | + cols: 120, |
| 123 | + poster: "npt:0:03" |
| 124 | + }} |
| 125 | +/> |
| 126 | + |
| 127 | +### Synchronizing ORM Schema with Database |
| 128 | + |
| 129 | +`cycle:orm:sync` |
| 130 | + |
| 131 | +This command directly synchronizes the Cycle ORM schema with the database. It bypasses the migration system and applies changes directly, which can be risky. |
| 132 | + |
| 133 | +#### Usage |
| 134 | + |
| 135 | +```bash |
| 136 | +php artisan cycle:orm:sync |
| 137 | +``` |
| 138 | + |
| 139 | +<Callout type="warning" emoji="⚠️"> |
| 140 | + Be cautious when using the `cycle:orm:sync` command, as it directly alters the database schema and can potentially lead to data loss. |
| 141 | +</Callout> |
0 commit comments