Database seeders
Description
Add support for a seeding mechanism in TempestPHP that allows developers to populate their databases with raw SQL data or using PHP classes — primarily for local development, testing, and bootstrapping environments.
Suggestion using php class:
final readonly class UserSeeder implements DatabaseSeeder
{
public function seed(): ??
{
}
}
Suggestion using raw sql (discovered by the seeder.sql name)
# user.seeder.sql
INSERT INTO `users` ...
This would be useful even without the concept of "Factories" or something similar.
There could be a dedicated command, like ./tempest seed or an argument in the migrations, like ./tempest migrate:up --seed
Benefits
It would be great to be able to set up some local-test data that you can recreate after freshly-migrating your database.
I've added this to post-1.0. However if someone wants to pick it up before, feel free!
My suggestion:
- Add a
DatabaseSeederinterface, all implementations get discovered - For now, we don't add support for
.sqlseeder files. They are already discovered as migrations
One open question: we can have multiple seeders, how do we decide which seeder is run during migrate:up --seed. There should be a way to indicate one or more "default seeder(s)".
For the db:seed command, we can easily show a search list with available seeders, and have the user select one to run. Of course with the option to specify it as an argument for non-interaction input.