12

I have historical data that I want to load in new DB.

I could do it by running MySQL command but I am interested to know whether there are artisan commands to do it?

1 Answer 1

22

There isn't a way to import a DB dump out-of-the-box using artisan. However, you could create a custom artisan command:

php artisan make:console DbImportCommand

and then have it issue a command like:

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

However, it may be advantageous to create a command that runs a seeder (or set of seeders).

php artisan make:console importHistoricalData

and then have that run specific seeders:

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

If you wipe the database at some point, or move to a new environment, it's as simple as just running the seeders again.

Sign up to request clarification or add additional context in comments.

2 Comments

I do know about seeder but here I am importing thousands of records.
Then my first suggestion may be more appropriate. You can also take a look at Seeders here: laravel.com/docs/5.1/seeding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.