sadpandajoe commented on code in PR #36086: URL: https://github.com/apache/superset/pull/36086#discussion_r2525087617
########## superset/migrations/versions/2025-11-12_12-54_x2s8ocx6rto6_expand_username_field_to_128_chars.py: ########## @@ -0,0 +1,97 @@ +# 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. +"""Expand username field to 128 chars + +Revision ID: x2s8ocx6rto6 +Revises: c233f5365c9e +Create Date: 2025-11-12 12:54:00.000000 + +""" + +import logging + +import sqlalchemy as sa +from alembic import op + +from superset.migrations.shared.utils import get_table_column + +logger = logging.getLogger("alembic.env") + +# revision identifiers, used by Alembic. +revision = "x2s8ocx6rto6" +down_revision = "c233f5365c9e" + + +def upgrade(): + """Expand ab_user.username field from 64 to 128 characters.""" + # Check current column length to avoid errors if already upgraded + column_info = get_table_column("ab_user", "username") + + if column_info is None: + logger.warning("Column ab_user.username not found. Skipping migration.") + return + + # Get current length - check the type attribute + current_type = column_info.get("type") + current_length = getattr(current_type, "length", None) + + if current_length is not None and current_length == 128: + logger.info( + "Column ab_user.username already has length %s. Skipping migration.", + current_length, + ) + return + + with op.batch_alter_table("ab_user") as batch_op: Review Comment: Just checking that we don't have a utils to do batch alters. If not then this looks good to me, else we should switch to the util -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
