fix(migrations): Prevent core/internal migrations from dropping external app tables#8
Merged
fix(migrations): Prevent core/internal migrations from dropping external app tables#8
Conversation
…nal app tables Core and internal app migrations were incorrectly attempting to drop external app tables during autogenerate because Alembic compared target metadata (core/internal only) against the entire database (including external apps). Changes: - Load app registry in core migration command to identify external apps - Collect external app table names (models + version tables) in autogen - Add include_object callback in core env.py to exclude external app tables - Apply exclusion logic to both core and internal app migrations (they share the same migration directory and version table) External apps remain unaffected as they use isolated migration systems.
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
When creating core or internal app migrations after external apps were attached to the project, Alembic's autogenerate would incorrectly attempt to drop external app tables. This happened because:
Example scenario:
eapp_eusers,alembic_version_eappDefaultUsersmodel and generates migrationop.drop_table('eapp_eusers')andop.drop_table('alembic_version_eapp')Solution
This PR fixes the issue by:
include_objectcallback in core migrationsenv.pyto exclude external app tables from autogenerate comparisoncore/db/migrations/) and version table (alembic_version)Changes
fastappkit/cli/migrate.py: Load registry and pass to autogen for core migrationsfastappkit/migrations/autogen.py: Collect external app tables and store in config attributesfastappkit/cli/templates/project/core/db/migrations/env.py.j2: Addinclude_objectcallback to filter external app tablesTesting
Notes
include_objectcallback mechanism