Another alternative to those mentioned if you need to do this a bunch of times with the same migration(s). Personally I think this adds a lot of flexibility to your migrations.
Add database/migrations
to your autoload object in your composer.json
like this:
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories",
"database/support",
"database/migrations" // add this line
]
},
Then add namespace Database\Migrations;
to all of your migration files.
Then run $ composer dump-autoload
to refresh your composer.lock
file.
Then, assuming your class name for the migration is AlterTableWebDirectories
, you can create a command like this:
$ php artisan make:command DropAlterTableWebDirectories
And write this logic in your handle()
method:
public function handle {
(new AlterTableWebDirectories)->down();
DB::raw("delete from migrations where migration like '%alter_table_web_directories%'");
}
This will do exactly what you want. If you want to decrement the migration count instead of deleting it, you can probably figure out how to change the DB:raw
command.
This command could be extended to allow you to dynamically choose which migration you're dropping it by passing an argument into the command.
Then when you're reading to migrate that file again, you can just run php artisan migrate
and it will only migrate that one.
This process allows you to make specific changes to migrations without having to do a full refresh and seed each time.
Personally I need to do that a lot because my seeds are rather large.