From d775dc15bdd05f5747cd61d11735b9b52a0c2408 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Fri, 3 Jul 2026 02:44:48 -0700 Subject: [PATCH 1/4] fix: emit per-child column overrides (DEFAULT, NOT NULL) in PARTITION OF (#499) When a partition child overrides DEFAULT or NOT NULL relative to the parent, generate the column-element list inside the PARTITION OF statement so `pgschema plan` produces faithful DDL. Co-Authored-By: Claude Opus 4.6 --- internal/diff/qualify_schema_test.go | 4 +- internal/diff/table.go | 53 +++++++++++++++++-- .../diff.sql | 13 +++++ .../new.sql | 14 +++++ .../old.sql | 1 + .../plan.json | 32 +++++++++++ .../plan.sql | 13 +++++ .../plan.txt | 26 +++++++++ 8 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides/diff.sql create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides/new.sql create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides/old.sql create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides/plan.json create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides/plan.sql create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides/plan.txt diff --git a/internal/diff/qualify_schema_test.go b/internal/diff/qualify_schema_test.go index fa8ffcab..a3d856bc 100644 --- a/internal/diff/qualify_schema_test.go +++ b/internal/diff/qualify_schema_test.go @@ -55,7 +55,7 @@ func TestQualifySchema_TableAndColumnType(t *testing.T) { } empty := map[string]bool{} - def, _ := generateTableSQL(table, "public", false, empty, empty, empty) + def, _ := generateTableSQL(table, "public", false, empty, empty, empty, nil) if !strings.Contains(def, "CREATE TABLE IF NOT EXISTS account (") { t.Errorf("default should use the bare table name: %q", def) } @@ -63,7 +63,7 @@ func TestQualifySchema_TableAndColumnType(t *testing.T) { t.Errorf("default should not qualify the target schema: %q", def) } - qualified, _ := generateTableSQL(table, "public", true, empty, empty, empty) + qualified, _ := generateTableSQL(table, "public", true, empty, empty, empty, nil) if !strings.Contains(qualified, "CREATE TABLE IF NOT EXISTS public.account (") { t.Errorf("forced qualification should qualify the table name: %q", qualified) } diff --git a/internal/diff/table.go b/internal/diff/table.go index acc7f2a0..8e93306d 100644 --- a/internal/diff/table.go +++ b/internal/diff/table.go @@ -418,10 +418,15 @@ func generateCreateTablesSQL( var deferredConstraints []*deferredConstraint createdTables := make(map[string]bool, len(tables)) + allTables := make(map[string]*ir.Table, len(tables)) + for _, t := range tables { + allTables[t.Schema+"."+t.Name] = t + } + // Process tables in the provided order (already topologically sorted) for _, table := range tables { // Create the table, deferring FK constraints that reference not-yet-created tables - sql, tableDeferred := generateTableSQL(table, targetSchema, collector.qualifySchema, createdTables, existingTables, suppressedInlineFKs) + sql, tableDeferred := generateTableSQL(table, targetSchema, collector.qualifySchema, createdTables, existingTables, suppressedInlineFKs, allTables) deferredConstraints = append(deferredConstraints, tableDeferred...) // Create context for this statement @@ -759,7 +764,7 @@ func generateDropTablesSQL(tables []*ir.Table, targetSchema string, collector *d } // generateTableSQL generates CREATE TABLE statement and returns any deferred FK constraints -func generateTableSQL(table *ir.Table, targetSchema string, qualifySchema bool, createdTables map[string]bool, existingTables map[string]bool, suppressedInlineFKs map[string]bool) (string, []*deferredConstraint) { +func generateTableSQL(table *ir.Table, targetSchema string, qualifySchema bool, createdTables map[string]bool, existingTables map[string]bool, suppressedInlineFKs map[string]bool, allTables map[string]*ir.Table) (string, []*deferredConstraint) { // Only include table name without schema if it's in the target schema (unless // forced qualification is on). tableName := ir.QualifyEntityNameWithQuotesMode(table.Schema, table.Name, targetSchema, qualifySchema) @@ -774,7 +779,44 @@ func generateTableSQL(table *ir.Table, targetSchema string, qualifySchema bool, } parentName := ir.QualifyEntityNameWithQuotesMode(parentSchema, table.PartitionOf, targetSchema, qualifySchema) - // Include child-specific constraints in the PARTITION OF statement. + // Include child-specific column overrides and constraints in the PARTITION OF statement. + var elementParts []string + + // Detect per-child column overrides (DEFAULT, NOT NULL) by comparing against the parent. + parentKey := parentSchema + "." + table.PartitionOf + if parentTable, ok := allTables[parentKey]; ok { + parentCols := make(map[string]*ir.Column, len(parentTable.Columns)) + for _, col := range parentTable.Columns { + parentCols[col.Name] = col + } + for _, col := range table.Columns { + parentCol := parentCols[col.Name] + if parentCol == nil { + continue + } + var overrides []string + childDefault := "" + parentDefault := "" + if col.DefaultValue != nil { + childDefault = *col.DefaultValue + } + if parentCol.DefaultValue != nil { + parentDefault = *parentCol.DefaultValue + } + if childDefault != parentDefault { + if col.DefaultValue != nil { + overrides = append(overrides, fmt.Sprintf("DEFAULT %s", *col.DefaultValue)) + } + } + if !col.IsNullable && parentCol.IsNullable { + overrides = append(overrides, "NOT NULL") + } + if len(overrides) > 0 { + elementParts = append(elementParts, fmt.Sprintf(" %s %s", ir.QuoteIdentifier(col.Name), strings.Join(overrides, " "))) + } + } + } + inlineConstraints := getInlineConstraintsForTable(table) var constraintParts []string var deferred []*deferredConstraint @@ -800,10 +842,11 @@ func generateTableSQL(table *ir.Table, targetSchema string, qualifySchema bool, createPrefix = "CREATE UNLOGGED TABLE IF NOT EXISTS" } + allParts := append(elementParts, constraintParts...) var sql string - if len(constraintParts) > 0 { + if len(allParts) > 0 { sql = fmt.Sprintf("%s %s PARTITION OF %s (\n%s\n) %s;", - createPrefix, tableName, parentName, strings.Join(constraintParts, ",\n"), table.PartitionBound) + createPrefix, tableName, parentName, strings.Join(allParts, ",\n"), table.PartitionBound) } else { sql = fmt.Sprintf("%s %s PARTITION OF %s %s;", createPrefix, tableName, parentName, table.PartitionBound) } diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/diff.sql b/testdata/diff/create_table/issue_499_partition_column_overrides/diff.sql new file mode 100644 index 00000000..eb3945f0 --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/diff.sql @@ -0,0 +1,13 @@ +CREATE TABLE IF NOT EXISTS orders ( + id bigint NOT NULL, + region text NOT NULL, + priority integer DEFAULT 0, + notes text +) PARTITION BY LIST (region); + +CREATE TABLE IF NOT EXISTS orders_eu PARTITION OF orders FOR VALUES IN ('eu'); + +CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( + priority DEFAULT 10, + notes NOT NULL +) FOR VALUES IN ('us'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/new.sql b/testdata/diff/create_table/issue_499_partition_column_overrides/new.sql new file mode 100644 index 00000000..72c2766e --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/new.sql @@ -0,0 +1,14 @@ +CREATE TABLE public.orders ( + id bigint NOT NULL, + region text NOT NULL, + priority integer DEFAULT 0, + notes text +) PARTITION BY LIST (region); + +CREATE TABLE public.orders_us PARTITION OF public.orders ( + priority DEFAULT 10, + notes NOT NULL +) FOR VALUES IN ('us'); + +CREATE TABLE public.orders_eu PARTITION OF public.orders + FOR VALUES IN ('eu'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/old.sql b/testdata/diff/create_table/issue_499_partition_column_overrides/old.sql new file mode 100644 index 00000000..03d7e9ae --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/old.sql @@ -0,0 +1 @@ +-- Empty schema diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/plan.json b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.json new file mode 100644 index 00000000..01e12ee0 --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.json @@ -0,0 +1,32 @@ +{ + "version": "1.0.0", + "pgschema_version": "1.11.1", + "created_at": "1970-01-01T00:00:00Z", + "source_fingerprint": { + "hash": "965b1131737c955e24c7f827c55bd78e4cb49a75adfd04229e0ba297376f5085" + }, + "groups": [ + { + "steps": [ + { + "sql": "CREATE TABLE IF NOT EXISTS orders (\n id bigint NOT NULL,\n region text NOT NULL,\n priority integer DEFAULT 0,\n notes text\n) PARTITION BY LIST (region);", + "type": "table", + "operation": "create", + "path": "public.orders" + }, + { + "sql": "CREATE TABLE IF NOT EXISTS orders_eu PARTITION OF orders FOR VALUES IN ('eu');", + "type": "table", + "operation": "create", + "path": "public.orders_eu" + }, + { + "sql": "CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders (\n priority DEFAULT 10,\n notes NOT NULL\n) FOR VALUES IN ('us');", + "type": "table", + "operation": "create", + "path": "public.orders_us" + } + ] + } + ] +} diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/plan.sql b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.sql new file mode 100644 index 00000000..eb3945f0 --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.sql @@ -0,0 +1,13 @@ +CREATE TABLE IF NOT EXISTS orders ( + id bigint NOT NULL, + region text NOT NULL, + priority integer DEFAULT 0, + notes text +) PARTITION BY LIST (region); + +CREATE TABLE IF NOT EXISTS orders_eu PARTITION OF orders FOR VALUES IN ('eu'); + +CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( + priority DEFAULT 10, + notes NOT NULL +) FOR VALUES IN ('us'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/plan.txt b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.txt new file mode 100644 index 00000000..556b5797 --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.txt @@ -0,0 +1,26 @@ +Plan: 3 to add. + +Summary by type: + tables: 3 to add + +Tables: + + orders + + orders_eu + + orders_us + +DDL to be executed: +-------------------------------------------------- + +CREATE TABLE IF NOT EXISTS orders ( + id bigint NOT NULL, + region text NOT NULL, + priority integer DEFAULT 0, + notes text +) PARTITION BY LIST (region); + +CREATE TABLE IF NOT EXISTS orders_eu PARTITION OF orders FOR VALUES IN ('eu'); + +CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( + priority DEFAULT 10, + notes NOT NULL +) FOR VALUES IN ('us'); From 7decbf3d0253a35513e017be82e9c19e4ed0a1d6 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Fri, 3 Jul 2026 02:58:06 -0700 Subject: [PATCH 2/4] fix: use allNewTables from target IR for parent lookup Address review feedback from Copilot, Greptile, and @schema-codex: the parent lookup for column-override detection was scoped to the current add-table batch, silently missing existing parents and cross-batch parents. Now uses allNewTables (all tables from the target schema state) so override detection works regardless of whether the parent is new or pre-existing. Adds regression fixture for the incremental case (existing parent, new child with overrides). Co-Authored-By: Claude Opus 4.6 --- internal/diff/diff.go | 7 +++++-- internal/diff/table.go | 8 ++------ .../diff.sql | 4 ++++ .../new.sql | 14 +++++++++++++ .../old.sql | 9 +++++++++ .../plan.json | 20 +++++++++++++++++++ .../plan.sql | 4 ++++ .../plan.txt | 15 ++++++++++++++ 8 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/diff.sql create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/new.sql create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/old.sql create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.sql create mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.txt diff --git a/internal/diff/diff.go b/internal/diff/diff.go index d1dfb99e..e23b76ee 100644 --- a/internal/diff/diff.go +++ b/internal/diff/diff.go @@ -271,6 +271,7 @@ type ddlDiff struct { addedTables []*ir.Table droppedTables []*ir.Table modifiedTables []*tableDiff + allNewTables map[string]*ir.Table addedViews []*ir.View droppedViews []*ir.View modifiedViews []*viewDiff @@ -626,6 +627,8 @@ func GenerateMigrationWithOptions(oldIR, newIR *ir.IR, targetSchema string, qual } } + diff.allNewTables = newTables + // Compare functions across all schemas oldFunctions := make(map[string]*ir.Function) newFunctions := make(map[string]*ir.Function) @@ -1823,7 +1826,7 @@ func (d *ddlDiff) generateCreateSQL(targetSchema string, collector *diffCollecto } // Create tables WITHOUT function/domain dependencies first (functions may reference these) - deferredPolicies1, deferredConstraints1 := generateCreateTablesSQL(tablesWithoutDeps, targetSchema, collector, existingTables, shouldDeferPolicy, d.suppressedInlineFKs) + deferredPolicies1, deferredConstraints1 := generateCreateTablesSQL(tablesWithoutDeps, targetSchema, collector, existingTables, shouldDeferPolicy, d.suppressedInlineFKs, d.allNewTables) // Build view lookup - needed for detecting functions that depend on views newViewLookup := buildViewLookup(d.addedViews) @@ -1877,7 +1880,7 @@ func (d *ddlDiff) generateCreateSQL(targetSchema string, collector *diffCollecto generateCreateProceduresSQL(d.addedProcedures, targetSchema, collector) // Create tables WITH function/domain dependencies (now that functions and deferred domains exist) - deferredPolicies2, deferredConstraints2 := generateCreateTablesSQL(tablesWithDeps, targetSchema, collector, existingTables, shouldDeferPolicy, d.suppressedInlineFKs) + deferredPolicies2, deferredConstraints2 := generateCreateTablesSQL(tablesWithDeps, targetSchema, collector, existingTables, shouldDeferPolicy, d.suppressedInlineFKs, d.allNewTables) // Emit COMMENT ON SEQUENCE for sequences created implicitly via CREATE TABLE (SERIAL/BIGSERIAL). // These were skipped from addedSequences but their comments must still be deployed. diff --git a/internal/diff/table.go b/internal/diff/table.go index 8e93306d..079a2c75 100644 --- a/internal/diff/table.go +++ b/internal/diff/table.go @@ -413,20 +413,16 @@ func generateCreateTablesSQL( existingTables map[string]bool, shouldDeferPolicy func(*ir.RLSPolicy) bool, suppressedInlineFKs map[string]bool, + allNewTables map[string]*ir.Table, ) ([]*ir.RLSPolicy, []*deferredConstraint) { var deferredPolicies []*ir.RLSPolicy var deferredConstraints []*deferredConstraint createdTables := make(map[string]bool, len(tables)) - allTables := make(map[string]*ir.Table, len(tables)) - for _, t := range tables { - allTables[t.Schema+"."+t.Name] = t - } - // Process tables in the provided order (already topologically sorted) for _, table := range tables { // Create the table, deferring FK constraints that reference not-yet-created tables - sql, tableDeferred := generateTableSQL(table, targetSchema, collector.qualifySchema, createdTables, existingTables, suppressedInlineFKs, allTables) + sql, tableDeferred := generateTableSQL(table, targetSchema, collector.qualifySchema, createdTables, existingTables, suppressedInlineFKs, allNewTables) deferredConstraints = append(deferredConstraints, tableDeferred...) // Create context for this statement diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/diff.sql b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/diff.sql new file mode 100644 index 00000000..55f62f06 --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/diff.sql @@ -0,0 +1,4 @@ +CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( + priority DEFAULT 10, + notes NOT NULL +) FOR VALUES IN ('us'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/new.sql b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/new.sql new file mode 100644 index 00000000..023cc207 --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/new.sql @@ -0,0 +1,14 @@ +CREATE TABLE public.orders ( + id bigint NOT NULL, + region text NOT NULL, + priority integer DEFAULT 0, + notes text +) PARTITION BY LIST (region); + +CREATE TABLE public.orders_eu PARTITION OF public.orders + FOR VALUES IN ('eu'); + +CREATE TABLE public.orders_us PARTITION OF public.orders ( + priority DEFAULT 10, + notes NOT NULL +) FOR VALUES IN ('us'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/old.sql b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/old.sql new file mode 100644 index 00000000..8e58a50f --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/old.sql @@ -0,0 +1,9 @@ +CREATE TABLE public.orders ( + id bigint NOT NULL, + region text NOT NULL, + priority integer DEFAULT 0, + notes text +) PARTITION BY LIST (region); + +CREATE TABLE public.orders_eu PARTITION OF public.orders + FOR VALUES IN ('eu'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json new file mode 100644 index 00000000..553dc66f --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json @@ -0,0 +1,20 @@ +{ + "version": "1.0.0", + "pgschema_version": "1.11.1", + "created_at": "1970-01-01T00:00:00Z", + "source_fingerprint": { + "hash": "PLACEHOLDER" + }, + "groups": [ + { + "steps": [ + { + "sql": "CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders (\n priority DEFAULT 10,\n notes NOT NULL\n) FOR VALUES IN ('us');", + "type": "table", + "operation": "create", + "path": "public.orders_us" + } + ] + } + ] +} diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.sql b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.sql new file mode 100644 index 00000000..55f62f06 --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.sql @@ -0,0 +1,4 @@ +CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( + priority DEFAULT 10, + notes NOT NULL +) FOR VALUES IN ('us'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.txt b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.txt new file mode 100644 index 00000000..9799ba0d --- /dev/null +++ b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.txt @@ -0,0 +1,15 @@ +Plan: 1 to add. + +Summary by type: + tables: 1 to add + +Tables: + + orders_us + +DDL to be executed: +-------------------------------------------------- + +CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( + priority DEFAULT 10, + notes NOT NULL +) FOR VALUES IN ('us'); From 0c7757643e550668490e68fdb18e87424a785695 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Fri, 3 Jul 2026 03:23:14 -0700 Subject: [PATCH 3/4] fix: update plan.json hash for existing_parent test case Co-Authored-By: Claude Opus 4.6 --- .../plan.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json index 553dc66f..c1e32bdd 100644 --- a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json +++ b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json @@ -3,7 +3,7 @@ "pgschema_version": "1.11.1", "created_at": "1970-01-01T00:00:00Z", "source_fingerprint": { - "hash": "PLACEHOLDER" + "hash": "8872790ced32fbe419a3297dfdcd20a1b6e17650d2dcb1773161f505b66b2be8" }, "groups": [ { From e92bd0359225457b41753e6699e29282e89d9ae1 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Fri, 3 Jul 2026 03:51:30 -0700 Subject: [PATCH 4/4] refactor: consolidate issue_499 test fixtures into one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep the existing-parent case (stronger test — covers the review-flagged incremental scenario) and remove the redundant empty-schema case. Co-Authored-By: Claude Opus 4.6 --- .../diff.sql | 9 --------- .../new.sql | 6 +++--- .../old.sql | 10 +++++++++- .../plan.json | 14 +------------ .../plan.sql | 9 --------- .../plan.txt | 15 ++------------ .../diff.sql | 4 ---- .../new.sql | 14 ------------- .../old.sql | 9 --------- .../plan.json | 20 ------------------- .../plan.sql | 4 ---- .../plan.txt | 15 -------------- 12 files changed, 15 insertions(+), 114 deletions(-) delete mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/diff.sql delete mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/new.sql delete mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/old.sql delete mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json delete mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.sql delete mode 100644 testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.txt diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/diff.sql b/testdata/diff/create_table/issue_499_partition_column_overrides/diff.sql index eb3945f0..55f62f06 100644 --- a/testdata/diff/create_table/issue_499_partition_column_overrides/diff.sql +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/diff.sql @@ -1,12 +1,3 @@ -CREATE TABLE IF NOT EXISTS orders ( - id bigint NOT NULL, - region text NOT NULL, - priority integer DEFAULT 0, - notes text -) PARTITION BY LIST (region); - -CREATE TABLE IF NOT EXISTS orders_eu PARTITION OF orders FOR VALUES IN ('eu'); - CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( priority DEFAULT 10, notes NOT NULL diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/new.sql b/testdata/diff/create_table/issue_499_partition_column_overrides/new.sql index 72c2766e..023cc207 100644 --- a/testdata/diff/create_table/issue_499_partition_column_overrides/new.sql +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/new.sql @@ -5,10 +5,10 @@ CREATE TABLE public.orders ( notes text ) PARTITION BY LIST (region); +CREATE TABLE public.orders_eu PARTITION OF public.orders + FOR VALUES IN ('eu'); + CREATE TABLE public.orders_us PARTITION OF public.orders ( priority DEFAULT 10, notes NOT NULL ) FOR VALUES IN ('us'); - -CREATE TABLE public.orders_eu PARTITION OF public.orders - FOR VALUES IN ('eu'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/old.sql b/testdata/diff/create_table/issue_499_partition_column_overrides/old.sql index 03d7e9ae..8e58a50f 100644 --- a/testdata/diff/create_table/issue_499_partition_column_overrides/old.sql +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/old.sql @@ -1 +1,9 @@ --- Empty schema +CREATE TABLE public.orders ( + id bigint NOT NULL, + region text NOT NULL, + priority integer DEFAULT 0, + notes text +) PARTITION BY LIST (region); + +CREATE TABLE public.orders_eu PARTITION OF public.orders + FOR VALUES IN ('eu'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/plan.json b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.json index 01e12ee0..c1e32bdd 100644 --- a/testdata/diff/create_table/issue_499_partition_column_overrides/plan.json +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.json @@ -3,23 +3,11 @@ "pgschema_version": "1.11.1", "created_at": "1970-01-01T00:00:00Z", "source_fingerprint": { - "hash": "965b1131737c955e24c7f827c55bd78e4cb49a75adfd04229e0ba297376f5085" + "hash": "8872790ced32fbe419a3297dfdcd20a1b6e17650d2dcb1773161f505b66b2be8" }, "groups": [ { "steps": [ - { - "sql": "CREATE TABLE IF NOT EXISTS orders (\n id bigint NOT NULL,\n region text NOT NULL,\n priority integer DEFAULT 0,\n notes text\n) PARTITION BY LIST (region);", - "type": "table", - "operation": "create", - "path": "public.orders" - }, - { - "sql": "CREATE TABLE IF NOT EXISTS orders_eu PARTITION OF orders FOR VALUES IN ('eu');", - "type": "table", - "operation": "create", - "path": "public.orders_eu" - }, { "sql": "CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders (\n priority DEFAULT 10,\n notes NOT NULL\n) FOR VALUES IN ('us');", "type": "table", diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/plan.sql b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.sql index eb3945f0..55f62f06 100644 --- a/testdata/diff/create_table/issue_499_partition_column_overrides/plan.sql +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.sql @@ -1,12 +1,3 @@ -CREATE TABLE IF NOT EXISTS orders ( - id bigint NOT NULL, - region text NOT NULL, - priority integer DEFAULT 0, - notes text -) PARTITION BY LIST (region); - -CREATE TABLE IF NOT EXISTS orders_eu PARTITION OF orders FOR VALUES IN ('eu'); - CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( priority DEFAULT 10, notes NOT NULL diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides/plan.txt b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.txt index 556b5797..9799ba0d 100644 --- a/testdata/diff/create_table/issue_499_partition_column_overrides/plan.txt +++ b/testdata/diff/create_table/issue_499_partition_column_overrides/plan.txt @@ -1,25 +1,14 @@ -Plan: 3 to add. +Plan: 1 to add. Summary by type: - tables: 3 to add + tables: 1 to add Tables: - + orders - + orders_eu + orders_us DDL to be executed: -------------------------------------------------- -CREATE TABLE IF NOT EXISTS orders ( - id bigint NOT NULL, - region text NOT NULL, - priority integer DEFAULT 0, - notes text -) PARTITION BY LIST (region); - -CREATE TABLE IF NOT EXISTS orders_eu PARTITION OF orders FOR VALUES IN ('eu'); - CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( priority DEFAULT 10, notes NOT NULL diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/diff.sql b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/diff.sql deleted file mode 100644 index 55f62f06..00000000 --- a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/diff.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( - priority DEFAULT 10, - notes NOT NULL -) FOR VALUES IN ('us'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/new.sql b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/new.sql deleted file mode 100644 index 023cc207..00000000 --- a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/new.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE public.orders ( - id bigint NOT NULL, - region text NOT NULL, - priority integer DEFAULT 0, - notes text -) PARTITION BY LIST (region); - -CREATE TABLE public.orders_eu PARTITION OF public.orders - FOR VALUES IN ('eu'); - -CREATE TABLE public.orders_us PARTITION OF public.orders ( - priority DEFAULT 10, - notes NOT NULL -) FOR VALUES IN ('us'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/old.sql b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/old.sql deleted file mode 100644 index 8e58a50f..00000000 --- a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/old.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE TABLE public.orders ( - id bigint NOT NULL, - region text NOT NULL, - priority integer DEFAULT 0, - notes text -) PARTITION BY LIST (region); - -CREATE TABLE public.orders_eu PARTITION OF public.orders - FOR VALUES IN ('eu'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json deleted file mode 100644 index c1e32bdd..00000000 --- a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "version": "1.0.0", - "pgschema_version": "1.11.1", - "created_at": "1970-01-01T00:00:00Z", - "source_fingerprint": { - "hash": "8872790ced32fbe419a3297dfdcd20a1b6e17650d2dcb1773161f505b66b2be8" - }, - "groups": [ - { - "steps": [ - { - "sql": "CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders (\n priority DEFAULT 10,\n notes NOT NULL\n) FOR VALUES IN ('us');", - "type": "table", - "operation": "create", - "path": "public.orders_us" - } - ] - } - ] -} diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.sql b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.sql deleted file mode 100644 index 55f62f06..00000000 --- a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( - priority DEFAULT 10, - notes NOT NULL -) FOR VALUES IN ('us'); diff --git a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.txt b/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.txt deleted file mode 100644 index 9799ba0d..00000000 --- a/testdata/diff/create_table/issue_499_partition_column_overrides_existing_parent/plan.txt +++ /dev/null @@ -1,15 +0,0 @@ -Plan: 1 to add. - -Summary by type: - tables: 1 to add - -Tables: - + orders_us - -DDL to be executed: --------------------------------------------------- - -CREATE TABLE IF NOT EXISTS orders_us PARTITION OF orders ( - priority DEFAULT 10, - notes NOT NULL -) FOR VALUES IN ('us');