""" cd derivation tables

Revision ID: d15d2cdfa25e
Revises: 7464131caaa8
Create Date: 2023-04-11 14:51:43.485069

"""

# revision identifiers, used by Alembic.
revision = 'd15d2cdfa25e'
down_revision = '7464131caaa8'
branch_labels = None
depends_on = None

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

def upgrade(engine_name):
    globals()["upgrade_%s" % engine_name]()


def downgrade(engine_name):
    globals()["downgrade_%s" % engine_name]()





def upgrade_data_broker():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('cd_city_grouped',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('cd_city_grouped_id', sa.Integer(), nullable=False),
    sa.Column('city_name', sa.Text(), nullable=True),
    sa.Column('state_abbreviation', sa.Text(), nullable=True),
    sa.Column('congressional_district_no', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('cd_city_grouped_id')
    )
    op.create_index(op.f('ix_cd_city_grouped_city_name'), 'cd_city_grouped', ['city_name'], unique=False)
    op.create_index(op.f('ix_cd_city_grouped_state_abbreviation'), 'cd_city_grouped', ['state_abbreviation'], unique=False)
    op.create_table('cd_county_grouped',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('cd_county_grouped_id', sa.Integer(), nullable=False),
    sa.Column('county_number', sa.Text(), nullable=True),
    sa.Column('state_abbreviation', sa.Text(), nullable=True),
    sa.Column('congressional_district_no', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('cd_county_grouped_id')
    )
    op.create_index(op.f('ix_cd_county_grouped_county_number'), 'cd_county_grouped', ['county_number'], unique=False)
    op.create_index(op.f('ix_cd_county_grouped_state_abbreviation'), 'cd_county_grouped', ['state_abbreviation'], unique=False)
    op.create_table('cd_state_grouped',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('cd_state_grouped_id', sa.Integer(), nullable=False),
    sa.Column('state_abbreviation', sa.Text(), nullable=True),
    sa.Column('congressional_district_no', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('cd_state_grouped_id')
    )
    op.create_index(op.f('ix_cd_state_grouped_state_abbreviation'), 'cd_state_grouped', ['state_abbreviation'], unique=False)
    op.create_table('cd_zips_grouped',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('cd_zips_grouped_id', sa.Integer(), nullable=False),
    sa.Column('zip5', sa.Text(), nullable=True),
    sa.Column('state_abbreviation', sa.Text(), nullable=True),
    sa.Column('congressional_district_no', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('cd_zips_grouped_id')
    )
    op.create_index(op.f('ix_cd_zips_grouped_zip5'), 'cd_zips_grouped', ['zip5'], unique=False)
    op.create_index(op.f('ix_cd_zips_grouped_state_abbreviation'), 'cd_zips_grouped', ['state_abbreviation'], unique=False)
    op.create_table('cd_zips_grouped_historical',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('cd_zips_grouped_historical_id', sa.Integer(), nullable=False),
    sa.Column('zip5', sa.Text(), nullable=True),
    sa.Column('state_abbreviation', sa.Text(), nullable=True),
    sa.Column('congressional_district_no', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('cd_zips_grouped_historical_id')
    )
    op.create_index(op.f('ix_cd_zips_grouped_historical_zip5'), 'cd_zips_grouped_historical', ['zip5'], unique=False)
    op.create_index(op.f('ix_cd_zips_grouped_historical_state_abbreviation'), 'cd_zips_grouped_historical', ['state_abbreviation'], unique=False)
    # ### end Alembic commands ###


def downgrade_data_broker():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_cd_zips_grouped_historical_zip5'), table_name='cd_zips_grouped_historical')
    op.drop_table('cd_zips_grouped_historical')
    op.drop_index(op.f('ix_cd_zips_grouped_zip5'), table_name='cd_zips_grouped')
    op.drop_table('cd_zips_grouped')
    op.drop_index(op.f('ix_cd_state_grouped_state_abbreviation'), table_name='cd_state_grouped')
    op.drop_table('cd_state_grouped')
    op.drop_index(op.f('ix_cd_county_grouped_state_abbreviation'), table_name='cd_county_grouped')
    op.drop_index(op.f('ix_cd_county_grouped_county_number'), table_name='cd_county_grouped')
    op.drop_table('cd_county_grouped')
    op.drop_index(op.f('ix_cd_city_grouped_state_abbreviation'), table_name='cd_city_grouped')
    op.drop_index(op.f('ix_cd_city_grouped_city_name'), table_name='cd_city_grouped')
    op.drop_table('cd_city_grouped')
    # ### end Alembic commands ###

