2.9 KiB
Ver1 Step 4 Migration and Rollback Runbook
Purpose
Provide a concise, operator-safe procedure for schema migration execution, compatibility validation, and rollback/mitigation for personal-scale deployments.
This runbook supports docs/ver1/ver1-step4.md and REQ-10 by keeping normal
production startup non-mutating unless explicitly configured otherwise.
Preconditions
- Application version to deploy is known and checked out.
.envvalues are configured for target environment.- Database backup path is prepared.
- Application process is stopped before migration on production-like systems.
Commands
Use explicit migration runner operations:
- List pending migrations:
uv run python -m transcription.migration_runner --list
- Apply pending migrations:
uv run python -m transcription.migration_runner --apply
- Validate schema compatibility:
uv run python -m transcription.migration_runner --check
Recommended execution order:
--list- backup database
--apply--check- start application
Backup Procedure (SQLite Baseline)
For SQLite deployments, copy the DB file before migration:
- Example DB path default:
./transcription.db - Keep timestamped backup copy in a safe location.
If the file is in active use, stop the app first.
Verification Checklist
After migration apply:
--checkexits successfully.schema_migration_historyincludes applied revisions.- Application starts successfully.
- Health endpoint responds:
/healthz. - Critical flows smoke-check:
- upload
- job processing
- revision listing/acceptance
Rollback and Mitigation Decision Tree
- If migration fails before changes commit:
- fix issue
- re-run apply
- If migration partially applied or compatibility check fails:
- stop app
- restore from backup
- investigate and produce forward-fix migration if needed
- If app starts but functional invariants fail:
- stop app
- restore backup
- add corrective migration/backfill and rehearse before retry
For this Step 4 baseline, backup restore is the primary rollback mechanism.
Failure Classification Guidance
Classify migration failures using docs/error_handling.md categories:
- transient connection issues ->
infrastructure_transient_error - permissions/misconfiguration ->
infrastructure_persistent_error - unexpected migration logic defects ->
internal_unexpected_error
Record failure details with operation context and timestamp.
Operational Notes
migration_auto_apply_on_startupdefaults toFalse.validate_schema_on_startupdefaults toTrue.- Startup schema validation fails fast on incompatibility.
This protects production from accidental schema drift.
Post-Step-4 Follow-Up
If migration complexity grows beyond lightweight revision scripts, introduce a dedicated migration framework in a future step while preserving this runbook structure and operator-first workflow.