Add a table mapping Teams to Projects
Change-Id: I4821d4d204a35abab6b43e1037424bdc5c9606a1
This commit is contained in:
parent
81e7f115bb
commit
e7fe27fa22
@ -0,0 +1,51 @@
|
|||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""Associate multiple projects with teams
|
||||||
|
|
||||||
|
Revision ID: 065
|
||||||
|
Revises: 064
|
||||||
|
Create Date: 2019-03-07 11:25:31.308033
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '065'
|
||||||
|
down_revision = '064'
|
||||||
|
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade(active_plugins=None, options=None):
|
||||||
|
op.create_table('project_teams',
|
||||||
|
sa.Column('project_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('team_id', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], )
|
||||||
|
)
|
||||||
|
dialect = op.get_bind().engine.dialect
|
||||||
|
if dialect.supports_alter:
|
||||||
|
op.drop_constraint('projects_ibfk_1', 'projects', type_='foreignkey')
|
||||||
|
op.drop_column('projects', 'team_id')
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade(active_plugins=None, options=None):
|
||||||
|
dialect = op.get_bind().engine.dialect
|
||||||
|
if dialect.supports_alter:
|
||||||
|
op.add_column('projects', sa.Column(
|
||||||
|
'team_id', sa.Integer(), autoincrement=False, nullable=True))
|
||||||
|
op.create_foreign_key(
|
||||||
|
'projects_ibfk_1', 'projects', 'teams', ['team_id'], ['id'])
|
||||||
|
op.drop_table('project_teams')
|
@ -217,6 +217,13 @@ class Team(ModelBuilder, Base):
|
|||||||
backref="teams")
|
backref="teams")
|
||||||
|
|
||||||
|
|
||||||
|
project_teams = Table(
|
||||||
|
'project_teams', Base.metadata,
|
||||||
|
Column('project_id', Integer, ForeignKey('projects.id'), nullable=False),
|
||||||
|
Column('team_id', Integer, ForeignKey('teams.id'), nullable=False)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
project_group_mapping = Table(
|
project_group_mapping = Table(
|
||||||
'project_group_mapping', Base.metadata,
|
'project_group_mapping', Base.metadata,
|
||||||
Column('project_id', Integer, ForeignKey('projects.id')),
|
Column('project_id', Integer, ForeignKey('projects.id')),
|
||||||
@ -267,8 +274,7 @@ class Project(FullText, ModelBuilder, Base):
|
|||||||
|
|
||||||
name = Column(String(CommonLength.top_middle_length))
|
name = Column(String(CommonLength.top_middle_length))
|
||||||
description = Column(UnicodeText())
|
description = Column(UnicodeText())
|
||||||
team_id = Column(Integer, ForeignKey('teams.id'))
|
teams = relationship(Team, secondary="project_teams", backref="projects")
|
||||||
team = relationship(Team, primaryjoin=team_id == Team.id)
|
|
||||||
tasks = relationship('Task', backref='project')
|
tasks = relationship('Task', backref='project')
|
||||||
branches = relationship('Branch', backref='project')
|
branches = relationship('Branch', backref='project')
|
||||||
repo_url = Column(String(CommonLength.top_large_length), default=None)
|
repo_url = Column(String(CommonLength.top_large_length), default=None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user