"""'initial migration'

Revision ID: 7bd1eff2af2b
Revises: 
Create Date: 2021-05-16 13:59:53.685952

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "7bd1eff2af2b"
down_revision = None
branch_labels = ("iex",)
depends_on = None


def upgrade():
    op.execute("create schema iex")
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "exchange",
        sa.Column("exchange", sa.String(), nullable=True),
        sa.Column("region", sa.String(), nullable=True),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("mic", sa.String(), nullable=True),
        sa.Column("exchange_suffix", sa.String(), nullable=True),
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("exchange"),
        schema="iex",
    )
    op.create_table(
        "usexchange",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(), nullable=True),
        sa.Column("long_name", sa.String(), nullable=True),
        sa.Column("mic", sa.String(), nullable=True),
        sa.Column("tape_id", sa.String(), nullable=True),
        sa.Column("oats_id", sa.String(), nullable=True),
        sa.Column("ref_id", sa.String(), nullable=True),
        sa.Column("type", sa.String(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        schema="iex",
    )
    op.create_table(
        "symbol",
        sa.Column("symbol", sa.String(), nullable=True),
        sa.Column("exchange_id", sa.String(), nullable=True),
        sa.Column("name", sa.String(), nullable=True),
        sa.Column("date", sa.Date(), nullable=True),
        sa.Column("is_enabled", sa.Boolean(), nullable=True),
        sa.Column("region", sa.String(), nullable=True),
        sa.Column("currency", sa.String(), nullable=True),
        sa.Column("iex_id", sa.String(), nullable=True),
        sa.Column("figi", sa.String(), nullable=True),
        sa.Column("cik", sa.String(), nullable=True),
        sa.Column(
            "type",
            sa.Enum(
                "ad", "cs", "cef", "et", "oef", "ps", "rt", "struct", "ut", "wi", "wt", "crypto", name="symbol_type"
            ),
            nullable=True,
        ),
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["exchange_id"],
            ["iex.exchange.exchange"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("symbol"),
        schema="iex",
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("symbol", schema="iex")
    op.drop_table("usexchange", schema="iex")
    op.drop_table("exchange", schema="iex")
    # ### end Alembic commands ###
    op.execute("drop schema iex")
