Skip to content

fix: make seed_db idempotent and require explicit --reset to drop tables (#1856) - #1893

Open
ionfwsrijan wants to merge 1 commit into
komalharshita:mainfrom
ionfwsrijan:fix/1856-idempotent-seed
Open

fix: make seed_db idempotent and require explicit --reset to drop tables (#1856)#1893
ionfwsrijan wants to merge 1 commit into
komalharshita:mainfrom
ionfwsrijan:fix/1856-idempotent-seed

Conversation

@ionfwsrijan

Copy link
Copy Markdown
Contributor

Problem

src/seed_db.py starts with an unconditional db.drop_all(), wiping every table — users, saved progress, game progress and admin flags — every time the documented seeding script is run on an existing database. It also inserts without the project validation that the data loader relies on.

Fix

  • src/seed_db.py: replace db.drop_all() with an idempotent upsert — db.create_all() then update-or-insert each project by id (matching the app.py auto-seed behavior) — so running the seed script no longer destroys user data.
  • The destructive path is now guarded behind an explicit --reset flag with a confirmation prompt.
  • The dataset is validated with validate_projects() before any writes, and the whole upsert is committed in one transaction.
  • tests/test_basic.py: add test_seed_database_is_idempotent_and_preserves_users verifying a user survives re-seeding and the project count stays correct.

Files changed

  • src/seed_db.py
  • tests/test_basic.py

Testing

  • py -m pytest tests/ -q → 522 passed, 19 pre-existing unrelated failures (identical to baseline), 3 skipped.
  • New test confirms seeding preserves existing user rows.

Closes #1856

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

@ionfwsrijan is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: seed_db.py runs db.drop_all() unconditionally - destroys all user data on re-run; seeding logic triplicated

1 participant