"""add foreign keys for election.

Revision ID: 0ffb83856183
Revises: a32e8a67e64a
Create Date: 2022-08-17 08:12:02.477123

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0ffb83856183'
down_revision = 'a32e8a67e64a'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('areas', sa.Column('election_id', sa.String(length=255), nullable=True))
    op.create_foreign_key(None, 'areas', 'elections', ['election_id'], ['id'])
    op.add_column('contests', sa.Column('election_id', sa.String(length=255), nullable=True))
    op.create_foreign_key(None, 'contests', 'elections', ['election_id'], ['id'])
    op.add_column('questions', sa.Column('election_id', sa.String(length=255), nullable=True))
    op.create_foreign_key(None, 'questions', 'elections', ['election_id'], ['id'])
    op.add_column('results', sa.Column('election_id', sa.String(length=255), nullable=True))
    op.create_foreign_key(None, 'results', 'elections', ['election_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'results', type_='foreignkey')
    op.drop_column('results', 'election_id')
    op.drop_constraint(None, 'questions', type_='foreignkey')
    op.drop_column('questions', 'election_id')
    op.drop_constraint(None, 'contests', type_='foreignkey')
    op.drop_column('contests', 'election_id')
    op.drop_constraint(None, 'areas', type_='foreignkey')
    op.drop_column('areas', 'election_id')
    # ### end Alembic commands ###
