Problems adding column to Superset User model (ab_user, Flask, Flask-Migrate)

I am trying to extend the user model in Apache/Superset and add that change to the migration folder. I want to add a new column called “solution_uuid” to the model.

  • I made my own fork of Apache/Superset from the TAG 4.0.2 (since that was the last stable release)
  • Then I added my custom models.py, security.py and views.py in superset/custom directory

This is the custom user model:

from flask_appbuilder.security.sqla.models import User
from sqlalchemy import (
    Column,
    String
)
class CustomUser(User):
    __tablename__ = "ab_user"
    solution_uuid = Column(String)

Before changing the default user model to use my custom one, I ran superset db migrate and superset db upgrade because there were some changes that hadn’t been migrated apparently (I assume these are changes that were already in the source code but for some reason hadn’t been migrated?). After this migration I applied my code changes and ran the same command (So now I generated 2 new migration files, the last one containing my solution_uuid changes).

When running this in docker locally it seemed to work, so I pushed the changes to my fork. The problem comes when I clone this repository into a server and try to run it (again, using docker-compose) I get the following error when superset-init runs superset db upgrade

INFO  [alembic.runtime.migration] Running upgrade 87d38ad83218 -> 17fcea065655, change_text_to_mediumtext
superset_init         | INFO  [alembic.runtime.migration] Running upgrade 17fcea065655 -> 346d233b7fc2, empty message
superset_init         | INFO  [alembic.runtime.migration] Running upgrade 346d233b7fc2 -> ddb1e557dd93, add solution_uuid
superset_db           | 2024-07-18 12:23:57.521 UTC [78] ERROR:  column "solution_uuid" of relation "ab_user" already exists
superset_db           | 2024-07-18 12:23:57.521 UTC [78] STATEMENT:  ALTER TABLE ab_user ADD COLUMN solution_uuid VARCHAR

It complains that the solution_uuid already exists even tho this is a new database and no other migration file adds that column.

This is the migration file with the changes I didn’t make:

# 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.
"""empty message

Revision ID: 346d233b7fc2
Revises: 17fcea065655
Create Date: 2024-07-17 10:58:57.600872

"""

