Is there a Laravel way to execute a .SQL file to load data

I have historical data that I want to load into a new database.

I could do this by running the MySQL command, but I'm curious to know if there are artisan commands for this?

+5
source share
1 answer

Unable to import database upload from database using artisan . However, you can create a custom artisan command:

php artisan make:console DbImportCommand

and then run a command like:

DB::unprepared(file_get_contents('full/path/to/dump.sql'));

However, it can be useful to create a command that starts the seeder (or a set of seeders).

php artisan make:console importHistoricalData

and then do the following seeders:

 $this->call(OldCompanySeeder::class); $this->call(OldEmployeeSeeder::class); // etc.... 

If you wipe the database at some point or move into a new environment, it will be as easy as just starting the seeders again.

+5
source

Source: https://habr.com/ru/post/1236454/


All Articles