"""Add category and product_category tables

Revision ID: fda01d592a69
Revises: dc9ae69457dc
Create Date: 2020-06-21 00:16:02.117198

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


# revision identifiers, used by Alembic.
revision = 'fda01d592a69'
down_revision = 'dc9ae69457dc'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('category',
    sa.Column('id', salsa.db.types.GUID(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_category'))
    )
    op.create_table('product_category',
    sa.Column('id', salsa.db.types.GUID(), nullable=False),
    sa.Column('product_id', salsa.db.types.GUID(), nullable=False),
    sa.Column('category_id', salsa.db.types.GUID(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['category_id'], ['category.id'], name=op.f('fk_product_category_category_id_category')),
    sa.ForeignKeyConstraint(['product_id'], ['product.id'], name=op.f('fk_product_category_product_id_product')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_product_category')),
    sa.UniqueConstraint('product_id', 'category_id', name='uk_product_to_category')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('product_category')
    op.drop_table('category')
    # ### end Alembic commands ###
