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/26 23:58:34 UTC

[GitHub] [airflow] kaxil opened a new pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

kaxil opened a new pull request #13921:
URL: https://github.com/apache/airflow/pull/13921


   closes https://github.com/apache/airflow/issues/13877
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#discussion_r566513043



##########
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:
       Removed the conditional to check DB, went with the approach Tomek suggested




----------------------------------------------------------------
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



[GitHub] [airflow] github-actions[bot] commented on pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#issuecomment-767911676


   [The Workflow run](https://github.com/apache/airflow/actions/runs/513635000) is cancelling this PR. Building images for the PR has failed. Follow the the workflow link to check the reason.


----------------------------------------------------------------
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



[GitHub] [airflow] kaxil commented on pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
kaxil commented on pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#issuecomment-769155881


   @ephraimbuddy @jhtimmins Can you take a look and review too please


----------------------------------------------------------------
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



[GitHub] [airflow] github-actions[bot] commented on pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#issuecomment-770007219


   The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#discussion_r566258541



##########
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:
       Won't `batch_alter_table` work for all? It seems to work for mysql at least:
   https://github.com/apache/airflow/blob/74da0faa7b85fe8a87d0a245179f8632fc93fd51/airflow/migrations/versions/74effc47d867_change_datetime_to_datetime2_6_on_mssql_.py#L52
   




----------------------------------------------------------------
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



[GitHub] [airflow] github-actions[bot] commented on pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#issuecomment-768701080


   [The Workflow run](https://github.com/apache/airflow/actions/runs/516735406) is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.


----------------------------------------------------------------
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



[GitHub] [airflow] github-actions[bot] commented on pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#issuecomment-768663171


   [The Workflow run](https://github.com/apache/airflow/actions/runs/516593374) is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.


----------------------------------------------------------------
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



[GitHub] [airflow] kaxil merged pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
kaxil merged pull request #13921:
URL: https://github.com/apache/airflow/pull/13921


   


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#discussion_r566512824



##########
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:
       Just tested it on Postgres too -- worked fine -- pushed the changes in https://github.com/apache/airflow/pull/13921/commits/890aa9336fa8d1ecf5f7305095bad44d9b961d97




----------------------------------------------------------------
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



[GitHub] [airflow] kaxil commented on pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
kaxil commented on pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#issuecomment-770003867


   > @kaxil looks good! What's the reason for the context manager?
   
   https://alembic.sqlalchemy.org/en/latest/batch.html -- That one SQLite runs a SQL query to transfer the data from the existing table to the new one, then drop the old table


----------------------------------------------------------------
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



[GitHub] [airflow] github-actions[bot] commented on pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#issuecomment-768345764


   [The Workflow run](https://github.com/apache/airflow/actions/runs/515401738) is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#discussion_r566285080



##########
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:
       The main reason was 
   `for fkey in inspector.get_foreign_keys(table_name="known_event", referred_table="users"):` was returning 2 elements, one of which had `fkey['name']` as `None` . And if you call `bop.drop_constraint(fkey['name'], type_="foreignkey")` for sqlite with `fkey['name']` it errors and complains about name not specified while it works for MySQL and Postgres -- so thought would be easier and safe to just keep the current behaviour with Postgres and MySQL.  (didn't investigate further on the foreign key entry with None name)
   
   




----------------------------------------------------------------
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



[GitHub] [airflow] jhtimmins commented on pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
jhtimmins commented on pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#issuecomment-770002588


   @kaxil looks good! What's the reason for the context manager?


----------------------------------------------------------------
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



[GitHub] [airflow] kaxil commented on pull request #13921: Fix DB Migration for SQLite to upgrade to 2.0

Posted by GitBox <gi...@apache.org>.
kaxil commented on pull request #13921:
URL: https://github.com/apache/airflow/pull/13921#issuecomment-769987323


   CI is green, ready to be re-reviewed 


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
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