Blog · Web Blog / Engineering Journal / Database
Deleting Seed Data Safely in Production
Deleting Seed Data Safely in Production
Seed data is useful in development and dangerous when its lifecycle is unclear. A seed script creates rows; a migration changes database structure. Treating them as the same thing makes cleanup risky.
The situation
The production knowledge site had demo content that was no longer wanted. The right task was to remove those content rows and their published revisions while leaving the schema, migration history, application, and database itself intact.
The safe sequence
Identify
First list the exact target rows by slug, ID, status, and type. Never delete “everything that looks like a demo” based only on a title prefix unless that rule is an explicit invariant.
Protect
Take a backup when the data has value. Confirm the target database and app before running a destructive command. Keep the connection string in the process environment and redact all output.
Delete transactionally
Delete only the selected content_items. The schema's foreign key from content_revisions.content_item_id uses onDelete: cascade, so the associated revision rows follow the content item. The cascade should be confirmed from the schema before relying on it.
Verify
After the transaction, verify:
SELECT count(*) FROM content_items;
SELECT count(*) FROM content_revisions;
SELECT r.content_item_id
FROM content_revisions r
LEFT JOIN content_items i ON i.id = r.content_item_id
WHERE i.id IS NULL;
The last query should return no orphaned revisions. Then request the public homepage, content index, sitemap, and llms.txt to confirm the removed rows are no longer discoverable.
What not to do
- Do not run
npm run db:seedto “reset” production. - Do not drop tables to remove rows.
- Do not use a broad
TRUNCATEwhen one set of content items is the target. - Do not edit migration history to hide a data operation.
- Do not report success from a delete command without checking counts and public routes.
The broader lesson
Data cleanup is a release operation. It needs a target definition, a blast-radius check, a transaction, and post-operation evidence. The same discipline applies to content archival, revision pruning, and account cleanup.
References
- Heroku PGBackups
- Drizzle migrations
- Repository source:
src/db/schema.ts.
Agent access
Choose a representation.
Both machine-readable links refer to this same published item and preserve its identity, relationships, freshness, and body.