Database Seeding: Separate Development Data from Reference Data
Seeding adds initial data so an application can start or a development and test database can be recreated. Reference values such as currencies or status codes have a different purpose and lifetime from sample users and posts. Version and deploy reference data consistently with schema changes; keep disposable fixtures in a separate, resettable development or test workflow. Explicitly restrict where each script may run so test accounts and reset logic cannot reach production. [Prisma ORM v7: Seeding](https://www.prisma.io/docs/orm/v7/prisma-migrate/workflows/seeding) [Flyway: Working with data](https://documentation.red-gate.com/fd/handling-data-138347109.html)
Database Seeding: Separate Development Data from Reference Data
Seeding adds initial data so an application can start or a development and test database can be recreated. Reference values such as currencies or status codes have a different purpose and lifetime from sample users and posts. Version and deploy reference data consistently with schema changes; keep disposable fixtures in a separate, resettable development or test workflow. Explicitly restrict where each script may run so test accounts and reset logic cannot reach production. Prisma ORM v7: Seeding Flyway: Working with data
What counts as seed data?
“Seed” describes when data is added, not one universal management rule.
**Reference data:** country or currency codes and application statuses that the application expects. Keep small, shared values in version control and deploy them with schema changes when every environment must agree. Flyway gives country lists and application settings as examples of static/reference data. [Flyway: Working with data](https://documentation.red-gate.com/fd/handling-data-138347109.html)
**Development and test fixtures:** fake users, orders, and posts used to exercise screens and behavior. Make them reproducible and disposable; do not copy production data. Prisma documents seeding for development data and environment recreation. [Prisma ORM v7: Seeding](https://www.prisma.io/docs/orm/v7/prisma-migrate/workflows/seeding)
**Transactional business data:** real orders, payments, or user records created during operation. Do not treat these as fixtures to regenerate or truncate. Correct them through a separately reviewed data-change process.
For example, a fixed status = 'pending' row may be shared reference data, while a sample “Alice” account and order belong only in local or test databases. Combining both in one script makes it harder to control what may be reset or updated in each environment.
Make reruns predictable
A seed command may run again when a developer resets a database or CI prepares tests. An idempotent seed produces the intended final state on repeated runs without accumulating duplicates. Use a stable unique key to find a record and an upsert-style operation to create or deliberately update it. Choose update fields carefully: overwriting every field can erase a developer’s work.
Prisma ORM v7 documents an upsert example keyed by a unique email and leaves the timing of seeding to an explicit prisma db seed command. In v7, seeds no longer run automatically after prisma migrate dev or prisma migrate reset; other Prisma versions may differ. Check the documentation for the version you use. Prisma ORM v7: Seeding
Illustrative Prisma code (not executed or validated against a particular project):
await prisma.user.upsert({
where: { email: "seed-reader@example.test" },
create: { email: "seed-reader@example.test", name: "Sample Reader" },
update: { name: "Sample Reader" },
});Create parent records before dependent records, respect foreign keys, and consider a transaction. If a failure leaves partial rows, confirm that rerunning can safely finish. A retry must not create duplicates or replace data that the fixture does not own.
How should seeds relate to migrations?
Use versioned migrations for schema changes and small reference-data updates that must be tracked and deployed consistently. Keep developer-specific or disposable sample data out of production migrations. For Flyway, repeatable migrations rerun after their checksum changes and run after pending versioned migrations; authors are responsible for making them safe to apply more than once. They can suit bulk reference-data reinsertion, but schema dependencies still matter. If a reference ID must change before adding a foreign key, put that prerequisite in the correctly ordered versioned migration instead of relying on repeatable-migration order. Flyway: Repeatable migrations Flyway: Working with data
Small fixed lists are often clearest as explicit, versioned inserts. Large datasets may benefit from a bulk loader, but the deployment process must also define file versioning, encoding, duplicate handling, and safe restart after failure. Flyway describes data-comparison tooling as an option for large, infrequently changing static data; some of these capabilities are edition-specific, so do not assume they are available everywhere. Flyway: Working with data
A safe workflow
**Name the purpose and target.** Separate shared reference data from fake fixtures. Explicitly allow only intended environments, and confirm the connection points to the expected database before running the seed. Production reference-data changes belong in a reviewed deployment workflow.
**Prepare the schema first.** Apply migrations, then insert parents before children. Make ordering explicit if reference rows are prerequisites for a schema change.
**Test repeatability and failure recovery.** In a disposable development database, run the seed twice and check for duplicates. Simulate a partial failure and confirm a rerun restores the intended state. The code above is illustrative and was not run.
**Exclude secrets and real personal data.** Do not commit passwords, API keys, production dumps, or real user data. Keep test accounts limited to dedicated environments.
**Verify the result.** Check required row counts and reference values, uniqueness and foreign-key constraints, and whether sample records reproduce the intended test case. Document any intentional environment differences.
A good seed is a data-management process matched to purpose and lifetime, not just a handful of initial inserts. Deploy shared reference data as reviewed, versioned changes; keep development fixtures isolated and repeatable; and preserve transactional data through its own business history.