From e2b7d65c1819f80b9dc08e016ef3e71dc43e60dc Mon Sep 17 00:00:00 2001 From: Anahkiasen Date: Fri, 26 Oct 2012 19:45:32 +0100 Subject: [PATCH] Added migrate:rebuild command to clean and reconstruct the database Signed-off-by: Anahkiasen --- laravel/cli/tasks/migrate/migrator.php | 19 +++++++++++++++++++ laravel/documentation/database/migrations.md | 8 ++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/laravel/cli/tasks/migrate/migrator.php b/laravel/cli/tasks/migrate/migrator.php index 4ab2ef05..7e99f713 100644 --- a/laravel/cli/tasks/migrate/migrator.php +++ b/laravel/cli/tasks/migrate/migrator.php @@ -139,6 +139,25 @@ public function reset($arguments = array()) while ($this->rollback()) {}; } + /** + * Reset the database to pristine state and run all migrations + * + * @param array $arguments + * @return void + */ + public function rebuild() + { + // Clean the database + $this->reset(); + + echo PHP_EOL; + + // Re-run all migrations + $this->migrate(); + + echo 'The database was successfully rebuilt'.PHP_EOL; + } + /** * Install the database tables used by the migration system. * diff --git a/laravel/documentation/database/migrations.md b/laravel/documentation/database/migrations.md index 8c095631..8ebf7082 100644 --- a/laravel/documentation/database/migrations.md +++ b/laravel/documentation/database/migrations.md @@ -33,7 +33,7 @@ ## Creating Migrations Now, check your **application/migrations** folder. You should see your brand new migration! Notice that it also contains a timestamp. This allows Laravel to run your migrations in the correct order. -You may also create migrations for a bundle. +You may also create migrations for a bundle. **Creating a migration for a bundle:** @@ -69,4 +69,8 @@ ## Rolling Back **Roll back all migrations that have ever run:** - php artisan migrate:reset \ No newline at end of file + php artisan migrate:reset + +**Roll back everything and run all migrations again:** + + php artisan migrate:rebuild