tempest-framework icon indicating copy to clipboard operation
tempest-framework copied to clipboard

Database seeders

Open erikaraujo opened this issue 8 months ago • 2 comments

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.

erikaraujo avatar Apr 16 '25 10:04 erikaraujo

I've added this to post-1.0. However if someone wants to pick it up before, feel free!

brendt avatar Apr 23 '25 07:04 brendt

My suggestion:

  • Add a DatabaseSeeder interface, all implementations get discovered
  • For now, we don't add support for .sql seeder 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.

brendt avatar May 17 '25 06:05 brendt