"""update on delete clauses to use set null instead of cascade

Revision ID: 8a5a0fc19ae9
Revises: af11679dca81
Create Date: 2021-03-19 19:48:26.051184

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8a5a0fc19ae9'
down_revision = 'af11679dca81'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('fk_bounty_assigned_user_id_user', 'bounty', type_='foreignkey')
    op.create_foreign_key(op.f('fk_bounty_assigned_user_id_user'), 'bounty', 'user', ['assigned_user_id'], ['user_id'], ondelete='SET NULL')
    op.drop_constraint('bounty_application_bounty_id_fkey', 'bounty_application', type_='foreignkey')
    op.create_foreign_key(op.f('fk_bounty_application_bounty_id_bounty'), 'bounty_application', 'bounty', ['bounty_id'], ['bounty_id'], ondelete='SET NULL')
    op.drop_constraint('fk_bounty_categories_category_id_category', 'bounty_categories', type_='foreignkey')
    op.create_foreign_key(op.f('fk_bounty_categories_category_id_category'), 'bounty_categories', 'category', ['category_id'], ['category_id'], ondelete='CASCADE')
    op.drop_constraint('fk_investment_bounty_id_bounty', 'investment', type_='foreignkey')
    op.create_foreign_key(op.f('fk_investment_bounty_id_bounty'), 'investment', 'bounty', ['bounty_id'], ['bounty_id'], ondelete='SET NULL')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(op.f('fk_investment_bounty_id_bounty'), 'investment', type_='foreignkey')
    op.create_foreign_key('fk_investment_bounty_id_bounty', 'investment', 'bounty', ['bounty_id'], ['bounty_id'])
    op.drop_constraint(op.f('fk_bounty_categories_category_id_category'), 'bounty_categories', type_='foreignkey')
    op.create_foreign_key('fk_bounty_categories_category_id_category', 'bounty_categories', 'category', ['category_id'], ['category_id'])
    op.drop_constraint(op.f('fk_bounty_application_bounty_id_bounty'), 'bounty_application', type_='foreignkey')
    op.create_foreign_key('bounty_application_bounty_id_fkey', 'bounty_application', 'bounty', ['bounty_id'], ['bounty_id'], ondelete='CASCADE')
    op.drop_constraint(op.f('fk_bounty_assigned_user_id_user'), 'bounty', type_='foreignkey')
    op.create_foreign_key('fk_bounty_assigned_user_id_user', 'bounty', 'user', ['assigned_user_id'], ['user_id'], ondelete='CASCADE')
    # ### end Alembic commands ###
