Skip to content

Pull operator classes an extension contests, leave out settings the server doesn't know, fail diff on schema errors - #363

Merged
archlemon merged 2 commits into
mainfrom
pg19-opclass-settings
Nov 21, 2026
Merged

archlemon merged 2 commits into
mainfrom
pg19-opclass-settings

Conversation

@archlemon

Copy link
Copy Markdown
Member

Fixes #337
Fixes #338
Fixes #350

Part of #325.

  • Pull leaves out extension operator classes that are defaults only on some versions (inet/cidr GiST on 19) #337: introspection marks an index column's operator class as contested when it belongs to an extension, or when an extension has a class for the same type and access method. Which of those is the default changes between versions: btree_gist's gist_inet_ops is the GiST default for inet on 18, core's inet_ops on 19. pgy pull now writes contested classes in index opclasses and in exclusion constraint expressions (ExcludeWithContestedOpclasses) even when they are the default, so YAML pulled on 18 builds the same indexes on 19 and the other way round. A named class already compared equal to the live one. Side effect: pulled YAML also names btree_gist/citext default classes such as gist_int4_ops.
  • Settings unknown to the server pass validate and diff, then fail at migrate #338: pgy diff looks up the setting names without a dot (database set and roles, role set, function and procedure set) with pg_settings_get_flags, and leaves unknown ones (e.g. escape_string_warning, removed in 19) out of the plan with a warning instead of planning a statement that fails at migrate. Dotted names are placeholders and are not looked up.
  • diff turns YAML errors into warnings and writes broken SQL #350: validate errors no longer become warnings in pgy diff: it prints them, writes nothing and exits 1, --no-warnings included. This reverses the errors-as-warnings choice of a3dba0c; validate's warning-severity findings and policy findings stay warnings. Help text, README and docs updated.

Tests: unit tests for each part, internal/cli/diff_invalid_test.go, integration opclass_settings_test.go and pull fixture contested_opclasses.sql. make test, go vet, and the cli + integration suites (with PGY_TEST_REQUIRE_PL=1 and the pg_dump comparison) pass on PostgreSQL 15, 18 and 19.

…erver doesn't know, fail diff on schema errors.

Which operator class is a type's default can change between server
versions: btree_gist's gist_inet_ops is the GiST default for inet on
PostgreSQL 18, core's inet_ops on 19. Pull left default classes out of
indexes and exclusion constraints, so YAML pulled on 18 built inet_ops
indexes on 19, a database upgraded to 19 planned to recreate them under
--unsafe, and YAML pulled on 19 built gist_inet_ops on 18, where an
exclusion constraint WITH && then failed. Introspection now marks a class
as contested when it belongs to an extension or an extension has a class
for the same type and access method, and pull writes contested classes
in index opclasses and exclusion constraint expressions even when they
are the default. A named class already compares equal to the live one.

A setting the server doesn't recognise (escape_string_warning, removed in
PostgreSQL 19) passed validate and diff and failed the migration with
unrecognized configuration parameter. diff now looks up the names without
a dot under database set and roles, role set, and function and procedure
set with pg_settings_get_flags, and leaves unknown ones out of the plan
with a warning. Names with a dot are placeholders PostgreSQL accepts, and
are not looked up.

diff printed validate's errors as warnings and went on to write a plan,
such as add constraint "c1" check () for a constraint written with check:
instead of expression, and exited 2. It now prints them and exits 1
without writing the buffer, --no-warnings included.
@archlemon
archlemon merged commit 06e7b94 into main Nov 21, 2026
8 checks passed
@archlemon
archlemon deleted the pg19-opclass-settings branch November 21, 2026 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant