From 09305f824875db0cf1f81efbb0ad099b30bb1764 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 27 Nov 2017 11:19:16 -0800 Subject: [PATCH] Add unique constraint to story_tags table This is a mapping table, we should not have duplicate entries Change-Id: I5b4548bdd39b9855919653b701efc5f357233a9f --- .../acca67ec622b_update_story_tag_table.py | 23 +++++++++++++++++++ boartty/db.py | 1 + 2 files changed, 24 insertions(+) create mode 100644 boartty/alembic/versions/acca67ec622b_update_story_tag_table.py diff --git a/boartty/alembic/versions/acca67ec622b_update_story_tag_table.py b/boartty/alembic/versions/acca67ec622b_update_story_tag_table.py new file mode 100644 index 0000000..724f5f3 --- /dev/null +++ b/boartty/alembic/versions/acca67ec622b_update_story_tag_table.py @@ -0,0 +1,23 @@ +"""update story_tag table + +Revision ID: acca67ec622b +Revises: 183755ac91df +Create Date: 2017-11-27 10:49:04.902131 + +""" + +# revision identifiers, used by Alembic. +revision = 'acca67ec622b' +down_revision = '183755ac91df' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.create_index(op.f('story_tag_unique'), 'story_tag', + ['story_key', 'tag_key'], unique=True) + + +def downgrade(): + pass diff --git a/boartty/db.py b/boartty/db.py index ed791e9..e292004 100644 --- a/boartty/db.py +++ b/boartty/db.py @@ -146,6 +146,7 @@ story_tag_table = Table( Column('key', Integer, primary_key=True), Column('story_key', Integer, ForeignKey("story.key"), index=True), Column('tag_key', Integer, ForeignKey("tag.key"), index=True), + UniqueConstraint('story_key', 'tag_key', name='story_tag_unique'), ) task_table = Table( 'task', metadata,