Skip to content

Fix seed.ts to drop all tables dynamically, add db:reset script - #64

Open
webfliccy wants to merge 1 commit into
ai-hero-dev:mainfrom
webfliccy:fix/seed-drop-all-tables-issue-63
Open

Fix seed.ts to drop all tables dynamically, add db:reset script#64
webfliccy wants to merge 1 commit into
ai-hero-dev:mainfrom
webfliccy:fix/seed-drop-all-tables-issue-63

Conversation

@webfliccy

Copy link
Copy Markdown

Summary

Fixes #63

  • seed.ts now queries sqlite_master for every existing table and drops them dynamically (instead of a hardcoded list), so leftover/renamed tables (e.g. an old course_reviews table) no longer leave the DB half-migrated.
  • Foreign key checks are toggled off/on around the drop loop so tables can be dropped in any order.
  • Added a db:reset script (rm -f data.db data.db-shm data.db-wal && pnpm db:seed) so a stale local DB can be fixed with one command instead of manual file deletion.

Test plan

  • Run pnpm db:reset on a DB with schema drift (e.g. an extra/old table not in the current drop list) and confirm migrate() completes cleanly
  • Run pnpm db:seed on a fresh DB and confirm seeding still succeeds as before

seed.ts dropped a hardcoded list of tables before calling migrate(),
which left stale tables (e.g. an old course_reviews table) behind
when migration history was regenerated, causing migrate() to leave
the schema half-applied (no such table: modules).

Now seed.ts queries sqlite_master and drops every table before
migrating, guaranteeing a clean slate regardless of schema drift.
Also adds pnpm db:reset as a one-command fix for a stale local DB.

Fixes ai-hero-dev#63
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: seeding database when navigating between commits

1 participant