You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jo...@apache.org on 2023/12/02 02:29:28 UTC

(superset) branch master updated: fix: Migration order due to cherry which went astray (#26160)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8644b1a319 fix: Migration order due to cherry which went astray (#26160)
8644b1a319 is described below

commit 8644b1a3192ffef3d20357f76cfa1feac20e4147
Author: John Bodley <45...@users.noreply.github.com>
AuthorDate: Fri Dec 1 18:29:21 2023 -0800

    fix: Migration order due to cherry which went astray (#26160)
---
 superset/migrations/shared/utils.py                |  8 ++--
 ...317970b4400c_added_time_secondary_column_to_.py | 34 +++++++++--------
 ...12-01_12-03_b7851ee5522f_replay_317970b4400c.py | 44 ++++++++++++++++++++++
 3 files changed, 65 insertions(+), 21 deletions(-)

diff --git a/superset/migrations/shared/utils.py b/superset/migrations/shared/utils.py
index 32e7dc1a39..2ae0dfeac1 100644
--- a/superset/migrations/shared/utils.py
+++ b/superset/migrations/shared/utils.py
@@ -43,11 +43,9 @@ def table_has_column(table: str, column: str) -> bool:
     :param column: A column name
     :returns: True iff the column exists in the table
     """
-    config = op.get_context().config
-    engine = engine_from_config(
-        config.get_section(config.config_ini_section), prefix="sqlalchemy."
-    )
-    insp = reflection.Inspector.from_engine(engine)
+
+    insp = inspect(op.get_context().bind)
+
     try:
         return any(col["name"] == column for col in insp.get_columns(table))
     except NoSuchTableError:
diff --git a/superset/migrations/versions/2023-09-06_13-18_317970b4400c_added_time_secondary_column_to_.py b/superset/migrations/versions/2023-09-06_13-18_317970b4400c_added_time_secondary_column_to_.py
index 859a6fe590..4972a86911 100755
--- a/superset/migrations/versions/2023-09-06_13-18_317970b4400c_added_time_secondary_column_to_.py
+++ b/superset/migrations/versions/2023-09-06_13-18_317970b4400c_added_time_secondary_column_to_.py
@@ -32,7 +32,7 @@ from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import Session
 
 from superset import db
-from superset.migrations.shared.utils import paginated_update
+from superset.migrations.shared.utils import paginated_update, table_has_column
 
 Base = declarative_base()
 
@@ -45,23 +45,25 @@ class SqlaTable(Base):
 
 
 def upgrade():
-    op.add_column(
-        "tables",
-        sa.Column(
-            "always_filter_main_dttm",
-            sa.Boolean(),
-            nullable=True,
-            default=False,
-            server_default=sa.false(),
-        ),
-    )
+    if not table_has_column("tables", "always_filter_main_dttm"):
+        op.add_column(
+            "tables",
+            sa.Column(
+                "always_filter_main_dttm",
+                sa.Boolean(),
+                nullable=True,
+                default=False,
+                server_default=sa.false(),
+            ),
+        )
 
-    bind = op.get_bind()
-    session = db.Session(bind=bind)
+        bind = op.get_bind()
+        session = db.Session(bind=bind)
 
-    for table in paginated_update(session.query(SqlaTable)):
-        table.always_filter_main_dttm = False
+        for table in paginated_update(session.query(SqlaTable)):
+            table.always_filter_main_dttm = False
 
 
 def downgrade():
-    op.drop_column("tables", "always_filter_main_dttm")
+    if table_has_column("tables", "always_filter_main_dttm"):
+        op.drop_column("tables", "always_filter_main_dttm")
diff --git a/superset/migrations/versions/2023-12-01_12-03_b7851ee5522f_replay_317970b4400c.py b/superset/migrations/versions/2023-12-01_12-03_b7851ee5522f_replay_317970b4400c.py
new file mode 100644
index 0000000000..b4286736f0
--- /dev/null
+++ b/superset/migrations/versions/2023-12-01_12-03_b7851ee5522f_replay_317970b4400c.py
@@ -0,0 +1,44 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""replay 317970b4400c
+
+Revision ID: b7851ee5522f
+Revises: 4b85906e5b91
+Create Date: 2023-12-01 12:03:27.538945
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "b7851ee5522f"
+down_revision = "4b85906e5b91"
+
+from importlib import import_module
+
+import sqlalchemy as sa
+from alembic import op
+
+module = import_module(
+    "superset.migrations.versions.2023-09-06_13-18_317970b4400c_added_time_secondary_column_to_"
+)
+
+
+def upgrade():
+    module.upgrade()
+
+
+def downgrade():
+    module.downgrade()