Skip to content

Make migration 000007 idempotent - #184

Merged
otc-zuul[bot] merged 1 commit into
mainfrom
fix/sql_migr_07
Sep 2, 2026
Merged

Make migration 000007 idempotent#184
otc-zuul[bot] merged 1 commit into
mainfrom
fix/sql_migr_07

Conversation

@bakhterets

Copy link
Copy Markdown
Contributor

Adds audit user fields (created_by, contact_email, version) to incident and
(created_by, modified_by) to incident_status in a re-runnable way.

Changes

  • Use ADD COLUMN IF NOT EXISTS for all new columns.
  • Backfill version = 1 for existing rows, then apply SET DEFAULT 1 / SET NOT NULL
    in a separate ALTER COLUMN statement.

Why

ADD COLUMN IF NOT EXISTS ... NOT NULL DEFAULT 1 silently skips the constraint when the
column already exists as nullable, leaving the schema out of sync with the GORM model.
Applying the constraint separately guarantees the final state regardless of prior history,
and the backfill must precede SET NOT NULL because it fails on any NULL row.

Verification

Tested on a scratch database:

  • clean run 1 → 8: OK, no dirty state
  • re-applying 000007 over an existing schema: NOTICE ... skipping, no errors
  • goto 6up with existing rows: data preserved, version restored to 1
  • final schema: version integer NOT NULL DEFAULT 1, others varchar(255) NULL

@bakhterets
bakhterets requested a review from sgmv September 2, 2026 13:01
@bakhterets bakhterets self-assigned this Sep 2, 2026
@bakhterets bakhterets added the gate Gate PR label Sep 2, 2026
@otc-zuul
otc-zuul Bot merged commit ba2a5f3 into main Sep 2, 2026
9 checks passed
@otc-zuul
otc-zuul Bot deleted the fix/sql_migr_07 branch September 2, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gate Gate PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants