"""add_responsaveis_financas_imprensa

Revision ID: add_responsaveis_financas_imprensa
Revises: add_aspirante_fields
Create Date: 2024-03-19 10:00:00.000000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'add_responsaveis_financas_imprensa'
down_revision = 'add_aspirante_fields'
branch_labels = None
depends_on = None


def upgrade():
    # Adicionar colunas na tabela celulas
    op.add_column('celulas', sa.Column('responsavel_financas_id', sa.Integer(), nullable=True))
    op.add_column('celulas', sa.Column('responsavel_imprensa_id', sa.Integer(), nullable=True))
    op.create_foreign_key('fk_celulas_responsavel_financas', 'celulas', 'militantes', ['responsavel_financas_id'], ['id'])
    op.create_foreign_key('fk_celulas_responsavel_imprensa', 'celulas', 'militantes', ['responsavel_imprensa_id'], ['id'])
    
    # Adicionar colunas na tabela setores
    op.add_column('setores', sa.Column('responsavel_financas_id', sa.Integer(), nullable=True))
    op.add_column('setores', sa.Column('responsavel_imprensa_id', sa.Integer(), nullable=True))
    op.create_foreign_key('fk_setores_responsavel_financas', 'setores', 'militantes', ['responsavel_financas_id'], ['id'])
    op.create_foreign_key('fk_setores_responsavel_imprensa', 'setores', 'militantes', ['responsavel_imprensa_id'], ['id'])
    
    # Adicionar colunas na tabela crs
    op.add_column('crs', sa.Column('responsavel_financas_id', sa.Integer(), nullable=True))
    op.add_column('crs', sa.Column('responsavel_imprensa_id', sa.Integer(), nullable=True))
    op.create_foreign_key('fk_crs_responsavel_financas', 'crs', 'militantes', ['responsavel_financas_id'], ['id'])
    op.create_foreign_key('fk_crs_responsavel_imprensa', 'crs', 'militantes', ['responsavel_imprensa_id'], ['id'])
    
    # Adicionar colunas na tabela ccs
    op.add_column('ccs', sa.Column('responsavel_financas_id', sa.Integer(), nullable=True))
    op.add_column('ccs', sa.Column('responsavel_imprensa_id', sa.Integer(), nullable=True))
    op.create_foreign_key('fk_ccs_responsavel_financas', 'ccs', 'militantes', ['responsavel_financas_id'], ['id'])
    op.create_foreign_key('fk_ccs_responsavel_imprensa', 'ccs', 'militantes', ['responsavel_imprensa_id'], ['id'])


def downgrade():
    # Remover foreign keys
    op.drop_constraint('fk_celulas_responsavel_financas', 'celulas', type_='foreignkey')
    op.drop_constraint('fk_celulas_responsavel_imprensa', 'celulas', type_='foreignkey')
    op.drop_constraint('fk_setores_responsavel_financas', 'setores', type_='foreignkey')
    op.drop_constraint('fk_setores_responsavel_imprensa', 'setores', type_='foreignkey')
    op.drop_constraint('fk_crs_responsavel_financas', 'crs', type_='foreignkey')
    op.drop_constraint('fk_crs_responsavel_imprensa', 'crs', type_='foreignkey')
    op.drop_constraint('fk_ccs_responsavel_financas', 'ccs', type_='foreignkey')
    op.drop_constraint('fk_ccs_responsavel_imprensa', 'ccs', type_='foreignkey')
    
    # Remover colunas
    op.drop_column('celulas', 'responsavel_financas_id')
    op.drop_column('celulas', 'responsavel_imprensa_id')
    op.drop_column('setores', 'responsavel_financas_id')
    op.drop_column('setores', 'responsavel_imprensa_id')
    op.drop_column('crs', 'responsavel_financas_id')
    op.drop_column('crs', 'responsavel_imprensa_id')
    op.drop_column('ccs', 'responsavel_financas_id')
    op.drop_column('ccs', 'responsavel_imprensa_id') 