问题
The obvious way to apply specific seeds rather than seeding everything is by using the --class
flag:
php artisan db:seed --class[=CLASS]
Is there a way to track which seeders have been applied so far in Laravel (say, the same way you can track how migrations got applied by running php artisan migrate:status
)?
Further, is there a way to apply a range of seeders (rather than specifying each class individually, which is very cumbersome).
What made me think about this is this part in a seeder in the book "Build APIs You Won't Hate":
28 foreach ($tables as $table) {
29 DB::table($table)->truncate();
30 }
31
32 $this->call('MerchantTableSeeder');
33 $this->call('PlaceTableSeeder');
34 $this->call('UserTableSeeder');”
The idea is that every time you want to run the main seeder, you must start from a clean slate. But that's not practical for us in our staging environment at least which will always have a combination of seeding data and manual data entered by our QA/Operations staff.
回答1:
I believe this package was created to run seeders like migrations: https://github.com/slampenny/SmartSeeder. I think it will do what you are looking for.
The reason there is so little written about this, is that most of the time seeders are only used to initialize the database with data manually, and is not part of a more complex deployment process.
回答2:
This seems like an overcomplication of how seeds work, or an under-complication of your QA environment.
Maybe have different seeds for development and whatever you call staging/qa?
来源:https://stackoverflow.com/questions/48122263/how-to-track-which-seeders-got-applied-in-laravel