Schema Diff: make the regression test assert its generated script, and fix what that found - #10305
Open
dpage wants to merge 1 commit into
Open
Schema Diff: make the regression test assert its generated script, and fix what that found#10305dpage wants to merge 1 commit into
dpage wants to merge 1 commit into
Conversation
…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
|
Caution Review failedAn 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. Comment |
hiteshjambhale
self-requested a review
August 18, 2026 10:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
SchemaDiffTestCasewrapped applying its generated script, and the comparison that follows, in a bareexcept Exceptionthat discarded both, so it reported a pass whatever the script did. That is why--pkg tools.schema_diffhas been printingon 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_DIFFERENCESwith 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
directory_diff()drops a plain value that only one side of the comparison has, and renderedCREATE TYPE ... AS RANGE (). With that fixed it wrote the catalogue's-placeholder out asCANONICAL = -; the reverse-engineered SQL path already maps-toNone, and the comparison path now does too.pg_dumpdoes. Note this is on the schema-diff queries only; the object explorer still lists them, which is worth its own look.get_columns.sqlcalls itcollnamewhilst the column templates rendercollspcname.Still open
table table_for_partition_1(#10301, the rebuild keeps its scaffolding default partition) andprocedure proc1(#10302,CREATE OR REPLACEwraps 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) andtables(469) all pass against PostgreSQL 18, andpycodestyle --config=.pycodestyleis clean. I confirmed the new assertions bite by watching them fail on each bug in turn before fixing it.