Remove Branch and Milestone legacy tables

Remove the Branch and Milestone legacy tables from the POC. Those will
very likely be implemented in a very different way now.

While it is unused yet, I kept the StoryTag table around, since its
implementation is likely to be quite similar.

In order to delete the milestone_id foreign key in the tasks table, we
need the name of the constraint. So I retroactively named all foreign
keys in table 'tasks' under the autogenerated name for MySQL databases.

Change-Id: Id3e8e12b19046aed243b8f073fe18a98c03011e6
This commit is contained in:
Thierry Carrez 2014-03-19 16:10:05 +01:00
parent 58a7063366
commit 2bcbdd4c7f
3 changed files with 100 additions and 32 deletions

View File

@ -217,10 +217,14 @@ def upgrade(active_plugins=None, options=None):
sa.Column('project_id', sa.Integer(), nullable=True),
sa.Column('assignee_id', sa.Integer(), nullable=True),
sa.Column('milestone_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['assignee_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['milestone_id'], ['milestones.id'], ),
sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ),
sa.ForeignKeyConstraint(['story_id'], ['stories.id'], ),
sa.ForeignKeyConstraint(['assignee_id'], ['users.id'],
name='tasks_ibfk_1'),
sa.ForeignKeyConstraint(['milestone_id'], ['milestones.id'],
name='tasks_ibfk_2'),
sa.ForeignKeyConstraint(['project_id'], ['projects.id'],
name='tasks_ibfk_3'),
sa.ForeignKeyConstraint(['story_id'], ['stories.id'],
name='tasks_ibfk_4'),
sa.PrimaryKeyConstraint('id'),
mysql_engine=MYSQL_ENGINE,
mysql_charset=MYSQL_CHARSET

View File

@ -0,0 +1,92 @@
# 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.
#
"""Remove Branch, Milestone tables
Revision ID: 008
Revises: 007
Create Date: 2014-03-19 15:00:39.149963
"""
# revision identifiers, used by Alembic.
revision = '008'
down_revision = '007'
from alembic import op
import sqlalchemy as sa
MYSQL_ENGINE = 'InnoDB'
MYSQL_CHARSET = 'utf8'
def _define_enums():
branch_status = sa.Enum(
'master', 'release', 'stable', 'unsupported',
name='branch_status')
return {
'branch_status': branch_status
}
def upgrade(active_plugins=None, options=None):
op.drop_constraint('tasks_ibfk_2',
'tasks', type_='foreignkey')
op.drop_column('tasks', 'milestone_id')
op.drop_table('milestones')
op.drop_table('branches')
# Need to explicitly delete enums during migrations for Postgres
enums = _define_enums()
for enum in enums.values():
enum.drop(op.get_bind())
def downgrade(active_plugins=None, options=None):
enums = _define_enums()
op.create_table(
'branches',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('name', sa.String(length=50), nullable=True),
sa.Column('status', enums['branch_status'], nullable=True),
sa.Column('release_date', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uniq_branch_name'),
mysql_engine=MYSQL_ENGINE,
mysql_charset=MYSQL_CHARSET
)
op.create_table(
'milestones',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('name', sa.String(length=50), nullable=True),
sa.Column('branch_id', sa.Integer(), nullable=True),
sa.Column('released', sa.Boolean(), nullable=True),
sa.Column('undefined', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['branch_id'], ['branches.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uniq_milestone_name'),
mysql_engine=MYSQL_ENGINE,
mysql_charset=MYSQL_CHARSET
)
op.add_column('tasks', sa.Column('milestone_id',
sa.Integer(),
nullable=True))
op.create_foreign_key('tasks_ibfk_2', 'tasks',
'milestones', ['milestone_id'], ['id'])

View File

@ -162,33 +162,6 @@ class ProjectGroup(Base):
projects = relationship("Project", secondary="project_group_mapping")
class Branch(Base):
# TODO(mordred): order_by release date?
_BRANCH_STATUS = ('master', 'release', 'stable', 'unsupported')
__tablename__ = 'branches'
__table_args__ = (
schema.UniqueConstraint('name', name='uniq_branch_name'),
)
id = Column(Integer, primary_key=True)
name = Column(String(50))
status = Column(Enum(*_BRANCH_STATUS, name='branch_status'))
release_date = Column(DateTime, nullable=True)
class Milestone(Base):
__table_args__ = (
schema.UniqueConstraint('name', name='uniq_milestone_name'),
)
name = Column(String(50))
branch_id = Column(Integer, ForeignKey('branches.id'))
branch = relationship(Branch, primaryjoin=branch_id == Branch.id)
released = Column(Boolean, default=False)
undefined = Column(Boolean, default=False)
tasks = relationship('Task', backref='milestone')
class Story(Base):
__tablename__ = 'stories'
_STORY_PRIORITIES = ('Undefined', 'Low', 'Medium', 'High', 'Critical')
@ -216,7 +189,6 @@ class Task(Base):
story_id = Column(Integer, ForeignKey('stories.id'))
project_id = Column(Integer, ForeignKey('projects.id'))
assignee_id = Column(Integer, ForeignKey('users.id'), nullable=True)
milestone_id = Column(Integer, ForeignKey('milestones.id'), nullable=True)
is_active = Column(Boolean, default=True)
_public_fields = ["id", "title", "status", "story_id", "project_id",