Reputation: 676
Because of different namming conventions than Laravel in an other database I need to automate this process in Laravel :
What could I do to achieve this ?
php artisan migrate:fresh --seed command would not work because it would import sql on last.
Upvotes: 1
Views: 1842
Reputation: 400
You can write a custom command for this task.
Create a command: php artisan make:command MigrateDatabase
Open the command file app/Console/Commands/MigrateDatabase.php
Change the command name i.e. to this: protected $signature = 'migrate_database:migrate';
Write these lines in the handle()
method:
public function handle(){
Artisan::call('migrate:reset', ['--force' => true]);
DB::unprepared(file_get_contents('full/path/to/dump.sql'));
Artisan::call('migrate');
}
Call the command: php artisan migrate_database:migrate
Be careful before run this in production, i did not tested. (And of course it will drop your db)
Upvotes: 2