---
id: 33
type: blog
title: "Deleting Seed Data Safely in Production"
slug: "deleting-seed-data-safely-production"
canonical_url: "https://docs.phatysd.me/content/deleting-seed-data-safely-production"
status: published
revision: 2
published_at: "2026-09-19T16:34:11.292Z"
updated_at: "2026-09-19T16:34:11.292Z"
hierarchy_path: "Web Blog > Engineering Journal > Database"
topics:
  - "PostgreSQL"
  - "Drizzle"
  - "Production safety"
  - "Data cleanup"
tags:
  - "postgres"
  - "drizzle"
  - "seed-data"
  - "migrations"
  - "production"
related:
  - slug: "heroku-postgres-drizzle-operations"
    title: "Heroku Postgres + Drizzle Operations"
    type: docs
    canonical_url: "https://docs.phatysd.me/content/heroku-postgres-drizzle-operations"
---

# 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:

```sql
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:seed` to “reset” production.
- Do not drop tables to remove rows.
- Do not use a broad `TRUNCATE` when 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](https://devcenter.heroku.com/articles/heroku-postgres-backups)
- [Drizzle migrations](https://orm.drizzle.team/docs/migrations)
- Repository source: `src/db/schema.ts`.
