"""Add cascade deletes to dag node references

Revision ID: 00cb22315e1b
Revises: e73199299bfa
Create Date: 2025-05-06 23:41:36.606272

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '00cb22315e1b'
down_revision = 'e73199299bfa'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('dag_node_entity_definition_id_fkey', 'dag_node', type_='foreignkey')
    op.drop_constraint('dag_node_transformer_id_fkey', 'dag_node', type_='foreignkey')
    op.drop_constraint('dag_node_connection_id_fkey', 'dag_node', type_='foreignkey')
    op.create_foreign_key(None, 'dag_node', 'entity_definition', ['entity_definition_id'], ['id'], ondelete='CASCADE')
    op.create_foreign_key(None, 'dag_node', 'transformer', ['transformer_id'], ['id'], ondelete='CASCADE')
    op.create_foreign_key(None, 'dag_node', 'connection', ['connection_id'], ['id'], ondelete='CASCADE')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'dag_node', type_='foreignkey')
    op.drop_constraint(None, 'dag_node', type_='foreignkey')
    op.drop_constraint(None, 'dag_node', type_='foreignkey')
    op.create_foreign_key('dag_node_connection_id_fkey', 'dag_node', 'connection', ['connection_id'], ['id'])
    op.create_foreign_key('dag_node_transformer_id_fkey', 'dag_node', 'transformer', ['transformer_id'], ['id'])
    op.create_foreign_key('dag_node_entity_definition_id_fkey', 'dag_node', 'entity_definition', ['entity_definition_id'], ['id'])
    # ### end Alembic commands ###
