Hotfix: make lib-jobs migration's FK drop idempotent - #272
Merged
Conversation
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>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
liquibase.exception.DatabaseException: ERROR: constraint "fk_jobs_users" of relation "jobs" does not existonALTER TABLE public.jobs DROP CONSTRAINT FK_JOBS_USERS.004-migrate-jobs-to-lib-jobschangeset into two idempotent changesets: one that dropsFK_JOBS_USERSonly 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 verifypasses locally (370+ tests, 100% JaCoCo coverage)liquibase-maven-plugin:ALTER TABLE ... DROP CONSTRAINT FK_JOBS_USERSstatement): drop-fk changeset gracefully marks itself as ran via the precondition, add-columns changeset still runs normally. Final schema identical in both cases.updateafterward is a clean no-op in both scenarios.🤖 Generated with Claude Code