如何跟踪Laravel中应用了哪些播种机?

如何跟踪Laravel中应用了哪些播种机?

问题描述:

应用特定种子而不是为所有种子添加种子的一种明显方法是使用--class标志:

The obvious way to apply specific seeds rather than seeding everything is by using the --class flag:

php artisan db:seed --class[=CLASS]

是否有一种方法可以跟踪到目前为止在Laravel中已经应用了哪些播种器(例如,您可以通过运行php artisan migrate:status来跟踪如何应用迁移的方法)?

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)?

此外,还有一种方法可以应用种子的 range 范围(而不是单独指定每个类,这很麻烦).

Further, is there a way to apply a range of seeders (rather than specifying each class individually, which is very cumbersome).

让我想到这一点的是这本书不愿讨厌的构建API"中的种子部分:

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');"

这个想法是,每次您要运行主播种机时,都必须从头开始.但这至少对于我们的登台环境不切实际,至少要始终将种子数据和QA/Operations人员输入的人工数据结合起来.

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.

我相信此软件包的创建是为了运行诸如迁移之类的种子:

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.