Skip to content

Commit

Permalink
fix: Migration order due to cherry which went astray (#26160)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Dec 2, 2023
1 parent b7a9c22 commit 8644b1a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 21 deletions.
8 changes: 3 additions & 5 deletions superset/migrations/shared/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
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()

Expand All @@ -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")
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 8644b1a

Please sign in to comment.