Skip to content

fix: rewrite denormalize migration to handle non-empty tables#106

Merged
guyb1 merged 1 commit intomainfrom
fix/migration-non-empty-tables
Mar 25, 2026
Merged

fix: rewrite denormalize migration to handle non-empty tables#106
guyb1 merged 1 commit intomainfrom
fix/migration-non-empty-tables

Conversation

@guyb1
Copy link
Copy Markdown
Contributor

@guyb1 guyb1 commented Mar 25, 2026

Summary

The uuid_and_denormalize migration failed on non-empty databases because it tried to add required columns (user_email, updated_at, user_id) without default values.

Fix

Rewritten as a 4-phase migration:

  1. Add all new columns as nullable
  2. Backfill denormalized data from joins (emails from users table, timestamps from created_at)
  3. Set NOT NULL constraints (safe now that all rows have values)
  4. Add foreign keys

The auto-generated migration tried to add required columns (user_email,
updated_at, user_id) without defaults, which fails on tables with
existing data. Rewrite to: add columns as nullable, backfill from
joins, then set NOT NULL.
@guyb1 guyb1 merged commit a6e75b7 into main Mar 25, 2026
1 check passed
@guyb1 guyb1 deleted the fix/migration-non-empty-tables branch March 25, 2026 13:45
@guyb1 guyb1 mentioned this pull request Mar 25, 2026
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