From 01c2c7baf88d3876d2f73ccf802376648797d060 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Fri, 15 Apr 2016 14:53:06 -0700 Subject: [PATCH] Fixing unique constraint in SqlaTable model (#360) --- ...6560d4f3_change_table_unique_constraint.py | 25 +++++++++++++++++++ caravel/models.py | 7 +++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 caravel/migrations/versions/b4456560d4f3_change_table_unique_constraint.py diff --git a/caravel/migrations/versions/b4456560d4f3_change_table_unique_constraint.py b/caravel/migrations/versions/b4456560d4f3_change_table_unique_constraint.py new file mode 100644 index 0000000000000..0b8164d0c1614 --- /dev/null +++ b/caravel/migrations/versions/b4456560d4f3_change_table_unique_constraint.py @@ -0,0 +1,25 @@ +"""change_table_unique_constraint + +Revision ID: b4456560d4f3 +Revises: bb51420eaf83 +Create Date: 2016-04-15 08:31:26.249591 + +""" + +# revision identifiers, used by Alembic. +revision = 'b4456560d4f3' +down_revision = 'bb51420eaf83' + +from alembic import op + + +def upgrade(): + op.drop_constraint( + u'tables_table_name_key', 'tables', type_='unique') + op.create_unique_constraint( + u'_customer_location_uc', 'tables', + ['database_id', 'schema', 'table_name']) + + +def downgrade(): + op.drop_constraint(u'_customer_location_uc', 'tables', type_='unique') diff --git a/caravel/models.py b/caravel/models.py index 0fce58e6e0b7b..57500b9c35ab4 100644 --- a/caravel/models.py +++ b/caravel/models.py @@ -406,7 +406,7 @@ class SqlaTable(Model, Queryable, AuditMixinNullable): __tablename__ = 'tables' id = Column(Integer, primary_key=True) - table_name = Column(String(250), unique=True) + table_name = Column(String(250)) main_dttm_col = Column(String(250)) description = Column(Text) default_endpoint = Column(Text) @@ -422,6 +422,11 @@ class SqlaTable(Model, Queryable, AuditMixinNullable): baselink = "tablemodelview" + __table_args__ = ( + sqla.UniqueConstraint( + 'database_id', 'schema', 'table_name', + name='_customer_location_uc'),) + def __repr__(self): return self.table_name