Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/feature_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions internal/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions internal/diff/inherited_overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Loading