|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +"""change_mediumtext_to_longtext |
| 18 | +Revision ID: f7b6750b67e8 |
| 19 | +Revises: f84fde59123a |
| 20 | +Create Date: 2024-05-09 19:19:46.630140 |
| 21 | +""" |
| 22 | + |
| 23 | +# revision identifiers, used by Alembic. |
| 24 | +revision = "f7b6750b67e8" |
| 25 | +down_revision = "f84fde59123a" |
| 26 | + |
| 27 | +from alembic import op # noqa: E402 |
| 28 | +from sqlalchemy.dialects.mysql import MEDIUMTEXT # noqa: E402 |
| 29 | +from sqlalchemy.dialects.mysql.base import MySQLDialect # noqa: E402 |
| 30 | + |
| 31 | +from superset.migrations.shared.utils import get_table_column # noqa: E402 |
| 32 | +from superset.utils.core import LongText, MediumText # noqa: E402 |
| 33 | + |
| 34 | + |
| 35 | +def upgrade(): |
| 36 | + if isinstance(op.get_bind().dialect, MySQLDialect): |
| 37 | + for item in ["query.executed_sql", "query.select_sql"]: |
| 38 | + table_name, column_name = item.split(".") |
| 39 | + |
| 40 | + if (column := get_table_column(table_name, column_name)) and isinstance( |
| 41 | + column["type"], |
| 42 | + MEDIUMTEXT, |
| 43 | + ): |
| 44 | + with op.batch_alter_table(table_name) as batch_op: |
| 45 | + batch_op.alter_column( |
| 46 | + column_name, |
| 47 | + existing_type=MediumText(), |
| 48 | + type_=LongText(), |
| 49 | + existing_nullable=True, |
| 50 | + ) |
| 51 | + |
| 52 | + |
| 53 | +def downgrade(): |
| 54 | + pass |
0 commit comments