*WIP* schemadiff: Diff()
of schemas ordered by valid dependencies
#12184
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.
Description
A
schemadiff
'sSchema
is normalized to have tables in foreign key dependency order (parents come first, children later), as well as in view dependency order (tables first, then views that only rely on tables, then 2nd level views etc.). This makes it possible to create, or apply, the schema by iterating its entities in order.With this PR, we also sort the
Diff()
of two schemas, such that the diff can be applied in-order to a schema and without error. At this time, the diff is sorted like so:CREATE TABLE
follow the same ordering for schema creation, ie. foreign key parents come first, then their children, and recursively onwards.CREATE TABLE
comes beforeCREATE VIEW
, again following same logic as illustrated above.DROP VIEW
uses reverse order of creation, such that we first drop the views with most dependencies, then those with fewest dependenciesDROP TABLE
uses reverse order of creation, such that we firstDROP
a foreign key relationship's child beforeDROP
ping its parent.There is still work to be done where it comes to modifying foreign key constraints in existing tables.
Related Issue(s)
Checklist
Deployment Notes