Skip to content

Conversation

@catatsuy
Copy link

Description

Add a new hazard for schema diffs that add a new column as NOT NULL without a DEFAULT.
When this pattern is detected, the generated plan includes a clear warning and guidance for a safer online approach (add the column nullable, backfill data, then set NOT NULL using the existing online NOT NULL workflow).

Motivation

ADD COLUMN ... NOT NULL without a DEFAULT is commonly unsafe for non-empty tables and can lead to failed migrations or unexpected blocking.
pg-schema-diff already supports online NOT NULL changes for existing columns, but for new columns the tool cannot infer how to backfill data. This change helps operators notice the risk early and nudges them toward a staged migration.

Testing

  • Added/updated tests to cover:

    • Adding a new NOT NULL column without a DEFAULT emits the new hazard and guidance.
    • Adding a new NOT NULL column with a constant DEFAULT does not emit the hazard (or follows the intended behavior).
  • Ran the test suite locally (go test ./...).

Adding a new NOT NULL column usually needs a backfill.
This change adds a hazard and shows a suggested online migration path
(add nullable -> backfill -> set NOT NULL).
@cla-assistant
Copy link

cla-assistant bot commented Dec 16, 2025

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link

cla-assistant bot commented Dec 16, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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