You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by xd...@apache.org on 2021/01/25 18:53:38 UTC

[airflow] branch master updated: Make Smart Sensors DB Migration idempotent (#13892)

This is an automated email from the ASF dual-hosted git repository.

xddeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new d7f7c63  Make Smart Sensors DB Migration idempotent (#13892)
d7f7c63 is described below

commit d7f7c63ca8d7a8ebcbd22e1e1c378b71d751314a
Author: Kaxil Naik <ka...@gmail.com>
AuthorDate: Mon Jan 25 18:53:24 2021 +0000

    Make Smart Sensors DB Migration idempotent (#13892)
---
 .../versions/e38be357a868_update_schema_for_smart_sensor.py  | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/airflow/migrations/versions/e38be357a868_update_schema_for_smart_sensor.py b/airflow/migrations/versions/e38be357a868_update_schema_for_smart_sensor.py
index 8b519d4..e603199 100644
--- a/airflow/migrations/versions/e38be357a868_update_schema_for_smart_sensor.py
+++ b/airflow/migrations/versions/e38be357a868_update_schema_for_smart_sensor.py
@@ -27,6 +27,7 @@ import sqlalchemy as sa
 from alembic import op
 from sqlalchemy import func
 from sqlalchemy.dialects import mysql
+from sqlalchemy.engine.reflection import Inspector
 
 # revision identifiers, used by Alembic.
 revision = 'e38be357a868'
@@ -50,6 +51,11 @@ def sa_timestamp():  # noqa: D103
 def upgrade():  # noqa: D103
 
     conn = op.get_bind()
+    inspector = Inspector.from_engine(conn)
+    tables = inspector.get_table_names()
+    if 'sensor_instance' in tables:
+        return
+
     if conn.dialect.name == 'mysql':
         timestamp = mysql_timestamp
     elif conn.dialect.name == 'mssql':
@@ -84,4 +90,8 @@ def upgrade():  # noqa: D103
 
 
 def downgrade():  # noqa: D103
-    op.drop_table('sensor_instance')
+    conn = op.get_bind()
+    inspector = Inspector.from_engine(conn)
+    tables = inspector.get_table_names()
+    if 'sensor_instance' in tables:
+        op.drop_table('sensor_instance')