Fix for nodes_closure migration when node name matches parent#1116
Fix for nodes_closure migration when node name matches parent#1116danielballan merged 6 commits intobluesky:mainfrom
Conversation
If we do the self-referential rows after the non-referential ones, we can clobber any self-referential rows that got in accidentally.
|
Need to update so that SQLite still works. |
|
This worked on my database: $ tiled catalog upgrade-database "postgresql+asyncpg://***:***@***/catalog"
Starting migration to add closure table...
Added 'parent' column and foreign key to 'nodes' table.
Created 'nodes_closure' table with uniqueness constraint.
Inserted root node with id=0.
Maximum depth of ancestors found: 3
Initialized parent of each node as 0 and set depth in 'nodes_closure'.
Updated 'parent' column and 'nodes_closure' for depth 1.
Updated 'parent' column and 'nodes_closure' for depth 2.
Updated 'parent' column and 'nodes_closure' for depth 3.
Completed updating 'parent' column recursively.
Inserted self-referential records into 'nodes_closure' for each node.
Updated index in the 'nodes' table.
Created unique constraint on (key, parent) pairs in 'nodes' table.
Dropped 'ancestors' column from the 'nodes' table.
Added triggers to maintain the closure table.
Migration to add closure table completed successfully. |
|
Thanks for upstreaming this fix, @canismarko! I leave it to @genematx's review. |
5797d5d to
1183354
Compare
1183354 to
e142a8d
Compare
|
Thanks for the update, @canismarko! Just to be clear, the node that caused problems has the following path in the catalog: |
Yes, that's right. Here is the SQL row: https://gist.github.com/canismarko/4b6244f6ee9bd95b473db20cbb88d78f#file-sql |
|
I think this should fix it, @canismarko. We don't need to change the order of migration steps, but we do need to check if the child has the same name (key) as its parent. |
|
Great, thanks. I'll take a look. |
Fix Alembic Migration
|
@genematx I restored to original DB from backup and ran the updated migration you sent. It ran without errors. ✅ I think this is ready to review and/or merge. |
Modifies the alembic migration that builds the initial
nodes_closuretable to handle a catalog with edge cases. See the linked issue for details.Fixes:
Checklist