Add support for topological sorting of tables and aggregate function changes #237
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.
This pull request builds on the changes made in djrobstep/schemainspect#90 to add a few enhancements to migra:
Topological sorting of tables
When generating the SQL statements to create tables, migra now takes into account the full dependency tree between tables. It builds a dependency graph using the new
dependents
attribute added toInspectedTable
in schemainspect. It then sorts the tables topologically based on this graph. This now handles cases where a column is an array of a composite type.Support for changes to aggregate functions
The
get_selectable_changes
function inchanges.py
was updated to include aggregate functions (relationtype 'a') in addition to regular functions when generating SQL statements for function changes.This change utilizes the new
InspectedAggFunction
class and related functionality added in schemainspect to make migra aware of aggregate functions and include them in schema comparisons and migrations.The
Changes
class has a newcomments
property that returns a partial function for generating SQL statements for changes to comments on database objects. Theadd_all_changes
method was updated to include creating and dropping comments at the appropriate points in the migration process.This integrates with the new comment inspection capabilities added in schemainspect, allowing migra to include comment changes as part of schema migrations.
With these changes, migra is now able to generate more accurate migration scripts, particularly in cases involving table dependencies, aggregate functions, and object comments. It can produce migrations that run correctly on the first try in more cases than before.
Please let me know if you have any questions or feedback on these changes. I'm happy to discuss further or make revisions as needed.