<reponame>BuildJet/dispatch<gh_stars>1-10
"""Adds more cascading deletes

Revision ID: e45e8226932a
Revises: <KEY>
Create Date: 2021-03-17 11:47:17.196729

"""
from alembic import op


# revision identifiers, used by Alembic.
revision = "e45e8226932a"
down_revision = "<KEY>"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint("document_terms_term_id_fkey", "document_terms", type_="foreignkey")
    op.drop_constraint("document_terms_document_id_fkey", "document_terms", type_="foreignkey")
    op.create_foreign_key(
        None, "document_terms", "document", ["document_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(None, "document_terms", "term", ["term_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint(
        "workflow_instance_artifact_workflow_instance_id_fkey",
        "workflow_instance_artifact",
        type_="foreignkey",
    )
    op.drop_constraint(
        "workflow_instance_artifact_document_id_fkey",
        "workflow_instance_artifact",
        type_="foreignkey",
    )
    op.create_foreign_key(
        None,
        "workflow_instance_artifact",
        "workflow_instance",
        ["workflow_instance_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.create_foreign_key(
        None, "workflow_instance_artifact", "document", ["document_id"], ["id"], ondelete="CASCADE"
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, "workflow_instance_artifact", type_="foreignkey")
    op.drop_constraint(None, "workflow_instance_artifact", type_="foreignkey")
    op.create_foreign_key(
        "workflow_instance_artifact_document_id_fkey",
        "workflow_instance_artifact",
        "document",
        ["document_id"],
        ["id"],
    )
    op.create_foreign_key(
        "workflow_instance_artifact_workflow_instance_id_fkey",
        "workflow_instance_artifact",
        "workflow_instance",
        ["workflow_instance_id"],
        ["id"],
    )
    op.drop_constraint(None, "document_terms", type_="foreignkey")
    op.drop_constraint(None, "document_terms", type_="foreignkey")
    op.create_foreign_key(
        "document_terms_document_id_fkey", "document_terms", "document", ["document_id"], ["id"]
    )
    op.create_foreign_key(
        "document_terms_term_id_fkey", "document_terms", "term", ["term_id"], ["id"]
    )
    # ### end Alembic commands ###
