Migration Commands

Migration Commands

Migration commands are essential for managing your database's evolution over time. They allow for the creation, execution, rollback, and status checking of migrations.

Command Reference Table

cycle:migrate:initInitializes the migration system by creating the necessary migrations table.
cycle:migrateExecutes pending migrations. Use the `--one` flag to execute only the first pending migration.
cycle:migrate:replayReplays migrations by rolling them back and then re-applying them. Use the `--all` flag to replay all migrations.
cycle:migrate:rollbackRolls back the last batch of migrations by default. Use the `--all` flag to roll back all migrations.
cycle:migrate:statusDisplays the status of all migrations, indicating which have been applied.
cycle:migrate:freshDrops all tables and re-runs all migrations, providing a clean slate. ⚠️

Initializing Migrations


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.


php artisan cycle:migrate:init

Running Migrations


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.


php artisan cycle:migrate


  • --one: Executes only the first pending migration, allowing for more granular control over the migration process.


Recording shows the visualization of applying migrations to the database.

Replaying Migrations


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.


php artisan cycle:migrate:replay


  • --all: Replays all migrations, effectively refreshing your entire database schema.

Rolling Back Migrations


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.


php artisan cycle:migrate:rollback


  • --all: Rolls back all migrations, allowing you to revert your database schema to its initial state.

Checking Migration Status


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.


php artisan cycle:migrate:status

Fresh Schema Command


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.


php artisan cycle:migrate:fresh

Be cautious when using the cycle:migrate:fresh command, as it will permanently delete all data in your database.


  • --seed: Seeds the database after running the migrations, populating it with initial data.