added migration order to respect FK dependencies - #26
Open
motriys98-alt wants to merge 1 commit into
Open
Conversation
|
hit exactly this on a real OWUI migration — 3 tables (chat_file, knowledge_file, group_member) landed with 0 rows. Your hardcoded priority map is a straightforward fix; a retry pass over failed tables might be more resilient to future OWUI schema additions |
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.
Problem
The migration script (migrator.py) migrates tables from SQLite to PostgreSQL in the order returned by sqlite_master, which does not respect foreign key (FK) dependencies.
This causes Foreign Key constraint violations for child tables that reference parent tables not yet migrated:
Root Cause
The migration loop uses the raw order from sqlite_master:
Old code — order from sqlite_master (arbitrary, ignores FK)
sqlite_cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
tables = sqlite_cursor.fetchall()
for (table_name,) in tables:
await process_table(table_name, ...)
In the original order, chat was migrated after chat_file and chat_message, causing FK violations.
Solution
Key priority anchors: