Skip to content

Hotfix: make lib-jobs migration's FK drop idempotent - #272

Merged
pconrad merged 1 commit into
mainfrom
pc-hotfix-db-migration-jobs
Aug 8, 2026
Merged

Hotfix: make lib-jobs migration's FK drop idempotent#272
pconrad merged 1 commit into
mainfrom
pc-hotfix-db-migration-jobs

Conversation

@pconrad

@pconrad pconrad commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a production migration failure introduced by Migrate jobs system to lib-jobs v0.1.6 (shared library) #270: liquibase.exception.DatabaseException: ERROR: constraint "fk_jobs_users" of relation "jobs" does not exist on ALTER TABLE public.jobs DROP CONSTRAINT FK_JOBS_USERS.
  • Splits the 004-migrate-jobs-to-lib-jobs changeset into two idempotent changesets: one that drops FK_JOBS_USERS only if it exists (precondition + onFail: MARK_RAN), and one that adds the new lib-jobs columns only if they aren't already present — both following the precondition idiom already used elsewhere in this changelog (e.g. 005_add_course_id_to_commons.json).

Test plan

  • mvn verify passes locally (370+ tests, 100% JaCoCo coverage)
  • Verified against a real Postgres 15 instance via liquibase-maven-plugin:
    • Fresh DB (normal path, FK exists): FK dropped, columns added, matches prior behavior.
    • Simulated broken DB (FK manually dropped out-of-band, reproducing the exact reported error on the raw ALTER TABLE ... DROP CONSTRAINT FK_JOBS_USERS statement): drop-fk changeset gracefully marks itself as ran via the precondition, add-columns changeset still runs normally. Final schema identical in both cases.
    • Re-running update afterward is a clean no-op in both scenarios.

🤖 Generated with Claude Code

The 004-migrate-jobs-to-lib-jobs changeset unconditionally dropped
FK_JOBS_USERS, but some environments' jobs table doesn't have a
constraint under that name, so the DROP CONSTRAINT fails with
"constraint ... does not exist" and blocks the whole migration.

Split the changeset into two: one that drops the FK only if it exists
(precondition + onFail=MARK_RAN, matching the precondition idiom
already used elsewhere in this changelog), and one that adds the new
lib-jobs columns only if they aren't already there. Verified against a
real Postgres instance in both the normal fresh-DB path and a
simulated broken DB where the FK was already missing; both converge
on the same final schema and re-running is a clean no-op.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@pconrad
pconrad merged commit 16d4ca3 into main Aug 8, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant