Skip to content
This repository has been archived by the owner on Aug 1, 2019. It is now read-only.

Commit

Permalink
Assocate StoryTag with Story via mapping
Browse files Browse the repository at this point in the history
A story can have more than one tag. A tag can be on more than one story.

Change-Id: I74c21ab3dcd2fb793df962ed7b425331e199886d
  • Loading branch information
emonty authored and Konovalov-Nik committed Aug 13, 2014
1 parent a496a3c commit cd7897d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
@@ -0,0 +1,56 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#

"""Add story and tag mapping table.
Revision ID: 023
Revises: 022
Create Date: 2014-08-13 13:47:29.795996
"""

# revision identifiers, used by Alembic.
revision = '023'
down_revision = '022'


from alembic import op
import sqlalchemy as sa

MYSQL_ENGINE = 'InnoDB'
MYSQL_CHARSET = 'utf8'


def upgrade(active_plugins=None, options=None):

### commands auto generated by Alembic - please adjust! ###
op.create_table('story_storytags',
sa.Column('story_id', sa.Integer(), nullable=True),
sa.Column('storytag_id', sa.Integer(), nullable=True),
mysql_engine=MYSQL_ENGINE,
mysql_charset=MYSQL_CHARSET
)
op.drop_constraint('storytags_ibfk_1', 'storytags', type_='foreignkey')
op.drop_column(u'storytags', u'story_id')
### end Alembic commands ###


def downgrade(active_plugins=None, options=None):

### commands auto generated by Alembic - please adjust! ###
op.add_column(u'storytags',
sa.Column('story_id', sa.Integer(), nullable=True))
op.create_foreign_key('storytags_ibfk_1', 'storytags',
'stories', ['story_id'], ['id'])
op.drop_table('story_storytags')
### end Alembic commands ###
12 changes: 10 additions & 2 deletions storyboard/db/models.py
Expand Up @@ -170,6 +170,13 @@ class ProjectGroup(Base):
_public_fields = ["id", "name", "title", "projects"]


story_storytags = Table(
'story_storytags', Base.metadata,
Column('story_id', Integer, ForeignKey('stories.id')),
Column('storytag_id', Integer, ForeignKey('storytags.id')),
)


class Story(FullText, Base):
__tablename__ = 'stories'

Expand All @@ -182,7 +189,7 @@ class Story(FullText, Base):
is_bug = Column(Boolean, default=True)
tasks = relationship('Task', backref='story')
events = relationship('TimeLineEvent', backref='story')
tags = relationship('StoryTag', backref='story')
tags = relationship('StoryTag', secondary='story_storytags')

_public_fields = ["id", "creator_id", "title", "description", "is_bug",
"tasks", "events", "tags"]
Expand All @@ -207,11 +214,12 @@ class Task(FullText, Base):


class StoryTag(Base):
__tablename__ = 'storytags'
__table_args__ = (
schema.UniqueConstraint('name', name='uniq_story_tags_name'),
)
name = Column(String(20))
story_id = Column(Integer, ForeignKey('stories.id'))
stories = relationship('StoryTag', secondary='story_storytags')


# Authorization models
Expand Down

0 comments on commit cd7897d

Please sign in to comment.