Add function, view, and materialized view dependency ordering#286
Open
da77a wants to merge 1 commit into
Open
Conversation
- Track function→table/view deps via pg_depend + body-text regex - Track view→function deps via pg_depend - Track matview→function deps via pg_depend - Include views and matviews in TableDependencies (relkind v,m) - Cascade view/matview recreation when dependencies are recreated - Fix cycle in function ordering (only emit reverse edges for removed deps) - Add unqualified FROM/JOIN detection in function bodies - Add --skip-privileges CLI flag - 50+ acceptance tests
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.
Function and view dependency ordering
This PR adds dependency tracking for functions, views, and materialized views so that
pg-schema-diff(mostly) correctly orders DDL statements when these objects reference each other.Motivation
Less cases where manual migration authoring is needed due to cascading dependencies issues involving objects other than tables.
This is the second attempt after some "working except when it doesn't" problems found using the first attempt.
Approach
This attempt created failing test cases systematically for the unsupported/failing scenarios, then fixed (most of) them.
What works
From-scratch creation — given any schema containing interdependent functions, views, and materialized views, the generated plan creates objects in the correct order:
FROM/JOIN(qualified and unqualified)%ROWTYPEor[]composite type declarationsIncremental migration — when a table change forces a view to be recreated (column rename/delete), dependent views and materialized views are cascaded:
Identical-schema diffs — diffing a schema against itself produces an empty plan, even when views depend on other views or call functions.
Known gaps (with failing tests documenting each)
FROM t1, t2, t3— only first table detectedCREATE OR REPLACEis always emitted, PG rejects if return type differsApproach
GetViews/GetMaterializedViews/GetProcs%ROWTYPE,[], andFROM/JOINreferences in function bodies) — best-effort, used for ordering onlyTesting
Acceptance test cases covering all the above scenarios, including the documented gaps (marked with
expectedPlanErrorContains).