You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ops(db): Create pre-migration DB schema checks and dry-run validation task #31
Description
Build a validation wrapper for database migrations using Python script triggers. The script must dry-run Alembic migrations, detect drift between models and active database schemas, and halt deployments if errors are found.
Context
In automated CI/CD and self-hosted environments, database state can drift from expectations due to manual modifications, causing subsequent migration upgrades to crash halfway and corrupt the database.
Technical Implementation Blueprint
Migration Verification Script: Create a CLI utility in docsgraph_server/db/verify.py.
Dry-run Integration: Initialize a test database connection, run alembic upgrade head, and compare the resulting schema metadata state with SQLAlchemy model definitions using SQLAlchemy's inspection tools:
python:
Script check logic stub
from alembic.script import ScriptDirectory
from alembic.config import Config
Self-Healing Check: Detect common minor discrepancies (like missing indexes or outdated table statistics) and attempt safe self-healing steps or output clear diagnostic errors before executing mutations.
Acceptance Criteria
Pre-migration task detects if the current DB state does not align with migration history and safely terminates execution.
Dry-runs output clear statements of planned changes (Tables added, columns removed) to stdout.
The migration pipeline supports rolling back to the previous stable state automatically if a new migration fails halfway.
Activity