|
1 |
| -# Console Commands |
| 1 | +import {Callout} from "nextra-theme-docs"; |
2 | 2 |
|
3 | 3 | This package includes CycleORM commands implemented as Laravel Console Commands, you can use them to manage your database schema and perform migrations.
|
4 | 4 |
|
5 |
| -The package extends Laravel's artisan commands, introducing a set of commands specifically designed for managing Cycle ORM migrations and database schema. These commands are intuitive for Laravel developers and follow the framework's conventions. |
| 5 | +The package extends Laravel's artisan commands, introducing a set of commands specifically designed for managing CycleORM migrations and database schema. These commands are intuitive for Laravel developers and follow the framework's conventions. |
6 | 6 |
|
7 | 7 |
|
8 | 8 | ## 🛠️ Commands for Migrations
|
9 | 9 |
|
10 |
| -The package includes a set of commands for managing migrations. These commands are similar to Laravel's migration commands, but they are designed to work with Cycle ORM. |
| 10 | +Migration commands are essential for managing your database's evolution over time. They allow for the creation, execution, rollback, and status checking of migrations. |
11 | 11 |
|
12 |
| -### Table of Contents |
| 12 | +### Command List |
13 | 13 |
|
14 |
| -| Command | Description | |
15 |
| -|--------------------------|-----------------------------------------------------------------------------------------------------------------| |
16 |
| -| `cycle:migrate` | Executes pending migrations. Use the --one flag to execute only the first pending migration. | |
17 |
| -| `cycle:migrate:replay` | Replays migrations by rolling them back and then re-applying them. Use the --all flag to replay all migrations. | |
18 |
| -| `cycle:migrate:rollback` | Rolls back the last batch of migrations by default. Use the --all flag to roll back all migrations. | |
19 |
| -| `cycle:migrate:init` | Initializes the migration system by creating the necessary migrations table. | |
20 |
| -| `cycle:migrate:status` | Displays the status of all migrations, indicating which have been applied. | |
21 |
| -| `cycle:migrate:fresh` | Drops all tables and re-runs all migrations, providing a clean slate. ⚠️ | |
| 14 | +| Command | Description | |
| 15 | +|--------------------------|-------------------------------------------------------------------------------------------------------------------| |
| 16 | +| `cycle:migrate:init` | Initializes the migration system by creating the necessary migrations table. | |
| 17 | +| `cycle:migrate` | Executes pending migrations. Use the `--one` flag to execute only the first pending migration. | |
| 18 | +| `cycle:migrate:replay` | Replays migrations by rolling them back and then re-applying them. Use the `--all` flag to replay all migrations. | |
| 19 | +| `cycle:migrate:rollback` | Rolls back the last batch of migrations by default. Use the `--all` flag to roll back all migrations. | |
| 20 | +| `cycle:migrate:status` | Displays the status of all migrations, indicating which have been applied. | |
| 21 | +| `cycle:migrate:fresh` | Drops all tables and re-runs all migrations, providing a clean slate. ⚠️ | |
22 | 22 |
|
23 |
| -### Usage |
| 23 | +### Initializing Migrations |
| 24 | + |
| 25 | +`cycle:migrate:init` |
| 26 | + |
| 27 | +This command is your starting point for migration management. It initializes the migration system by creating the necessary migrations table in your database, ensuring that you can start tracking and executing migrations. |
| 28 | + |
| 29 | +#### Usage: |
| 30 | + |
| 31 | +```bash |
| 32 | +php artisan cycle:migrate:init |
| 33 | +``` |
| 34 | + |
| 35 | +### Running Migrations |
| 36 | + |
| 37 | +`cycle:migrate` |
| 38 | + |
| 39 | +To apply pending migrations to your database, use the `cycle:migrate` command. This will execute all migrations that have not yet been applied, updating your database schema accordingly. |
| 40 | + |
| 41 | +#### Usage: |
| 42 | + |
| 43 | +```bash |
| 44 | +php artisan cycle:migrate |
| 45 | +``` |
| 46 | + |
| 47 | +#### Options: |
| 48 | + |
| 49 | +`--one`: Executes only the first pending migration, allowing for more granular control over the migration process. |
| 50 | + |
| 51 | +### Replaying Migrations |
| 52 | + |
| 53 | +`cycle:migrate:replay` |
| 54 | + |
| 55 | +This command facilitates the replaying of migrations by first rolling them back and then re-applying them. It's particularly useful for development environments where you need to quickly test changes to migrations. |
| 56 | + |
| 57 | +#### Usage: |
| 58 | + |
| 59 | +```bash |
| 60 | +php artisan cycle:migrate:replay |
| 61 | +``` |
| 62 | + |
| 63 | +#### Options: |
| 64 | + |
| 65 | +`--all`: Replays all migrations, effectively refreshing your entire database schema. |
| 66 | + |
| 67 | + |
| 68 | +### Rolling Back Migrations |
| 69 | + |
| 70 | +`cycle:migrate:rollback` |
| 71 | + |
| 72 | +To undo the last batch of migrations, you can use the `cycle:migrate:rollback` command. This is useful when you need to revert changes made by the most recent migrations. |
| 73 | + |
| 74 | +#### Usage: |
| 75 | + |
| 76 | +```bash |
| 77 | +php artisan cycle:migrate:rollback |
| 78 | +``` |
| 79 | + |
| 80 | +#### Options: |
| 81 | + |
| 82 | +`--all`: Rolls back all migrations, allowing you to revert your database schema to its initial state. |
| 83 | + |
| 84 | + |
| 85 | +### Checking Migration Status |
| 86 | + |
| 87 | +`cycle:migrate:status` |
| 88 | + |
| 89 | +Keeping track of which migrations have been applied is crucial for database management. The `cycle:migrate:status` command displays the status of all migrations, indicating which have been applied and which are pending. |
| 90 | + |
| 91 | +#### Usage: |
| 92 | + |
| 93 | +```bash |
| 94 | +php artisan cycle:migrate:status |
| 95 | +``` |
| 96 | + |
| 97 | +### Fresh Schema Command |
| 98 | + |
| 99 | +`cycle:migrate:fresh` |
| 100 | + |
| 101 | +When you need to start from a clean slate, the `cycle:migrate:fresh` command drops all tables from the database and re-runs all migrations. This is particularly useful for resetting the database to a known state during development or testing. |
| 102 | + |
| 103 | +#### Usage: |
| 104 | + |
| 105 | +```bash |
| 106 | +php artisan cycle:migrate:fresh |
| 107 | +``` |
| 108 | + |
| 109 | +<Callout type="warning" emoji="⚠️"> |
| 110 | + Be cautious when using the `cycle:migrate:fresh` command, as it will permanently delete all data in your database. |
| 111 | +</Callout> |
| 112 | + |
| 113 | +#### Options: |
| 114 | + |
| 115 | +`--seed`: Seeds the database after running the migrations, populating it with initial data. |
0 commit comments