Skip to content

Commit

Permalink
fix: old unique constraint remnance
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed May 22, 2020
1 parent ee99196 commit 5f51fc5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 5 additions & 1 deletion superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ class SqlaTable(Model, BaseDatasource):
owner_class = security_manager.user_model

__tablename__ = "tables"
__table_args__ = (UniqueConstraint("database_id", "table_name"),)
__table_args__ = (
UniqueConstraint(
"database_id", "schema", "table_name", name="_customer_location_uc",
),
)

table_name = Column(String(250), nullable=False)
main_dttm_col = Column(String(250))
Expand Down
4 changes: 3 additions & 1 deletion superset/migrations/versions/4e6a06bad7a8_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def upgrade():
"changed_by_fk", sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("table_name"),
# Commenting out spring 2020 to avoid flimsy delete in
# subsequent migration b4456560d4f3_change_table_unique_constraint.py
# sa.UniqueConstraint("table_name"),
)
op.create_table(
"columns",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@

def upgrade():
try:
# Trying since sqlite doesn't like constraints
# Trying to drop the constraint if it exists
op.drop_constraint("tables_table_name_key", "tables", type_="unique")
op.create_unique_constraint(
"_customer_location_uc", "tables", ["database_id", "schema", "table_name"]
)
except Exception:
pass
op.create_unique_constraint(
"_customer_location_uc", "tables", ["database_id", "schema", "table_name"]
)


def downgrade():
try:
# Trying since sqlite doesn't like constraints
op.drop_constraint(u"_customer_location_uc", "tables", type_="unique")
except Exception:
pass
op.drop_constraint(u"_customer_location_uc", "tables", type_="unique")

0 comments on commit 5f51fc5

Please sign in to comment.