You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/01/28 19:33:33 UTC

[GitHub] [airflow] ephraimbuddy commented on a change in pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

ephraimbuddy commented on a change in pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#discussion_r566355581



##########
File path: airflow/migrations/versions/cf5dc11e79ad_drop_user_and_chart.py
##########
@@ -47,7 +47,12 @@ def upgrade():  # noqa: D103
 
     if 'known_event' in tables:
         for fkey in inspector.get_foreign_keys(table_name="known_event", referred_table="users"):
-            op.drop_constraint(fkey['name'], 'known_event', type_="foreignkey")
+            if conn.dialect.name == "sqlite":
+                if fkey['name']:
+                    with op.batch_alter_table(table_name='known_event') as bop:
+                        bop.drop_constraint(fkey['name'], type_="foreignkey")
+            else:
+                op.drop_constraint(fkey['name'], 'known_event', type_="foreignkey")

Review comment:
       
   What if you use naming_convention? batch_alter_table supports naming_convention where unnamed foreign_keys are named during reflection. https://alembic.sqlalchemy.org/en/latest/batch.html
   `naming_convention = {
       "fk":
       "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
   }`
   ```suggestion
               with op.batch_alter_table(table_name='known_event', naming_convention=naming_convention) as bop:
                   bop.drop_constraint(fkey['name'], type_="foreignkey")
   
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org