"""Initialize Database

Revision ID: ac49b2a193ff
Revises: 
Create Date: 2020-08-23 15:26:11.891606

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "ac49b2a193ff"
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "category",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=50), nullable=False),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("sequence", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("sequence"),
    )
    op.create_index(op.f("ix_category_id"), "category", ["id"], unique=False)
    op.create_index(op.f("ix_category_name"), "category", ["name"], unique=True)
    op.create_table(
        "customer",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("salutation", sa.String(length=50), nullable=True),
        sa.Column("firstname", sa.String(length=50), nullable=False),
        sa.Column("lastname", sa.String(length=50), nullable=False),
        sa.Column("streetname", sa.String(length=100), nullable=False),
        sa.Column("address_additive", sa.String(length=50), nullable=True),
        sa.Column("zipcode", sa.String(length=4), nullable=True),
        sa.Column("city", sa.String(length=100), nullable=True),
        sa.Column("email", sa.String(length=255), nullable=True),
        sa.Column("phone", sa.String(length=14), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("email"),
    )
    op.create_index(op.f("ix_customer_id"), "customer", ["id"], unique=False)
    op.create_table(
        "payment",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=50), nullable=False),
        sa.Column("description", sa.String(length=1024), nullable=True),
        sa.Column("additional_costs", sa.Float(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_index(op.f("ix_payment_id"), "payment", ["id"], unique=False)
    op.create_table(
        "property",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_index(op.f("ix_property_id"), "property", ["id"], unique=False)
    op.create_table(
        "shipment",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("description", sa.String(length=1024), nullable=True),
        sa.Column("additional_costs", sa.Float(), nullable=True),
        sa.Column("days_to_deliver", sa.Integer(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_index(op.f("ix_shipment_id"), "shipment", ["id"], unique=False)
    op.create_table(
        "order",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("distribution_number", sa.String(length=50), nullable=True),
        sa.Column("state", sa.String(length=100), nullable=True),
        sa.Column("status", sa.String(length=100), nullable=True),
        sa.Column("total_price", sa.Float(), nullable=False),
        sa.Column("pay_date", sa.Date(), nullable=True),
        sa.Column("delivery_date", sa.Date(), nullable=True),
        sa.Column("reminder_date", sa.Date(), nullable=True),
        sa.Column("notes", sa.String(length=2048), nullable=True),
        sa.Column("pf_payment_method", sa.String(length=255), nullable=True),
        sa.Column("pf_acceptance", sa.String(length=255), nullable=True),
        sa.Column("pf_status", sa.String(length=255), nullable=True),
        sa.Column("pf_payid", sa.Text(), nullable=True),
        sa.Column("pf_brand", sa.String(length=255), nullable=True),
        sa.Column("ip_address", sa.String(length=15), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.Column("payment_id", sa.Integer(), nullable=True),
        sa.Column("shipment_id", sa.Integer(), nullable=True),
        sa.Column("customer_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["customer_id"], ["customer.id"],),
        sa.ForeignKeyConstraint(["payment_id"], ["payment.id"],),
        sa.ForeignKeyConstraint(["shipment_id"], ["shipment.id"],),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_order_id"), "order", ["id"], unique=False)
    op.create_table(
        "product",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("description", sa.Text(), nullable=False),
        sa.Column("number", sa.Integer(), nullable=False),
        sa.Column("price", sa.Float(), nullable=True),
        sa.Column("active_until", sa.Date(), nullable=True),
        sa.Column("active_from", sa.Date(), nullable=True),
        sa.Column("sale_price", sa.Float(), nullable=True),
        sa.Column("sale_from", sa.Date(), nullable=True),
        sa.Column("sale_until", sa.Date(), nullable=True),
        sa.Column("num_in_stock", sa.Integer(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.Column("category_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["category_id"], ["category.id"],),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("number"),
    )
    op.create_index(op.f("ix_product_id"), "product", ["id"], unique=False)
    op.create_index(op.f("ix_product_name"), "product", ["name"], unique=True)
    op.create_table(
        "propertyitem",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("item_order", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.Column("property_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["property_id"], ["property.id"],),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_propertyitem_id"), "propertyitem", ["id"], unique=False)
    op.create_table(
        "user",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("login_name", sa.String(length=100), nullable=False),
        sa.Column("hashed_password", sa.String(length=255), nullable=False),
        sa.Column("remember_token", sa.Integer(), nullable=True),
        sa.Column("is_admin", sa.Integer(), nullable=True),
        sa.Column("state", sa.String(length=50), nullable=True),
        sa.Column("password_reset_token", sa.String(length=255), nullable=True),
        sa.Column("password_reset_token_sent_at", sa.DateTime(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.Column("customer_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["customer_id"], ["customer.id"],),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("login_name"),
    )
    op.create_index(op.f("ix_user_id"), "user", ["id"], unique=False)
    op.create_table(
        "lineitem",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("quantity", sa.Integer(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.Column("product_id", sa.Integer(), nullable=False),
        sa.Column("order_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["order_id"], ["order.id"],),
        sa.ForeignKeyConstraint(["product_id"], ["product.id"],),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_lineitem_id"), "lineitem", ["id"], unique=False)
    op.create_table(
        "productproperty",
        sa.Column("product_id", sa.Integer(), nullable=False),
        sa.Column("property_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["product_id"], ["product.id"],),
        sa.ForeignKeyConstraint(["property_id"], ["property.id"],),
        sa.PrimaryKeyConstraint("product_id", "property_id"),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("productproperty")
    op.drop_index(op.f("ix_lineitem_id"), table_name="lineitem")
    op.drop_table("lineitem")
    op.drop_index(op.f("ix_user_id"), table_name="user")
    op.drop_table("user")
    op.drop_index(op.f("ix_propertyitem_id"), table_name="propertyitem")
    op.drop_table("propertyitem")
    op.drop_index(op.f("ix_product_name"), table_name="product")
    op.drop_index(op.f("ix_product_id"), table_name="product")
    op.drop_table("product")
    op.drop_index(op.f("ix_order_id"), table_name="order")
    op.drop_table("order")
    op.drop_index(op.f("ix_shipment_id"), table_name="shipment")
    op.drop_table("shipment")
    op.drop_index(op.f("ix_property_id"), table_name="property")
    op.drop_table("property")
    op.drop_index(op.f("ix_payment_id"), table_name="payment")
    op.drop_table("payment")
    op.drop_index(op.f("ix_customer_id"), table_name="customer")
    op.drop_table("customer")
    op.drop_index(op.f("ix_category_name"), table_name="category")
    op.drop_index(op.f("ix_category_id"), table_name="category")
    op.drop_table("category")
    # ### end Alembic commands ###
