"""Add unique constraint on review table

Revision ID: 33e89c81d574
Revises: 97d675790f2c
Create Date: 2020-05-27 01:36:58.561630

"""
import salsa
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '33e89c81d574'
down_revision = '97d675790f2c'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('review', sa.Column('purchase_id', salsa.db.types.GUID(), nullable=False))
    op.create_unique_constraint('_user_id_product_id_purchase_id_uc', 'review', ['user_id', 'product_id', 'purchase_id'])
    op.create_foreign_key(op.f('fk_review_purchase_id_purchase'), 'review', 'purchase', ['purchase_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(op.f('fk_review_purchase_id_purchase'), 'review', type_='foreignkey')
    op.drop_constraint('_user_id_product_id_purchase_id_uc', 'review', type_='unique')
    op.drop_column('review', 'purchase_id')
    # ### end Alembic commands ###
