Skip to content

chore(db): prune old drizzle migration snapshots - #3217

Merged
Chia1104 merged 1 commit into
developfrom
chore/prune-migration-snapshots
Nov 15, 2026
Merged

Chia1104 merged 1 commit into
developfrom
chore/prune-migration-snapshots

Conversation

@Chia1104

Copy link
Copy Markdown
Owner

Summary

packages/db/.drizzle/migrations held one full-schema snapshot.json per migration (48 files, about 213k lines). Only the recent ones are used:

  • drizzle-kit generate diffs the schema against the newest snapshot.
  • drizzle-kit migrate and the runtime migrate() read migration.sql only.

This PR, following lobehub/lobehub#21907:

  • Deletes the oldest 38 snapshots and keeps the newest 10. Every migration.sql is untouched. The folder goes from 6.6M to 1.7M.
  • Adds packages/db/prune-snapshots.ts and runs it as postdb:generate, so each new migration commits its own pruning.
  • Records the rule in packages/db/AGENTS.md.
  • Removes the db:check script, which pointed at a check.ts that does not exist.

Notes

  • The hook is postdb:generate rather than drizzle-kit generate && …, so pnpm db:generate --name foo still passes --name to drizzle-kit.
  • The keep count is not only for dropping and regenerating a draft migration. drizzle-kit 1.0.0-rc.4 runs check before every generate and needs the snapshot two branches forked at. Without it, check diffs both branches against an empty schema and exits 1 with a false conflict (reproduced on a copy of the folder). Ten is enough as long as no unmerged branch forked more than ten migrations ago.
  • Running drizzle-kit generate directly skips the pruning; the next db:generate catches up.
  • This shrinks the working tree only; git history is unchanged.

Verification

  • After pruning, pnpm run db:generate reports No schema changes, nothing to migrate and drizzle-kit check reports Everything's fine.
  • pnpm --filter @chia/db test: 59 tests pass, including 3 new ones for pruneSnapshots.
  • tsc --noEmit and oxlint on the new files are clean.
  • Not run: drizzle-kit migrate against a database. The migrator source reads migration.sql only, and those files are unchanged.

🤖 Generated with Claude Code

drizzle-kit diffs the schema against the newest snapshot and runtime
migrations read only migration.sql, so older snapshot.json files are
dead weight. Keep the newest 10 and prune the rest after db:generate.

Also drop the db:check script, which pointed at a missing check.ts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
chia1104 Error Error Nov 15, 2026 7:29am UTC

@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0292bd3c-9986-40d9-96e4-31a126f6f004
Commits

Reviewing files that changed from the base of the PR and between 8cef068 and c375ad9.

Files selected for processing: 42

  • packages/db/.drizzle/migrations/20260112183525_init/snapshot.json
  • packages/db/.drizzle/migrations/20260112192209_invitation_status_cancled/snapshot.json
  • packages/db/.drizzle/migrations/20260112200528_apikey_rate_limit_enabled__default_false/snapshot.json
  • packages/db/.drizzle/migrations/20260113105901_add_feed_translation_embedding512/snapshot.json
  • packages/db/.drizzle/migrations/20260321155621_refactor_better_auth_api_key/snapshot.json
  • packages/db/.drizzle/migrations/20260408081709_feeds_deleted_at/snapshot.json
  • packages/db/.drizzle/migrations/20260714093921_feeds_index_refactor/snapshot.json
  • packages/db/.drizzle/migrations/20260722085923_spotify_credential/snapshot.json
  • packages/db/.drizzle/migrations/20260727070133_agent_harnesses/snapshot.json
  • packages/db/.drizzle/migrations/20260811165041_resource_chunks/snapshot.json
  • packages/db/.drizzle/migrations/20260812083824_resource_index_run/snapshot.json
  • packages/db/.drizzle/migrations/20260813173839_keen_tenebrous/snapshot.json
  • packages/db/.drizzle/migrations/20260818165011_agent_run_external_id_unique/snapshot.json
  • packages/db/.drizzle/migrations/20260824025534_agent_schema/snapshot.json
  • packages/db/.drizzle/migrations/20260825061419_agent_session_fork/snapshot.json
  • packages/db/.drizzle/migrations/20260826191254_agent_memory/snapshot.json
  • packages/db/.drizzle/migrations/20260827094715_account_issuer/snapshot.json
  • packages/db/.drizzle/migrations/20260827115115_agent_config/snapshot.json
  • packages/db/.drizzle/migrations/20260828172446_agent_usage_ledger/snapshot.json
  • packages/db/.drizzle/migrations/20260828193759_agent_quota_config/snapshot.json
  • packages/db/.drizzle/migrations/20260828194540_agent_quota_running_turns/snapshot.json
  • packages/db/.drizzle/migrations/20260828200833_user_is_anonymous/snapshot.json
  • packages/db/.drizzle/migrations/20260902102512_timestamptz/snapshot.json
  • packages/db/.drizzle/migrations/20260902121350_remove_organization_project/snapshot.json
  • packages/db/.drizzle/migrations/20260902154929_profile_entry/snapshot.json
  • packages/db/.drizzle/migrations/20260904052458_usage_credential_source/snapshot.json
  • packages/db/.drizzle/migrations/20260904115757_feed_draft/snapshot.json
  • packages/db/.drizzle/migrations/20260905033051_writing_session_draft/snapshot.json
  • packages/db/.drizzle/migrations/20260906094510_tool_approval_key/snapshot.json
  • packages/db/.drizzle/migrations/20260906143701_tool_approval_relay_run/snapshot.json
  • packages/db/.drizzle/migrations/20260909192034_kind_config_min_tier/snapshot.json
  • packages/db/.drizzle/migrations/20260912124353_lesson_learning_loop/snapshot.json
  • packages/db/.drizzle/migrations/20260916074304_drop_agent_session_entry_type_idx/snapshot.json
  • packages/db/.drizzle/migrations/20260917042320_feed_draft_content_hash/snapshot.json
  • packages/db/.drizzle/migrations/20260917043016_feed_draft_revision_kinds/snapshot.json
  • packages/db/.drizzle/migrations/20260917044049_feed_draft_applied_commit/snapshot.json
  • packages/db/.drizzle/migrations/20260917155847_agent_memory_fetched_at/snapshot.json
  • packages/db/.drizzle/migrations/20260919080651_drop_account_issuer/snapshot.json
  • packages/db/AGENTS.md
  • packages/db/__tests__/prune-snapshots.spec.ts
  • packages/db/package.json
  • packages/db/prune-snapshots.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Chia1104
Chia1104 merged commit 683ced0 into develop Nov 15, 2026
14 of 17 checks passed

This branch had an error being deployed

1 failed deployment
Preview — c375ad9b Deployed Nov 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant