-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redundant alembic migrations with foreign keys drop/create #145
Comments
cc @snowstakeda @keller00 |
Hey guys, any update on this issue? |
bump on this. |
Hey, I'm sorry but we don't officially support Alembic. |
Hi all! |
This is happening on all migrations. Any update on this? |
i'm facing this issue also right now. Any update guys? |
I dont know if I'm yet convinced this is a foolproof solution or not, but I set As far as I can tell, you're forced to set By using some other schema, i.e. |
thank you for sharing the workaround earlier here! for the full support and necessary changes, we'll consider this as a possible enhancement in the future but as mentioned earlier by the dev team, contributions are more than welcome and can likely speed up implementation by a great deal. |
What version of Python are you using (
python --version
)?A. 3.7.5
What operating system and processor architecture are you using (
python -c 'import platform; print(platform.platform())'
)?A. Darwin-18.7.0-x86_64-i386-64bit
What are the component versions in the environment (
pip list
)?Relevant ones:
Flask 1.1.1
Flask-Migrate 2.5.2
Flask-SQLAlchemy 2.4.1
snowflake-sqlalchemy 1.1.17
What did you do?
The complete problem is stated in https://stackoverflow.com/questions/59449387/prevent-alembic-auto-migration-from-being-generated-when-there-are-no-changes-to . Essentially, I built a minimal flask application using sqlalchemy for my models (2 tables with 1 foreign key between them), and snowflake as my backend database. This package proved beneficial for this integration :). After I make and execute the first migration, my db is as expected. However, when I run
alembic revision --autogenerate
again (through flask-migrate), I get an extra/duplicate/redundant migration file which drops the previous foreign key and creates a new one. This is due to a schema mismatch when comparing metadata and connection fks on alembic side. I always get a redundant migration file no matter how often I migrate and upgrade.What did you expect to see?
No migration file generated at all, since there's no changes to the schema
What did you see instead?
Redundant migration file:
The problem identified by me here is that the way alembic works with schema names is a lil involved: Redundant Foreign Key migrations (again) sqlalchemy/alembic#519 . As the author of Alembic says there, the schema name in foreign keys created through SQLAlchemy will be set to empty, because we don't pre-define the schema names when declaring a new class (table) in our models. When comparing, Alembic sees the schema for the foreign key in the metadata as None. When it gets the existing foreign key from the connection, the schema is returned through https://github.com/snowflakedb/snowflake-sqlalchemy/blob/master/snowdialect.py#L290 which sets the schema name to the db connection name (not None), as required by snowflake. Since there is a mismatch, Alembic drops the foreign key and tries to create it again every single time. I was able to fix the problem by changing that line to:
However, I am not sure this is the correct permanent fix, since this seems specific to integration with Alembic. Please let me know if you have any questions. Thanks!
My question is: is it okay for the
referred_schema
to be returned as None for foreign keys? Should this be changed permanently in the repo? What other options do I have to make this work?The text was updated successfully, but these errors were encountered: