Skip to content

Commit e2b7d65

Browse files
committed
Added migrate:rebuild command to clean and reconstruct the database
Signed-off-by: Anahkiasen <ehtnam6@gmail.com>
1 parent 205cc48 commit e2b7d65

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

laravel/cli/tasks/migrate/migrator.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ public function reset($arguments = array())
139139
while ($this->rollback()) {};
140140
}
141141

142+
/**
143+
* Reset the database to pristine state and run all migrations
144+
*
145+
* @param array $arguments
146+
* @return void
147+
*/
148+
public function rebuild()
149+
{
150+
// Clean the database
151+
$this->reset();
152+
153+
echo PHP_EOL;
154+
155+
// Re-run all migrations
156+
$this->migrate();
157+
158+
echo 'The database was successfully rebuilt'.PHP_EOL;
159+
}
160+
142161
/**
143162
* Install the database tables used by the migration system.
144163
*

laravel/documentation/database/migrations.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ You can easily create migrations through Laravel's "Artisan" CLI. It looks like
3333

3434
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.
3535

36-
You may also create migrations for a bundle.
36+
You may also create migrations for a bundle.
3737

3838
**Creating a migration for a bundle:**
3939

@@ -69,4 +69,8 @@ When you roll back a migration, Laravel rolls back the entire migration "operati
6969

7070
**Roll back all migrations that have ever run:**
7171

72-
php artisan migrate:reset
72+
php artisan migrate:reset
73+
74+
**Roll back everything and run all migrations again:**
75+
76+
php artisan migrate:rebuild

0 commit comments

Comments
 (0)