Skip to content

Guard against model/migration drift between datagov-data-access and the harvester #797

Description

@cody-seibert-gsa

Models live in datagov-data-access; Alembic migrations live here. Nothing enforces that a model column added there gets a migration here, so a version bump can land a column the database does not have. Any query selecting the model then fails with column ... does not exist.

This has now happened twice with the same column

harvest_job.records_warned was added to the model in data-access 1.1.0.

  1. PR Update datagov-data-access to 1.1.0 #794 bumped the pin to 1.1.0 and added the migration (b3f4a9c1d7e2).
  2. Independently, PR Add ON DELETE CASCADE to harvest source/job/record foreign keys #793 hit the missing column while testing and wrote its own migration for it (f4a2b8c15d93).

Both landed. After #793 merged main, the branch had two Alembic heads and two migrations adding the same column. flask db upgrade runs on every deploy (app-start.sh:9) and fails on multiple heads, so the branch would have broken deploys. Fixed in 9a4f5c9 by dropping the duplicate and relinking to a single head.

So the failure mode is not only "migration missing" — it is also "two people write the same migration and collide."

Suggested guards

  • CI check for multiple heads. Cheap and catches the collision class directly:
    flask db heads   # fail the build if it reports more than one
    
  • CI check that models match migrations. alembic check (or autogenerate-and-diff) fails when a model column has no corresponding migration, catching the drift at the bump rather than in production.
  • Checklist item on data-access bump PRs: state explicitly whether the release added or changed columns, and link the migration if so.

The first two are the durable fixes; the multiple-heads check alone would have caught this instance in CI.

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions