Merge "Assocate StoryTag with Story via mapping"

This commit is contained in:
Jenkins 2014-08-14 19:50:23 +00:00 committed by Gerrit Code Review
commit ec7cdbf5b7
2 changed files with 66 additions and 2 deletions

View File

@ -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 ###

View File

@ -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'
@ -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"]
@ -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