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

Silence error on migration 4736ec66ce19 constraint drop #5729

Merged
merged 2 commits into from
Aug 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions superset/migrations/versions/4736ec66ce19_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

"""

# revision identifiers, used by Alembic.
revision = '4736ec66ce19'
down_revision = 'f959a6652acd'
import logging

from alembic import op
import sqlalchemy as sa
from sqlalchemy.exc import OperationalError

from superset.utils import (
generic_find_fk_constraint_name,
generic_find_fk_constraint_names,
generic_find_uq_constraint_name,
)

# revision identifiers, used by Alembic.
revision = '4736ec66ce19'
down_revision = 'f959a6652acd'

conv = {
'fk': 'fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s',
Expand Down Expand Up @@ -101,16 +101,24 @@ def upgrade():

batch_op.drop_column('datasource_name')

# Drop the old more restrictive uniqueness constraint.
with op.batch_alter_table('datasources', naming_convention=conv) as batch_op:
batch_op.drop_constraint(
generic_find_uq_constraint_name(
'datasources',
{'datasource_name'},
insp,
) or 'uq_datasources_datasource_name',
type_='unique',
)
try:
# Drop the old more restrictive uniqueness constraint.
with op.batch_alter_table('datasources', naming_convention=conv) as batch_op:
batch_op.drop_constraint(
generic_find_uq_constraint_name(
'datasources',
{'datasource_name'},
insp,
) or 'uq_datasources_datasource_name',
type_='unique',
)
except Exception as e:
logging.warning(
'Constraint drop failed, you may want to do this '
'manually on your database. For context, this is a known '
'issue around undeterministic contraint names on Postgres '
'and perhaps more databases through SQLAlchemy.')
logging.exception(e)


def downgrade():
Expand Down