"""Created first tables

Revision ID: 09740f1cd33d
Revises: 
Create Date: 2020-01-07 16:56:03.504331

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

# revision identifiers, used by Alembic.
revision = '09740f1cd33d'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'pokedex_abilities', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_pokedex_abilities'))
    )
    op.create_table(
        'pokedex_egg_group', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=20), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_pokedex_egg_group'))
    )
    op.create_table(
        'pokedex_generation', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=20), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_pokedex_generation'))
    )
    op.create_table(
        'pokedex_region', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=20), nullable=False),
        sa.Column('descriptor', sa.String(length=10), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_pokedex_region'))
    )
    op.create_table(
        'pokedex_type', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=20), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_pokedex_type'))
    )
    op.create_table(
        'pokedex_pokemon',
        sa.Column('national_dex', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=20), nullable=False),
        sa.Column('japanese_name', sa.String(length=20), nullable=False),
        sa.Column(
            'japanese_transliteration', sa.String(length=50), nullable=False
        ),
        sa.Column('japanese_romanized', sa.String(length=50), nullable=False),
        sa.Column('has_mega', sa.Boolean(), nullable=False),
        sa.Column('category', sa.String(length=20), nullable=False),
        sa.Column('hatch_time', sa.Integer(), nullable=False),
        sa.Column('experience_yield', sa.Integer(), nullable=False),
        sa.Column(
            'gender_code',
            sa.Float(precision=4, asdecimal=True),
            nullable=False
        ), sa.Column('catch_rate', sa.Integer(), nullable=False),
        sa.Column('introduced_generation', sa.Integer(), nullable=True),
        sa.Column('base_friendship', sa.Integer(), nullable=False),
        sa.Column('url', sqlalchemy_utils.types.url.URLType(), nullable=False),
        sa.ForeignKeyConstraint(
            ['introduced_generation'], ['pokedex_generation.id'],
            name=op.
            f('fk_pokedex_pokemon_introduced_generation_pokedex_generation')
        ),
        sa.PrimaryKeyConstraint(
            'national_dex', name=op.f('pk_pokedex_pokemon')
        )
    )
    op.create_table(
        'pokedex_form', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=20), nullable=False),
        sa.Column(
            'image_relative_link', sa.String(length=500), nullable=False
        ),
        sa.Column(
            'sprite_relative_link', sa.String(length=500), nullable=False
        ),
        sa.Column(
            'weight', sa.Float(precision=2, asdecimal=True), nullable=False
        ),
        sa.Column(
            'height', sa.Float(precision=2, asdecimal=True), nullable=False
        ), sa.Column('pokemon_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['pokemon_id'], ['pokedex_pokemon.national_dex'],
            name=op.f('fk_pokedex_form_pokemon_id_pokedex_pokemon')
        ), sa.PrimaryKeyConstraint('id', name=op.f('pk_pokedex_form'))
    )
    op.create_table(
        'pokedex_mega_stone_picture',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=20), nullable=False),
        sa.Column('image_relative_link', sa.String(length=50), nullable=False),
        sa.Column('pokemon_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['pokemon_id'], ['pokedex_pokemon.national_dex'],
            name=op.
            f('fk_pokedex_mega_stone_picture_pokemon_id_pokedex_pokemon')
        ),
        sa.PrimaryKeyConstraint(
            'id', name=op.f('pk_pokedex_mega_stone_picture')
        )
    )
    op.create_table(
        'pokedex_pokedex_pokemon_pokedex_egg_group',
        sa.Column('pokedex_egg_group_id', sa.Integer(), nullable=False),
        sa.Column('pokedex_pokemon_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['pokedex_egg_group_id'], ['pokedex_egg_group.id'],
            name=op.f(
                'fk_pokedex_pokedex_pokemon_pokedex_egg_group_pokedex_egg_group_id_pokedex_egg_group'
            )
        ),
        sa.ForeignKeyConstraint(
            ['pokedex_pokemon_id'], ['pokedex_pokemon.national_dex'],
            name=op.f(
                'fk_pokedex_pokedex_pokemon_pokedex_egg_group_pokedex_pokemon_id_pokedex_pokemon'
            )
        ),
        sa.PrimaryKeyConstraint(
            'pokedex_egg_group_id',
            'pokedex_pokemon_id',
            name=op.f('pk_pokedex_pokedex_pokemon_pokedex_egg_group')
        )
    )
    op.create_table(
        'pokedex_pokemon_dex',
        sa.Column('region_id', sa.Integer(), nullable=False),
        sa.Column('pokemon_id', sa.Integer(), nullable=False),
        sa.Column('regional_dex', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['pokemon_id'], ['pokedex_pokemon.national_dex'],
            name=op.f('fk_pokedex_pokemon_dex_pokemon_id_pokedex_pokemon')
        ),
        sa.ForeignKeyConstraint(
            ['region_id'], ['pokedex_region.id'],
            name=op.f('fk_pokedex_pokemon_dex_region_id_pokedex_region')
        ),
        sa.PrimaryKeyConstraint(
            'region_id', 'pokemon_id', name=op.f('pk_pokedex_pokemon_dex')
        )
    )
    op.create_table(
        'pokedex_form_ability',
        sa.Column('ability_id', sa.Integer(), nullable=False),
        sa.Column('form_id', sa.Integer(), nullable=False),
        sa.Column(
            'slot',
            sqlalchemy_utils.types.choice.ChoiceType([
                ('F', 'First'),
                ('S', 'Second'),
                ('H', 'Hidden'),
                ('M', 'Mega'),
            ]),
            nullable=False
        ),
        sa.ForeignKeyConstraint(
            ['ability_id'], ['pokedex_abilities.id'],
            name=op.f('fk_pokedex_form_ability_ability_id_pokedex_abilities')
        ),
        sa.ForeignKeyConstraint(
            ['form_id'], ['pokedex_form.id'],
            name=op.f('fk_pokedex_form_ability_form_id_pokedex_form')
        ),
        sa.PrimaryKeyConstraint(
            'ability_id', 'form_id', name=op.f('pk_pokedex_form_ability')
        )
    )
    op.create_table(
        'pokedex_form_type',
        sa.Column('pokemon_type_id', sa.Integer(), nullable=False),
        sa.Column('form_id', sa.Integer(), nullable=False),
        sa.Column(
            'slot',
            sqlalchemy_utils.types.choice.ChoiceType([
                ('P', 'Primary'),
                ('S', 'Secondary'),
            ]),
            nullable=False
        ),
        sa.ForeignKeyConstraint(
            ['form_id'], ['pokedex_form.id'],
            name=op.f('fk_pokedex_form_type_form_id_pokedex_form')
        ),
        sa.ForeignKeyConstraint(
            ['pokemon_type_id'], ['pokedex_type.id'],
            name=op.f('fk_pokedex_form_type_pokemon_type_id_pokedex_type')
        ),
        sa.PrimaryKeyConstraint(
            'pokemon_type_id', 'form_id', name=op.f('pk_pokedex_form_type')
        )
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('pokedex_form_type')
    op.drop_table('pokedex_form_ability')
    op.drop_table('pokedex_pokemon_dex')
    op.drop_table('pokedex_pokedex_pokemon_pokedex_egg_group')
    op.drop_table('pokedex_mega_stone_picture')
    op.drop_table('pokedex_form')
    op.drop_table('pokedex_pokemon')
    op.drop_table('pokedex_type')
    op.drop_table('pokedex_region')
    op.drop_table('pokedex_generation')
    op.drop_table('pokedex_egg_group')
    op.drop_table('pokedex_abilities')
    # ### end Alembic commands ###
