Add a migration script for the new table and log entry kinds

This commit is contained in:
Joseph Schorr 2014-08-18 20:45:48 -04:00
parent 43b6695f9c
commit d5027d2383

View file

@ -0,0 +1,72 @@
"""Add support for team member invites
Revision ID: 25aea439ad0e
Revises: 82297d834ad
Create Date: 2014-08-18 20:40:38.553951
"""
# revision identifiers, used by Alembic.
revision = '25aea439ad0e'
down_revision = '82297d834ad'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('teammemberinvite',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('email', sa.String(length=255), nullable=True),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('inviter_id', sa.Integer(), nullable=False),
sa.Column('invite_token', sa.String(length=255), nullable=False),
sa.ForeignKeyConstraint(['inviter_id'], ['user.id'], ),
sa.ForeignKeyConstraint(['team_id'], ['team.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index('teammemberinvite_inviter_id', 'teammemberinvite', ['inviter_id'], unique=False)
op.create_index('teammemberinvite_team_id', 'teammemberinvite', ['team_id'], unique=False)
op.create_index('teammemberinvite_user_id', 'teammemberinvite', ['user_id'], unique=False)
### end Alembic commands ###
schema = gen_sqlalchemy_metadata(all_models)
# Manually add the new logentrykind types
op.bulk_insert(schema.tables['logentrykind'],
[
{'id':41, 'name':'org_invite_team_member'},
{'id':42, 'name':'org_team_member_invite_accepted'},
{'id':43, 'name':'org_team_member_invite_declined'},
])
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_index('teammemberinvite_user_id', table_name='teammemberinvite')
op.drop_index('teammemberinvite_team_id', table_name='teammemberinvite')
op.drop_index('teammemberinvite_inviter_id', table_name='teammemberinvite')
op.drop_table('teammemberinvite')
### end Alembic commands ###
schema = gen_sqlalchemy_metadata(all_models)
logentrykind = schema.tables['logentrykind']
op.execute(
(logentrykind.delete()
.where(logentrykind.c.name == op.inline_literal('org_invite_team_member')))
)
op.execute(
(logentrykind.delete()
.where(logentrykind.c.name == op.inline_literal('org_team_member_invite_accepted')))
)
op.execute(
(logentrykind.delete()
.where(logentrykind.c.name == op.inline_literal('org_team_member_invite_declined')))
)