diff --git a/docs/feature_support.md b/docs/feature_support.md index 6a4f9bf..8702671 100644 --- a/docs/feature_support.md +++ b/docs/feature_support.md @@ -4,7 +4,7 @@ This document tracks `pgy`'s support for various PostgreSQL features within its Features are grouped by relative complexity and impact on the diffing engine. -Supported servers: PostgreSQL 15, 16, 17, 18 and 19 (the integration suite runs against each in CI). Syntax specific to a newer release is emitted only when the YAML asks for it: `nullsNotDistinct` needs 15+ (the floor anyway), changing a generated expression in place needs 17+ (before, the column is dropped and added again), and `virtual` generated columns, `enforced: false` and temporal `without overlaps`/`period` keys need 18+. +Supported servers: PostgreSQL 15, 16, 17, 18 and 19 (the integration suite runs against each in CI). Syntax specific to a newer release is emitted only when the YAML asks for it: `nullsNotDistinct` needs 15+ (the floor anyway), changing a generated expression in place needs 17+ (before, the column is dropped and added again), `virtual` generated columns, `enforced: false`, temporal `without overlaps`/`period` keys, `notNullNoInherit` and `largeObjects` default privileges need 18+, and a publication's `allSequences` and `except`, a foreign-data wrapper's `connection` and an aggregate's `support` need 19+. `pgy diff` warns when the server is older than such a key needs. Some changes run in place only on newer servers: `enforced: false` on an existing foreign key on 18+ and on an existing check on 19+, `SET EXPRESSION` on a virtual column of a table with check constraints on 19+, and a switch of a publication to `allTables` or `allSequences` on 19+. ## Level 1: Basic Schema & Tables These are the foundational elements required for almost any relational database application. diff --git a/internal/diff/diff.go b/internal/diff/diff.go index cb52783..0b4f800 100644 --- a/internal/diff/diff.go +++ b/internal/diff/diff.go @@ -4440,6 +4440,8 @@ func inheritedOverrideStmts(desired *schema.Database, live *Live, fq, cn string, concurrent = append(concurrent, fmt.Sprintf("alter table %s validate constraint %s;", pqIdent(fq), quoteIdent(lc.NotNullNotValid))) case lc == nil && root != nil && !root.Nullable && root.NotValid && (liveRoot == nil || liveRoot.Nullable): alters = append(alters, fmt.Sprintf("alter table %s validate constraint %s;", pqIdent(fq), quoteIdent(notNullConstraintName(rootFq, cn, root)))) + case lc != nil && lc.Nullable && root != nil && !root.Nullable && root.NotValid && liveRoot != nil && liveRoot.Nullable: + concurrent = append(concurrent, fmt.Sprintf("alter table %s validate constraint %s;", pqIdent(fq), quoteIdent(notNullConstraintName(rootFq, cn, root)))) } } return alters, concurrent diff --git a/internal/diff/inherited_overrides_test.go b/internal/diff/inherited_overrides_test.go index c8a0ea6..0836aed 100644 --- a/internal/diff/inherited_overrides_test.go +++ b/internal/diff/inherited_overrides_test.go @@ -183,3 +183,21 @@ func TestInheritedNotNullValidatedCopyAlter(t *testing.T) { t.Errorf("a NOT VALID copy is validated in the no-transaction migration, got %q, %v", Render(p), p.Concurrent) } } + +func TestInheritedNotNullValidatedCopyReadded(t *testing.T) { + live := emptyLive() + live.ServerVersion = 180000 + live.Schemas["app"] = true + base, kid := newLiveTable(), newLiveTable() + base.Columns["e"] = &LiveColumn{Type: "text", Nullable: true} + kid.Columns["e"] = &LiveColumn{Type: "text", Nullable: true, Inherited: true} + kid.Inherits = []string{"app.base"} + live.Tables["app.base"], live.Tables["app.kid"] = base, kid + p := Plan(live, notValidCopyDB(), false) + if !findAlter(p, `alter table "app"."base" add constraint "base_e_nn" not null "e" not valid;`) { + t.Fatalf("the parent's NOT VALID constraint is added again:\n%s", Render(p)) + } + if len(p.Concurrent) != 1 || p.Concurrent[0] != `alter table "app"."kid" validate constraint "base_e_nn";` { + t.Errorf("the child's copy is validated in the no-transaction migration after the parent adds it, got %v", p.Concurrent) + } +}