Downloads
Stars
Version
rus /
An intelligent alternative version of Laravel 5 Database Migrations
UD-DOWN-UP
--TRANSACTION
- if specified, the migration will be launched within a transaction--UP
and --DOWN
tags.";"
(the last character at the end of the line)--TRANSACTION
--UP
ALTER TABLE authors ADD COLUMN code INT;
ALTER TABLE posts ADD COLUMN slug TEXT;
--DOWN
ALTER TABLE authors DROP COLUMN code;
ALTER TABLE posts DROP COLUMN slug;
If you need to change the delimiter (when in SQL you have to use ";"
)
--SEPARATOR=@
--UP
... some sql ...@
... some sql ...@
--DOWN
... some sql ...@
... some sql ...@
Require this package with composer using the following command:
composer require maxim-oleinik/blade-migrations-laravel
Update config/database.php
'migrations' => [
// migrations table name
'table' => 'migrations',
// path to migrations dir
'dir' => __DIR__ . '/../database/migrations',
],
Register ServiceProvider at config/app.php
for Laravel < 5.5
'providers' => [
...
Blade\Migrations\Laravel\MigrationsServiceProvider::class,
],
for Laravel 6/7/8.X
replace
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class
with
Illuminate\Foundation\Providers\ComposerServiceProvider::class,
Illuminate\Foundation\Providers\ArtisanServiceProvider::class
do disable original mirgations
Create migration table
php artisan migrate:install
php artisan make:migration NAME
php artisan migrate:status
+---+----+---------------------+------------------------+
| | ID | Date | Name |
+---+----+---------------------+------------------------+
| Y | 6 | 28.08.2018 20:17:01 | 20180828_195348_M1.sql |
| D | 7 | 28.08.2018 20:17:21 | 20180828_201639_M3.sql |
| A | | | 20180828_200950_M2.sql |
+---+----+---------------------+------------------------+
# Apply next А-migration
php artisan migrate
# Apply the migration without a prompt
php artisan migrate -f
# Apply with rollback testing: UP-DOWN-UP
php artisan migrate -t
# Auto-migrate all - rollback all D-migrations and appply all А-migrations
php artisan migrate --auto
# Apply migration from the specified file
php artisan migrate FILE_NAME
The migrate file with SQL-commands is saved to DB after applying the migration. So the rollback is processing from this saved instructions. This is done to be able to rollback the migration when project switches to another branch which does not contains this file.
# Rollback the latest Y-migration
php artisan migrate:rollback
# To force the rollback without a prompt
php artisan migrate:rollback -f
# Rollback migration by its ID
php artisan migrate:rollback --id=N
# Rollback migration with commands taken from migration file, not from DB (if saved version contains error)
php artisan migrate:rollback --load-file
Rollback migration and run it again
php artisan migrate:reload
# the same options as rollback
php artisan migrate:reload -f --id=N --load-file