DB backup script and alembic auto-backup hook #6
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/5-db-backups"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #5 (will be manually closed on merge).
Summary
Guardrail against data loss during schema work or destructive operations.
scripts/backup-db.sh [reason]writes a timestamped copy ofquartermaster.dbtobackups/quartermaster-YYYYMMDD-HHMMSS-{slug}.dbsqlite3.Connection.backup), not a plain file copy, so it is safe while the app is writingQUARTERMASTER_DB_URL(sqlite:/// only) or./quartermaster.db; override the destination directory withQUARTERMASTER_BACKUP_DIRalembic/env.pyruns the script automatically with reasonalembicbefore every migration / current / revision command; a failing backup does not stop the migrationCLAUDE.mdcodifies the durable rule: run the script before any schema change or destructive DB operationWhy
Earlier today I wiped the local
quartermaster.dbmultiple times during development (rm before alembic autogen, rm before and after live smoke tests). The file is gitignored, so there was no recovery path. This PR makes losing the data require deliberate action in the presence of a working hook.Test plan
uv run pytestpasses (18/18, +5 new)./scripts/backup-db.sh smoke-testcreatesbackups/quartermaster-*-smoke-test.dbcontaining the same rows as the source./scripts/backup-db.shon a missing DB exits 0 with the expected messageQUARTERMASTER_DB_URLexits 1 with a clear erroruv run alembic currentfires the hook:backup-db.sh: /tmp/qm-dev.db -> /tmp/qm-dev-backups/quartermaster-...-alembic.dbOut of scope