Skip to content

Schema Diff: make the regression test assert its generated script, and fix what that found - #10305

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/schema-diff-serial-followup
Open

Schema Diff: make the regression test assert its generated script, and fix what that found#10305
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/schema-diff-serial-followup

Conversation

@dpage

@dpage dpage commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What this is

SchemaDiffTestCase wrapped applying its generated script, and the comparison that follows, in a bare except Exception that discarded both, so it reported a pass whatever the script did. That is why --pkg tools.schema_diff has been printing

syntax error at or near ")"
LINE 995: );

on every run whilst cheerfully reporting 2 tests passed. This makes the test assert what it was written to assert, and fixes the bugs that turning it on exposed. Each of those is filed separately, and the commit message maps them one to one.

The test

It now fails when an object's SQL does not apply, and when applying the whole script leaves the two databases different. Two differences it cannot settle yet are listed in KNOWN_DIFFERENCES with their issue numbers, and the test also fails if one of them starts passing, so the list cannot quietly rot.

Objects go in one at a time and are retried, rather than as a single script, because the script is no longer ordered by dependency (#10295), so an object can fail purely because something it needs comes later on. Retrying tells that apart from SQL that is simply wrong. When #10295 is fixed this can go back to applying the script in one go.

restore_schema() now returns the error alongside its status, so a failure says which statement did not apply, and the script is left on disk when the test fails since it is the only evidence of what went wrong.

The fixes

Still open

table table_for_partition_1 (#10301, the rebuild keeps its scaffolding default partition) and procedure proc1 (#10302, CREATE OR REPLACE wraps the body in newlines) are the two known differences. #10292 and #10295 are untouched and described on their own issues; #10295 in particular means users' generated scripts can fail to run, and wants JS work.

Testing

tools.schema_diff (3), resql, foreign_tables (44), sequences (11), types (39), functions (74), casts (38) and tables (469) all pass against PostgreSQL 18, and pycodestyle --config=.pycodestyle is clean. I confirmed the new assertions bite by watching them fail on each bug in turn before fixing it.

…d fix what that found

The Schema Diff comparison test wrapped applying its generated script, and
the comparison that follows it, in a bare `except Exception` that discarded
both. It reported a pass whatever the script did, which is why it printed
`syntax error at or near ")"` on every run whilst claiming two tests passed.
It now fails when an object's SQL does not apply, and when applying the lot
leaves the two databases different, with a short list of the differences
that are known not to settle yet so that the list cannot quietly rot.

Objects are applied one at a time and retried rather than as a single
script, because the script is no longer ordered by dependency (pgadmin-org#10295), so
an object can fail purely because something it needs comes later on;
retrying tells that apart from SQL that is simply wrong.

Turning the assertions on found the following, each of which is fixed here:

* A range type being dropped and recreated because its kind changed lost
  its subtype, because directory_diff() drops a plain value that only one
  side of the comparison has, and rendered `CREATE TYPE ... AS RANGE ()`.
  Once that was fixed it wrote the catalogue's `-` placeholder out as
  `CANONICAL = -`, which the reverse-engineered SQL path already avoids.
  Both are now handled where the comparison data is built (pgadmin-org#10304).

* The constructor functions, casts and multirange types that PostgreSQL
  creates for a range type were compared as though a user had written them,
  so the script tried to recreate objects that come into being with their
  parent type: 47 of 151 objects in the test's fixtures were these.
  Internal dependencies are now excluded alongside extension ones, matching
  what pg_dump does.

* Recreating a foreign table declared any column that also differed twice,
  because a changed column was appended to the table's existing columns
  rather than replacing the entry already there (pgadmin-org#10297).

* Raising a sequence's MINVALUE above the value it currently sits at, or
  lowering MAXVALUE below it, generated a statement PostgreSQL rejects
  outright, taking every other change to that sequence with it. Such a
  change is now accompanied by the RESTART it requires (pgadmin-org#10298).

* A foreign table column added by Schema Diff lost its collation, because
  get_columns.sql calls it collname whilst the column templates render
  collspcname (pgadmin-org#10300).

* A comparison that threw part way through emitted its failure and then
  reported success as well, handing the client a fraction of the databases
  as though it were a complete result (pgadmin-org#10303).

Two differences remain listed as known: a rebuilt partitioned table keeps
the default partition used as scaffolding for the data copy (pgadmin-org#10301), and
CREATE OR REPLACE wraps a function body in newlines, leaving a
whitespace-only difference (pgadmin-org#10302).

Fixes pgadmin-org#10293
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Caution

Review failed

An error occurred during the review process. Please try again later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kundansable kundansable added this to the 9.18 milestone Aug 18, 2026
@hiteshjambhale
hiteshjambhale self-requested a review August 18, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants