"""Add favourite proposal table

Revision ID: fb6c96630733
Revises: ad8f368b172a
Create Date: 2016-07-20 22:33:53.989491

"""

# revision identifiers, used by Alembic.
revision = 'fb6c96630733'
down_revision = 'ad8f368b172a'

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('favourite_proposals_version',
    sa.Column('user_id', sa.Integer(), autoincrement=False, nullable=True),
    sa.Column('proposal_id', sa.Integer(), autoincrement=False, nullable=True),
    sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('operation_type', sa.SmallInteger(), nullable=False),
    sa.PrimaryKeyConstraint('transaction_id', name=op.f('pk_favourite_proposals_version'))
    )
    with op.batch_alter_table('favourite_proposals_version', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_favourite_proposals_version_operation_type'), ['operation_type'], unique=False)
        batch_op.create_index(batch_op.f('ix_favourite_proposals_version_transaction_id'), ['transaction_id'], unique=False)

    op.create_table('favourite_proposals',
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('proposal_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['proposal_id'], ['proposal.id'], name=op.f('fk_favourite_proposals_proposal_id_proposal')),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_favourite_proposals_user_id_user'))
    )
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('favourite_proposals')
    with op.batch_alter_table('favourite_proposals_version', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_favourite_proposals_version_transaction_id'))
        batch_op.drop_index(batch_op.f('ix_favourite_proposals_version_operation_type'))

    op.drop_table('favourite_proposals_version')
    ### end Alembic commands ###
