From 3a359b0577f4bf33992c3de2d54e8546bd3d216f Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 30 Sep 2020 12:12:43 +0100 Subject: [PATCH 1/4] fix: alembic migration fails by deleting non existent constraint on tables --- ...98_fix_table_unique_constraint_in_mysql.py | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py diff --git a/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py b/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py deleted file mode 100644 index f4c5af19dc942..0000000000000 --- a/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py +++ /dev/null @@ -1,42 +0,0 @@ -# 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. -"""Delete table_name unique constraint in mysql - -Revision ID: 18532d70ab98 -Revises: 3fbbc6e8d654 -Create Date: 2020-09-25 10:56:13.711182 - -""" - -# revision identifiers, used by Alembic. -revision = "18532d70ab98" -down_revision = "3fbbc6e8d654" - -from alembic import op - - -def upgrade(): - try: - # index only exists in mysql db - with op.get_context().autocommit_block(): - op.drop_constraint("table_name", "tables", type_="unique") - except Exception as ex: - print(ex) - - -def downgrade(): - pass From 4219f83ccbf8ce21fe00871abb3f1a41f6c3b647 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 30 Sep 2020 15:33:57 +0100 Subject: [PATCH 2/4] Revert "fix: alembic migration fails by deleting non existent constraint on tables" This reverts commit 3a359b0577f4bf33992c3de2d54e8546bd3d216f. --- ...98_fix_table_unique_constraint_in_mysql.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py diff --git a/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py b/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py new file mode 100644 index 0000000000000..f4c5af19dc942 --- /dev/null +++ b/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py @@ -0,0 +1,42 @@ +# 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. +"""Delete table_name unique constraint in mysql + +Revision ID: 18532d70ab98 +Revises: 3fbbc6e8d654 +Create Date: 2020-09-25 10:56:13.711182 + +""" + +# revision identifiers, used by Alembic. +revision = "18532d70ab98" +down_revision = "3fbbc6e8d654" + +from alembic import op + + +def upgrade(): + try: + # index only exists in mysql db + with op.get_context().autocommit_block(): + op.drop_constraint("table_name", "tables", type_="unique") + except Exception as ex: + print(ex) + + +def downgrade(): + pass From ef93f987c7d290efe01cf5fa2da9e20096223335 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 30 Sep 2020 15:45:46 +0100 Subject: [PATCH 3/4] mantain migration but just for MySQL and add downgrade procedure --- ...32d70ab98_fix_table_unique_constraint_in_mysql.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py b/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py index f4c5af19dc942..ad04ee590fb3e 100644 --- a/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py +++ b/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py @@ -27,16 +27,20 @@ down_revision = "3fbbc6e8d654" from alembic import op +from sqlalchemy.dialects.mysql.base import MySQLDialect def upgrade(): - try: + bind = op.get_bind() + if isinstance(bind.dialect, MySQLDialect): # index only exists in mysql db with op.get_context().autocommit_block(): op.drop_constraint("table_name", "tables", type_="unique") - except Exception as ex: - print(ex) def downgrade(): - pass + bind = op.get_bind() + if isinstance(bind.dialect, MySQLDialect): + # index only exists in mysql db + with op.get_context().autocommit_block(): + op.add_constraint("table_name", "tables", type_="unique") From 35c93bc6e302ce993648bbe492bbb7c8725d5e48 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Thu, 1 Oct 2020 11:59:09 +0100 Subject: [PATCH 4/4] skip the downgrade --- .../18532d70ab98_fix_table_unique_constraint_in_mysql.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py b/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py index ad04ee590fb3e..c011c06eec65c 100644 --- a/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py +++ b/superset/migrations/versions/18532d70ab98_fix_table_unique_constraint_in_mysql.py @@ -39,8 +39,4 @@ def upgrade(): def downgrade(): - bind = op.get_bind() - if isinstance(bind.dialect, MySQLDialect): - # index only exists in mysql db - with op.get_context().autocommit_block(): - op.add_constraint("table_name", "tables", type_="unique") + pass