# revision identifiers, used by Alembic.
revision = '346d233b7fc2'
down_revision = '17fcea065655'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('annotation', 'layer_id',
               existing_type=sa.INTEGER(),
               nullable=False)
    op.alter_column('dashboard_roles', 'dashboard_id',
               existing_type=sa.INTEGER(),
               nullable=False)
    op.alter_column('dbs', 'allow_file_upload',
               existing_type=sa.BOOLEAN(),
               nullable=True,
               existing_server_default=sa.text('true'))
    op.create_unique_constraint(None, 'dynamic_plugin', ['bundle_url'])
    op.alter_column('embedded_dashboards', 'uuid',
               existing_type=postgresql.UUID(),
               nullable=False)
    op.create_foreign_key(None, 'embedded_dashboards', 'ab_user', ['changed_by_fk'], ['id'])
    op.create_foreign_key(None, 'embedded_dashboards', 'ab_user', ['created_by_fk'], ['id'])
    op.drop_index('ix_key_value_expires_on', table_name='key_value')
    op.drop_index('ix_key_value_uuid', table_name='key_value')
    op.create_unique_constraint(None, 'key_value', ['uuid'])
    op.drop_index('ix_logs_user_id_dttm', table_name='logs')
    op.alter_column('report_schedule', 'extra_json',
               existing_type=sa.TEXT(),
               nullable=True)
    op.drop_index('ix_creation_method', table_name='report_schedule')
    op.create_unique_constraint(None, 'report_schedule_user', ['user_id', 'report_schedule_id'])
    op.drop_index('ix_row_level_security_filters_filter_type', table_name='row_level_security_filters')
    op.alter_column('sl_columns', 'is_additive',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.alter_column('sl_columns', 'is_aggregation',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.alter_column('sl_columns', 'is_increase_desired',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.alter_column('sl_columns', 'is_partition',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.alter_column('sl_columns', 'is_physical',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.alter_column('sl_columns', 'is_spatial',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.alter_column('sl_columns', 'is_temporal',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.drop_constraint('sl_table_columns_column_id_fkey', 'sl_table_columns', type_='foreignkey')
    op.drop_constraint('sl_table_columns_table_id_fkey', 'sl_table_columns', type_='foreignkey')
    op.create_foreign_key(None, 'sl_table_columns', 'sl_columns', ['column_id'], ['id'], ondelete='CASCADE')
    op.create_foreign_key(None, 'sl_table_columns', 'sl_tables', ['table_id'], ['id'], ondelete='CASCADE')
    op.create_unique_constraint(None, 'sl_tables', ['database_id', 'catalog', 'schema', 'name'])
    op.alter_column('ssh_tunnels', 'database_id',
               existing_type=sa.INTEGER(),
               nullable=False)
    op.drop_index('ix_ssh_tunnels_database_id', table_name='ssh_tunnels')
    op.drop_index('ix_ssh_tunnels_uuid', table_name='ssh_tunnels')
    op.create_unique_constraint(None, 'ssh_tunnels', ['uuid'])
    op.create_unique_constraint(None, 'ssh_tunnels', ['database_id'])
    op.create_foreign_key(None, 'ssh_tunnels', 'ab_user', ['created_by_fk'], ['id'])
    op.create_foreign_key(None, 'ssh_tunnels', 'ab_user', ['changed_by_fk'], ['id'])
    op.alter_column('tab_state', 'autorun',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.alter_column('tab_state', 'hide_left_bar',
               existing_type=sa.BOOLEAN(),
               nullable=True,
               existing_server_default=sa.text('false'))
    op.drop_index('ix_tab_state_id', table_name='tab_state')
    op.drop_index('ix_table_schema_id', table_name='table_schema')
    op.drop_index('ix_tagged_object_object_id', table_name='tagged_object')
    op.create_foreign_key(None, 'tagged_object', 'slices', ['object_id'], ['id'])
    op.create_foreign_key(None, 'tagged_object', 'dashboards', ['object_id'], ['id'])
    op.create_foreign_key(None, 'tagged_object', 'saved_query', ['object_id'], ['id'])
    op.alter_column('user_favorite_tag', 'user_id',
               existing_type=sa.INTEGER(),
               nullable=True)
    op.alter_column('user_favorite_tag', 'tag_id',
               existing_type=sa.INTEGER(),
               nullable=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('user_favorite_tag', 'tag_id',
               existing_type=sa.INTEGER(),
               nullable=False)
    op.alter_column('user_favorite_tag', 'user_id',
               existing_type=sa.INTEGER(),
               nullable=False)
    op.drop_constraint(None, 'tagged_object', type_='foreignkey')
    op.drop_constraint(None, 'tagged_object', type_='foreignkey')
    op.drop_constraint(None, 'tagged_object', type_='foreignkey')
    op.create_index('ix_tagged_object_object_id', 'tagged_object', ['object_id'], unique=False)
    op.create_index('ix_table_schema_id', 'table_schema', ['id'], unique=False)
    op.create_index('ix_tab_state_id', 'tab_state', ['id'], unique=False)
    op.alter_column('tab_state', 'hide_left_bar',
               existing_type=sa.BOOLEAN(),
               nullable=False,
               existing_server_default=sa.text('false'))
    op.alter_column('tab_state', 'autorun',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.drop_constraint(None, 'ssh_tunnels', type_='foreignkey')
    op.drop_constraint(None, 'ssh_tunnels', type_='foreignkey')
    op.drop_constraint(None, 'ssh_tunnels', type_='unique')
    op.drop_constraint(None, 'ssh_tunnels', type_='unique')
    op.create_index('ix_ssh_tunnels_uuid', 'ssh_tunnels', ['uuid'], unique=False)
    op.create_index('ix_ssh_tunnels_database_id', 'ssh_tunnels', ['database_id'], unique=False)
    op.alter_column('ssh_tunnels', 'database_id',
               existing_type=sa.INTEGER(),
               nullable=True)
    op.drop_constraint(None, 'sl_tables', type_='unique')
    op.drop_constraint(None, 'sl_table_columns', type_='foreignkey')
    op.drop_constraint(None, 'sl_table_columns', type_='foreignkey')
    op.create_foreign_key('sl_table_columns_table_id_fkey', 'sl_table_columns', 'sl_tables', ['table_id'], ['id'])
    op.create_foreign_key('sl_table_columns_column_id_fkey', 'sl_table_columns', 'sl_columns', ['column_id'], ['id'])
    op.alter_column('sl_columns', 'is_temporal',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.alter_column('sl_columns', 'is_spatial',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.alter_column('sl_columns', 'is_physical',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.alter_column('sl_columns', 'is_partition',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.alter_column('sl_columns', 'is_increase_desired',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.alter_column('sl_columns', 'is_aggregation',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.alter_column('sl_columns', 'is_additive',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.create_index('ix_row_level_security_filters_filter_type', 'row_level_security_filters', ['filter_type'], unique=False)
    op.drop_constraint(None, 'report_schedule_user', type_='unique')
    op.create_index('ix_creation_method', 'report_schedule', ['creation_method'], unique=False)
    op.alter_column('report_schedule', 'extra_json',
               existing_type=sa.TEXT(),
               nullable=False)
    op.create_index('ix_logs_user_id_dttm', 'logs', ['user_id', 'dttm'], unique=False)
    op.drop_constraint(None, 'key_value', type_='unique')
    op.create_index('ix_key_value_uuid', 'key_value', ['uuid'], unique=False)
    op.create_index('ix_key_value_expires_on', 'key_value', ['expires_on'], unique=False)
    op.drop_constraint(None, 'embedded_dashboards', type_='foreignkey')
    op.drop_constraint(None, 'embedded_dashboards', type_='foreignkey')
    op.alter_column('embedded_dashboards', 'uuid',
               existing_type=postgresql.UUID(),
               nullable=True)
    op.drop_constraint(None, 'dynamic_plugin', type_='unique')
    op.alter_column('dbs', 'allow_file_upload',
               existing_type=sa.BOOLEAN(),
               nullable=False,
               existing_server_default=sa.text('true'))
    op.alter_column('dashboard_roles', 'dashboard_id',
               existing_type=sa.INTEGER(),
               nullable=True)
    op.alter_column('annotation', 'layer_id',
               existing_type=sa.INTEGER(),
               nullable=True)
    # ### end Alembic commands ###

And this is the one with my changes

# 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.
"""add solution_uuid

Revision ID: ddb1e557dd93
Revises: 346d233b7fc2
Create Date: 2024-07-17 11:18:33.257574

"""

# revision identifiers, used by Alembic.
revision = 'ddb1e557dd93'
down_revision = '346d233b7fc2'

from alembic import op
import sqlalchemy as sa


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('ab_user', sa.Column('solution_uuid', sa.String(), nullable=True))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('ab_user', 'solution_uuid')
    # ### end Alembic commands ###

Any idea why this is happening?

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật