<reponame>doanguyen/digeiz_boilerplate
"""init

Revision ID: ab31c76462ed
Revises: 
Create Date: 2021-01-19 15:37:11.633887

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "account",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column(
            "created_at",
            sa.DateTime(),
            nullable=False,
            comment="Automatic store the creation time of the object",
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(),
            nullable=True,
            comment="Automatic store the update time of the object",
        ),
        sa.Column(
            "username", sa.String(length=50), nullable=True, comment="Unique username"
        ),
        sa.Column("email", sa.String(), nullable=True, comment="User unique email"),
        sa.Column("phone", sa.String(), nullable=True, comment="User telephone number"),
        sa.Column("name", sa.String(), nullable=True, comment="User full name"),
        sa.Column("dob", sa.Date(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_account_email"), "account", ["email"], unique=True)
    op.create_index(op.f("ix_account_username"), "account", ["username"], unique=True)
    op.create_table(
        "mall",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column(
            "created_at",
            sa.DateTime(),
            nullable=False,
            comment="Automatic store the creation time of the object",
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(),
            nullable=True,
            comment="Automatic store the update time of the object",
        ),
        sa.Column("name", sa.String(length=128), nullable=False),
        sa.Column(
            "location",
            sa.String(),
            nullable=True,
            comment="The mall location in detail",
        ),
        sa.Column(
            "province",
            sa.String(),
            nullable=True,
            comment="The mall province. I.e: Isere",
        ),
        sa.Column(
            "city", sa.String(), nullable=True, comment="The mall city. I.e: Grenoble"
        ),
        sa.Column(
            "country",
            sa.String(),
            nullable=True,
            comment="The mall's country. Should match the country_code. I.e: France",
        ),
        sa.Column(
            "country_code",
            sa.String(),
            nullable=True,
            comment="The two-letter country code corresponds to the country. I.e: FR",
        ),
        sa.Column(
            "latitude",
            sa.Float(),
            nullable=True,
            comment="The latitude of the mall's location. I.e: 42.12",
        ),
        sa.Column(
            "longitude",
            sa.Float(),
            nullable=True,
            comment="The longitude of the mall's location. I.e: -22.43",
        ),
        sa.Column("account_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["account_id"], ["account.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_mall_name"), "mall", ["name"], unique=True)
    op.create_table(
        "unit",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column(
            "created_at",
            sa.DateTime(),
            nullable=False,
            comment="Automatic store the creation time of the object",
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(),
            nullable=True,
            comment="Automatic store the update time of the object",
        ),
        sa.Column("name", sa.String(length=128), nullable=False),
        sa.Column("mall_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["mall_id"], ["mall.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_unit_name"), "unit", ["name"], unique=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_unit_name"), table_name="unit")
    op.drop_table("unit")
    op.drop_index(op.f("ix_mall_name"), table_name="mall")
    op.drop_table("mall")
    op.drop_index(op.f("ix_account_username"), table_name="account")
    op.drop_index(op.f("ix_account_email"), table_name="account")
    op.drop_table("account")
    # ### end Alembic commands ###
