Build seeders out of factories instead of maintaining independent logic

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the workflows category.

Last Updated: 2022-12-01

I like having a rich set of data in my development and testing environments when coding. The default way of getting data locally for development is with seeders calling SQL/an ORM, whereas factories are the default in tests.

In two code-bases I worked on, I "manually" created the records for the seeders (e.g. with inserts to the DB or using the ORM API directly).

In both these cases, I came to regret my decision to base seeders off of factories, especially as the seeding became more complex and required increasingly difficult-to-setup data.

Lesson

Always build seeders out of factories. If there are no factories, make them first (this encourages testing on your team).