"""adds_teams_and_members_table

Revision ID: 4e067f29994d
Revises: 67e4f755b1c6
Create Date: 2017-09-29 18:23:18.494917

"""

# revision identifiers, used by Alembic.
revision = '4e067f29994d'
down_revision = '67e4f755b1c6'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from sqlalchemy.schema import Sequence, CreateSequence


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('teams',
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('name', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.execute(CreateSequence(Sequence('team_id_seq')))
    op.create_index(op.f('ix_team_name'), 'teams', ['name'], unique=False)

    op.create_table('team_members',
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('user_id', sa.BigInteger(), nullable=False),
    sa.Column('team_id', sa.BigInteger(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'],),
    sa.ForeignKeyConstraint(['team_id'], ['teams.id'],),
    sa.PrimaryKeyConstraint('id')
    )
    op.execute(CreateSequence(Sequence('team_member_id_seq')))
    op.create_index(op.f('ix_team_member_user_id'), 'team_members', ['user_id'], unique=False)
    op.create_index(op.f('ix_team_member_team_id'), 'team_members', ['team_id'], unique=False)
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_team_member_user_id'), table_name='team_members')
    op.drop_index(op.f('ix_team_member_team_id'), table_name='team_members')
    op.drop_table('team_members')
    op.drop_index(op.f('ix_team_name'), table_name='teams')
    op.drop_table('teams')
    ### end Alembic commands ###
