"""add_eodp_id_to_samples

Revision ID: eaf7958d318d
Revises: 0fcf4cc40b4b
Create Date: 2022-02-22 18:21:33.066100

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'eaf7958d318d'
down_revision = '0fcf4cc40b4b'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('samples', sa.Column('eodp_id', sa.String(), nullable=True))
    op.create_foreign_key(None, 'samples_taxa', 'taxa', ['taxon_id'], ['id'])
    op.alter_column('taxa', 'created_at',
               existing_type=postgresql.TIMESTAMP(),
               nullable=False)
    op.alter_column('taxa', 'name',
               existing_type=sa.VARCHAR(),
               nullable=False)
    op.alter_column('taxa', 'taxon_group',
               existing_type=sa.VARCHAR(),
               nullable=False)
    op.create_foreign_key(None, 'taxa_crosswalk', 'taxa', ['taxon_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'taxa_crosswalk', type_='foreignkey')
    op.alter_column('taxa', 'taxon_group',
               existing_type=sa.VARCHAR(),
               nullable=True)
    op.alter_column('taxa', 'name',
               existing_type=sa.VARCHAR(),
               nullable=True)
    op.alter_column('taxa', 'created_at',
               existing_type=postgresql.TIMESTAMP(),
               nullable=True)
    op.drop_constraint(None, 'samples_taxa', type_='foreignkey')
    op.drop_column('samples', 'eodp_id')

    # ### end Alembic commands ###
