Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.79 KB

File metadata and controls

47 lines (35 loc) · 1.79 KB

Migration Squash Baseline

We consolidated the legacy Alembic history into a single baseline revision that matches the current SQLAlchemy models.

New Baseline

  • Revision ID: c0ce38f74fe0
  • Location: alembic/versions/c0ce38f74fe0_baseline_unified_schema.py
  • Previous revisions archived under alembic/versions_archive/

Safety Checklist

  1. Back up your production database before performing any changes.
  2. Use scripts/db_introspect.py to inspect existing tables and confirm expected state.
  3. Apply the appropriate path below depending on whether you are provisioning a new database or migrating an existing one.

New Databases

Run the standard Alembic upgrade against an empty database:

alembic upgrade head

This creates the entire schema defined by the baseline revision.

Existing Databases

Because all historical migrations are archived, existing environments only need to acknowledge the new baseline. After taking a backup, manually update the Alembic version table:

-- psql example
BEGIN;
UPDATE alembic_version SET version_num = 'c0ce38f74fe0';
COMMIT;

If alembic_version does not exist, create it and insert the revision number:

CREATE TABLE IF NOT EXISTS alembic_version (version_num VARCHAR(32) PRIMARY KEY);
INSERT INTO alembic_version (version_num) VALUES ('c0ce38f74fe0')
  ON CONFLICT (version_num) DO NOTHING;

CI Guardrails

  • tests/test_schema_parity.py reflects the database schema and compares it to the SQLAlchemy models.
  • The GitHub Actions backend job now runs alembic upgrade head against Postgres before executing pytest. This keeps CI red if models and migrations drift.

Rollback Path

All prior migrations remain available in alembic/versions_archive/ for reference and manual rollback should we need to replay specific operations.