Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: drop check constraint on dbs to rename column #17275

Merged

Conversation

betodealmeida
Copy link
Member

SUMMARY

The migration in #16756 is failing in MySQL 8. Renaming the column dbs.allow_csv_upload fails because there's a check constraint on it.

This seems to be a known bug (sqlalchemy/alembic#699), and from that thread dropping the constraint seems safe. The problem is that existing installations already have the constraint, so we can't add create_constraint=False to boolean columns in the model.

This PR fixes the migration by explicitly dropping the check constraint if it exists, and renaming the column after.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

Install Superset using a MySQL 8 database. The superset db upgrade step will fail on the migration b92d69a6643c_rename_csv_to_file.py.

With this PR, the check constraint is dropped and the migration succeeds.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@betodealmeida betodealmeida requested a review from a team as a code owner October 29, 2021 00:12
@betodealmeida betodealmeida changed the title Drop constraint fix: drop check constraint on dbs to rename column Oct 29, 2021
@codecov
Copy link

codecov bot commented Oct 29, 2021

Codecov Report

Merging #17275 (3d66523) into master (37909aa) will decrease coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17275      +/-   ##
==========================================
- Coverage   77.02%   77.02%   -0.01%     
==========================================
  Files        1037     1037              
  Lines       55629    55629              
  Branches     7594     7594              
==========================================
- Hits        42850    42848       -2     
- Misses      12529    12531       +2     
  Partials      250      250              
Flag Coverage Δ
hive 81.52% <ø> (ø)
mysql 81.95% <ø> (ø)
postgres 81.96% <ø> (ø)
presto 81.82% <ø> (-0.01%) ⬇️
python 82.45% <ø> (-0.01%) ⬇️
sqlite 81.63% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/db_engine_specs/presto.py 89.95% <0.00%> (-0.42%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37909aa...3d66523. Read the comment docs.

Copy link
Contributor

@exemplary-citizen exemplary-citizen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we can change the original db migration to not create a constraint in revision 1d9e835a84f9

# 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: 1d9e835a84f9
Revises: 3dda56f1c4c6
Create Date: 2018-07-16 18:04:07.764659

"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.sql import expression

# revision identifiers, used by Alembic.
revision = "1d9e835a84f9"
down_revision = "3dda56f1c4c6"


def upgrade():
    op.add_column(
        "dbs",
        sa.Column(
            "allow_csv_upload",
            sa.Boolean(create_constraint=False),
            nullable=False,
            server_default=expression.true(),
        ),
    )


def downgrade():
    op.drop_column("dbs", "allow_csv_upload")

@betodealmeida
Copy link
Member Author

Alternatively, we can change the original db migration to not create a constraint in revision 1d9e835a84f9

Unfortunately that would work only for fresh installs. Everyone already using Superset has the constraint set in their databases, and if they're running it under MySQL 8 the only way to upgrade their DB with your migration is to drop the constraint.

@betodealmeida betodealmeida merged commit 8ee50de into apache:master Oct 29, 2021
@eschutho eschutho added v1.4 and removed v1.4 labels Nov 22, 2021
AAfghahi pushed a commit that referenced this pull request Jan 10, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants