feat(pgsql): diff against the live database by default for direct output
Direct pgsql output (job output.conn_env, merge --output-conn) now reads the live schema and executes only the differences. full_ddl: true (job option) or --full-ddl (merge) restores the full idempotent DDL; file output is unchanged. - compare PKs by columns, skip constraint-backed indexes, normalize index method, FK actions, serial/numeric types, default literals/casts and truncated names - diff table and column comments instead of re-emitting them - remove leftover ZZDUMP debug code
This commit is contained in:
@@ -380,3 +380,30 @@ func TestDiffStatements_TruncatedConstraintNameMatches(t *testing.T) {
|
||||
t.Fatalf("expected truncated live name to match, got:\n%s", diffJoin(stmts))
|
||||
}
|
||||
}
|
||||
|
||||
func TestColumnDefaultsEqual_LiveRepresentations(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
model, cur interface{}
|
||||
want bool
|
||||
}{
|
||||
{"cast wrapped in parentheses", "gen_random_uuid()::text", "(gen_random_uuid())::text", true},
|
||||
{"jsonb re-spaced array", `'["openid","profile","email"]'`, `'["openid", "profile", "email"]'::jsonb`, true},
|
||||
{"backticked function", "`now()`", "now()", true},
|
||||
{"quoted literal with cast", "'[]'", "'[]'::jsonb", true},
|
||||
{"jsonb array already unquoted by the reader", `'["openid","profile"]'`, `["openid", "profile"]`, true},
|
||||
{"text with spaces and braces", "`'{actor} #{actor_id} - {chartofaccount}'`", "{actor} #{actor_id} - {chartofaccount}", true},
|
||||
{"cast on plain function stays equal", "gen_random_uuid()::text", "gen_random_uuid()::text", true},
|
||||
{"different jsonb content", `'["a"]'`, `'["b"]'::jsonb`, false},
|
||||
{"different function", "gen_random_uuid()::text", "(now())::text", false},
|
||||
{"different literal", "'active'", "'inactive'::text", false},
|
||||
{"nil vs value", nil, "now()", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := columnDefaultsEqual(tt.model, tt.cur); got != tt.want {
|
||||
t.Errorf("columnDefaultsEqual(%v, %v) = %v, want %v", tt.model, tt.cur, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user