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

Fixing unique constraint in SqlaTable model #360

Merged
merged 1 commit into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -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')
7 changes: 6 additions & 1 deletion caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down