def upgrade()

in src/dispatch/database/revisions/tenant/versions/2021-06-15_8a558baeef05.py [0:0]


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("document_terms")
    op.drop_table("team_contact_terms")
    op.drop_table("recommendation_documents")
    op.drop_table("service_incident_type")
    op.drop_table("assoc_individual_contact_incident_priority")
    op.drop_table("recommendation_terms")
    op.drop_table("team_contact_incident_priority")
    op.drop_table("recommendation_individual_contacts")
    op.drop_table("assoc_individual_contact_terms")
    op.drop_table("recommendation_incident_types")
    op.drop_table("assoc_individual_contact_incident_type")
    op.drop_table("recommendation_incident_priorities")
    op.drop_table("document_incident_priority")
    op.drop_table("service_incident_priority")
    op.drop_table("document_incident_type")
    op.drop_table("recommendation_services")
    op.drop_table("service_terms")
    op.drop_table("team_contact_incident_type")
    op.drop_table("recommendation_team_contacts")
    op.drop_table("recommendation_accuracy")
    op.drop_constraint(
        "assoc_document_filters_document_id_fkey", "assoc_document_filters", type_="foreignkey"
    )
    op.drop_constraint(
        "assoc_document_filters_search_filter_id_fkey", "assoc_document_filters", type_="foreignkey"
    )
    op.create_foreign_key(
        None,
        "assoc_document_filters",
        "search_filter",
        ["search_filter_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.create_foreign_key(
        None, "assoc_document_filters", "document", ["document_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "assoc_incident_tags_incident_id_fkey", "assoc_incident_tags", type_="foreignkey"
    )
    op.drop_constraint("assoc_incident_tags_tag_id_fkey", "assoc_incident_tags", type_="foreignkey")
    op.create_foreign_key(
        None, "assoc_incident_tags", "incident", ["incident_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(
        None, "assoc_incident_tags", "tag", ["tag_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "assoc_incident_terms_incident_id_fkey", "assoc_incident_terms", type_="foreignkey"
    )
    op.drop_constraint(
        "assoc_incident_terms_term_id_fkey", "assoc_incident_terms", type_="foreignkey"
    )
    op.create_foreign_key(
        None, "assoc_incident_terms", "incident", ["incident_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(
        None, "assoc_incident_terms", "term", ["term_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "assoc_individual_contact_filters_search_filter_id_fkey",
        "assoc_individual_contact_filters",
        type_="foreignkey",
    )
    op.drop_constraint(
        "assoc_individual_contact_filters_individual_contact_id_fkey",
        "assoc_individual_contact_filters",
        type_="foreignkey",
    )
    op.create_foreign_key(
        None,
        "assoc_individual_contact_filters",
        "individual_contact",
        ["individual_contact_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.create_foreign_key(
        None,
        "assoc_individual_contact_filters",
        "search_filter",
        ["search_filter_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.drop_constraint(
        "assoc_notification_filters_search_filter_id_fkey",
        "assoc_notification_filters",
        type_="foreignkey",
    )
    op.drop_constraint(
        "assoc_notification_filters_notification_id_fkey",
        "assoc_notification_filters",
        type_="foreignkey",
    )
    op.create_foreign_key(
        None,
        "assoc_notification_filters",
        "search_filter",
        ["search_filter_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.create_foreign_key(
        None,
        "assoc_notification_filters",
        "notification",
        ["notification_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.drop_constraint(
        "assoc_service_filters_service_id_fkey", "assoc_service_filters", type_="foreignkey"
    )
    op.drop_constraint(
        "assoc_service_filters_search_filter_id_fkey", "assoc_service_filters", type_="foreignkey"
    )
    op.create_foreign_key(
        None,
        "assoc_service_filters",
        "search_filter",
        ["search_filter_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.create_foreign_key(
        None, "assoc_service_filters", "service", ["service_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "assoc_team_contact_filters_search_filter_id_fkey",
        "assoc_team_contact_filters",
        type_="foreignkey",
    )
    op.drop_constraint(
        "assoc_team_contact_filters_team_contact_id_fkey",
        "assoc_team_contact_filters",
        type_="foreignkey",
    )
    op.create_foreign_key(
        None,
        "assoc_team_contact_filters",
        "team_contact",
        ["team_contact_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.create_foreign_key(
        None,
        "assoc_team_contact_filters",
        "search_filter",
        ["search_filter_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.drop_constraint("conference_incident_id_fkey", "conference", type_="foreignkey")
    op.create_foreign_key(
        None, "conference", "incident", ["incident_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint("conversation_incident_id_fkey", "conversation", type_="foreignkey")
    op.create_foreign_key(
        None, "conversation", "incident", ["incident_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint("definition_project_id_fkey", "definition", type_="foreignkey")
    op.create_foreign_key(None, "definition", "project", ["project_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint(
        "definition_teams_definition_id_fkey", "definition_teams", type_="foreignkey"
    )
    op.drop_constraint(
        "definition_teams_team_contact_id_fkey", "definition_teams", type_="foreignkey"
    )
    op.create_foreign_key(None, "definition_teams", "definition", ["definition_id"], ["id"])
    op.create_foreign_key(None, "definition_teams", "team_contact", ["team_contact_id"], ["id"])
    op.drop_constraint("definition_terms_term_id_fkey", "definition_terms", type_="foreignkey")
    op.drop_constraint(
        "definition_terms_definition_id_fkey", "definition_terms", type_="foreignkey"
    )
    op.create_foreign_key(None, "definition_terms", "term", ["term_id"], ["id"])
    op.create_foreign_key(None, "definition_terms", "definition", ["definition_id"], ["id"])
    op.alter_column(
        "dispatch_user_project", "dispatch_user_id", existing_type=sa.INTEGER(), nullable=False
    )
    op.alter_column(
        "dispatch_user_project", "project_id", existing_type=sa.INTEGER(), nullable=False
    )
    op.drop_constraint(
        "dispatch_user_project_project_id_fkey", "dispatch_user_project", type_="foreignkey"
    )
    op.drop_constraint(
        "dispatch_user_project_dispatch_user_id_fkey", "dispatch_user_project", type_="foreignkey"
    )
    op.create_foreign_key(None, "dispatch_user_project", "project", ["project_id"], ["id"])
    op.create_foreign_key(
        None,
        "dispatch_user_project",
        "dispatch_user",
        ["dispatch_user_id"],
        ["id"],
        referent_schema="dispatch_core",
    )
    op.drop_column("dispatch_user_project", "id")
    op.drop_constraint("document_project_id_fkey", "document", type_="foreignkey")
    op.drop_constraint("document_incident_id_fkey", "document", type_="foreignkey")
    op.drop_constraint("document_report_id_fkey", "document", type_="foreignkey")
    op.create_foreign_key(None, "document", "project", ["project_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(None, "document", "report", ["report_id"], ["id"])
    op.create_foreign_key(
        None, "document", "incident", ["incident_id"], ["id"], ondelete="CASCADE", use_alter=True
    )
    op.drop_constraint("event_incident_id_fkey", "event", type_="foreignkey")
    op.drop_constraint("event_individual_id_fkey", "event", type_="foreignkey")
    op.create_foreign_key(
        None, "event", "individual_contact", ["individual_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(None, "event", "incident", ["incident_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("feedback_incident_id_fkey", "feedback", type_="foreignkey")
    op.drop_constraint("feedback_participant_id_fkey", "feedback", type_="foreignkey")
    op.create_foreign_key(None, "feedback", "incident", ["incident_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(None, "feedback", "participant", ["participant_id"], ["id"])
    op.drop_constraint("group_incident_id_fkey", "group", type_="foreignkey")
    op.create_foreign_key(None, "group", "incident", ["incident_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("incident_project_id_fkey", "incident", type_="foreignkey")
    op.drop_constraint("incident_incident_type_id_fkey", "incident", type_="foreignkey")
    op.drop_constraint("incident_duplicate_id_fkey", "incident", type_="foreignkey")
    op.drop_constraint("incident_incident_priority_id_fkey", "incident", type_="foreignkey")
    op.create_foreign_key(None, "incident", "project", ["project_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(None, "incident", "incident_priority", ["incident_priority_id"], ["id"])
    op.create_foreign_key(None, "incident", "incident", ["duplicate_id"], ["id"])
    op.create_foreign_key(None, "incident", "incident_type", ["incident_type_id"], ["id"])
    op.drop_constraint("incident_cost_incident_id_fkey", "incident_cost", type_="foreignkey")
    op.drop_constraint("incident_cost_project_id_fkey", "incident_cost", type_="foreignkey")
    op.drop_constraint(
        "incident_cost_incident_cost_type_id_fkey", "incident_cost", type_="foreignkey"
    )
    op.create_foreign_key(
        None, "incident_cost", "incident_cost_type", ["incident_cost_type_id"], ["id"]
    )
    op.create_foreign_key(
        None, "incident_cost", "incident", ["incident_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(
        None, "incident_cost", "project", ["project_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "incident_cost_type_project_id_fkey", "incident_cost_type", type_="foreignkey"
    )
    op.create_foreign_key(
        None, "incident_cost_type", "project", ["project_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint("incident_priority_project_id_fkey", "incident_priority", type_="foreignkey")
    op.create_foreign_key(
        None, "incident_priority", "project", ["project_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "incident_type_template_document_id_fkey", "incident_type", type_="foreignkey"
    )
    op.drop_constraint("incident_type_project_id_fkey", "incident_type", type_="foreignkey")
    op.drop_constraint(
        "incident_type_commander_service_id_fkey", "incident_type", type_="foreignkey"
    )
    op.execute(
        "ALTER TABLE incident_type DROP CONSTRAINT IF EXISTS incident_type_liason_service_id_fkey"
    )
    op.create_foreign_key(None, "incident_type", "service", ["commander_service_id"], ["id"])
    op.create_foreign_key(None, "incident_type", "document", ["template_document_id"], ["id"])
    op.create_foreign_key(None, "incident_type", "service", ["liaison_service_id"], ["id"])
    op.create_foreign_key(
        None, "incident_type", "project", ["project_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "individual_contact_project_id_fkey", "individual_contact", type_="foreignkey"
    )
    op.drop_constraint(
        "individual_contact_team_contact_id_fkey", "individual_contact", type_="foreignkey"
    )
    op.create_foreign_key(None, "individual_contact", "team_contact", ["team_contact_id"], ["id"])
    op.create_foreign_key(
        None, "individual_contact", "project", ["project_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint("notification_project_id_fkey", "notification", type_="foreignkey")
    op.create_foreign_key(
        None, "notification", "project", ["project_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint("participant_service_id_fkey", "participant", type_="foreignkey")
    op.drop_constraint("participant_incident_id_fkey", "participant", type_="foreignkey")
    op.drop_constraint("participant_added_by_id_fkey", "participant", type_="foreignkey")
    op.drop_constraint("participant_individual_contact_id_fkey", "participant", type_="foreignkey")
    op.create_foreign_key(
        None, "participant", "individual_contact", ["individual_contact_id"], ["id"]
    )
    op.create_foreign_key(
        None, "participant", "service", ["service_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(None, "participant", "participant", ["added_by_id"], ["id"])
    op.create_foreign_key(
        None, "participant", "incident", ["incident_id"], ["id"], ondelete="CASCADE", use_alter=True
    )
    op.drop_constraint(
        "participant_role_participant_id_fkey", "participant_role", type_="foreignkey"
    )
    op.create_foreign_key(
        None, "participant_role", "participant", ["participant_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint("plugin_instance_plugin_id_fkey", "plugin_instance", type_="foreignkey")
    op.drop_constraint("plugin_instance_project_id_fkey", "plugin_instance", type_="foreignkey")
    op.create_foreign_key(
        None, "plugin_instance", "project", ["project_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(
        None, "plugin_instance", "plugin", ["plugin_id"], ["id"], referent_schema="dispatch_core"
    )
    op.drop_constraint("project_organization_id_fkey", "project", type_="foreignkey")
    op.create_foreign_key(
        None,
        "project",
        "organization",
        ["organization_id"],
        ["id"],
        referent_schema="dispatch_core",
    )
    op.drop_constraint("recommendation_incident_id_fkey", "recommendation", type_="foreignkey")
    op.create_foreign_key(None, "recommendation", "incident", ["incident_id"], ["id"])
    op.drop_column("recommendation", "text")
    op.drop_constraint(
        "recommendation_match_recommendation_id_fkey", "recommendation_match", type_="foreignkey"
    )
    op.create_foreign_key(
        None, "recommendation_match", "recommendation", ["recommendation_id"], ["id"]
    )
    op.drop_constraint("report_participant_id_fkey", "report", type_="foreignkey")
    op.drop_constraint("report_incident_id_fkey", "report", type_="foreignkey")
    op.create_foreign_key(None, "report", "participant", ["participant_id"], ["id"])
    op.create_foreign_key(
        None, "report", "incident", ["incident_id"], ["id"], ondelete="CASCADE", use_alter=True
    )
    op.drop_constraint("search_filter_project_id_fkey", "search_filter", type_="foreignkey")
    op.drop_constraint("search_filter_creator_id_fkey", "search_filter", type_="foreignkey")
    op.create_foreign_key(
        None, "search_filter", "project", ["project_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(
        None,
        "search_filter",
        "dispatch_user",
        ["creator_id"],
        ["id"],
        referent_schema="dispatch_core",
    )
    op.drop_constraint("service_project_id_fkey", "service", type_="foreignkey")
    op.create_foreign_key(None, "service", "project", ["project_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("service_incident_service_id_fkey", "service_incident", type_="foreignkey")
    op.drop_constraint("service_incident_incident_id_fkey", "service_incident", type_="foreignkey")
    op.create_foreign_key(None, "service_incident", "incident", ["incident_id"], ["id"])
    op.create_foreign_key(None, "service_incident", "service", ["service_id"], ["id"])
    op.drop_constraint("storage_incident_id_fkey", "storage", type_="foreignkey")
    op.create_foreign_key(None, "storage", "incident", ["incident_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("tag_project_id_fkey", "tag", type_="foreignkey")
    op.drop_constraint("tag_tag_type_id_fkey", "tag", type_="foreignkey")
    op.create_foreign_key(None, "tag", "project", ["project_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(None, "tag", "tag_type", ["tag_type_id"], ["id"])
    op.drop_constraint("tag_type_project_id_fkey", "tag_type", type_="foreignkey")
    op.create_foreign_key(None, "tag_type", "project", ["project_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("task_incident_id_fkey", "task", type_="foreignkey")
    op.drop_constraint("task_creator_id_fkey", "task", type_="foreignkey")
    op.drop_constraint("task_owner_id_fkey", "task", type_="foreignkey")
    op.create_foreign_key(None, "task", "incident", ["incident_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(None, "task", "participant", ["creator_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(None, "task", "participant", ["owner_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("task_assignees_task_id_fkey", "task_assignees", type_="foreignkey")
    op.drop_constraint("task_assignees_participant_id_fkey", "task_assignees", type_="foreignkey")
    op.create_foreign_key(
        None, "task_assignees", "participant", ["participant_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(None, "task_assignees", "task", ["task_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("task_tickets_task_id_fkey", "task_tickets", type_="foreignkey")
    op.drop_constraint("task_tickets_ticket_id_fkey", "task_tickets", type_="foreignkey")
    op.create_foreign_key(None, "task_tickets", "task", ["task_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(None, "task_tickets", "ticket", ["ticket_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("team_contact_project_id_fkey", "team_contact", type_="foreignkey")
    op.create_foreign_key(
        None, "team_contact", "project", ["project_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "team_contact_incident_incident_id_fkey", "team_contact_incident", type_="foreignkey"
    )
    op.drop_constraint(
        "team_contact_incident_team_contact_id_fkey", "team_contact_incident", type_="foreignkey"
    )
    op.create_foreign_key(
        None, "team_contact_incident", "team_contact", ["team_contact_id"], ["id"]
    )
    op.create_foreign_key(None, "team_contact_incident", "incident", ["incident_id"], ["id"])
    op.drop_constraint("term_project_id_fkey", "term", type_="foreignkey")
    op.create_foreign_key(None, "term", "project", ["project_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("ticket_incident_id_fkey", "ticket", type_="foreignkey")
    op.create_foreign_key(None, "ticket", "incident", ["incident_id"], ["id"], ondelete="CASCADE")
    op.drop_constraint("workflow_plugin_id_fkey", "workflow", type_="foreignkey")
    op.drop_constraint("workflow_project_id_fkey", "workflow", type_="foreignkey")
    op.create_foreign_key(None, "workflow", "project", ["project_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(
        None, "workflow", "plugin", ["plugin_id"], ["id"], referent_schema="dispatch_core"
    )
    op.drop_constraint(
        "workflow_incident_priority_incident_priority_id_fkey",
        "workflow_incident_priority",
        type_="foreignkey",
    )
    op.drop_constraint(
        "workflow_incident_priority_workflow_id_fkey",
        "workflow_incident_priority",
        type_="foreignkey",
    )
    op.create_foreign_key(
        None,
        "workflow_incident_priority",
        "incident_priority",
        ["incident_priority_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.create_foreign_key(
        None, "workflow_incident_priority", "workflow", ["workflow_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "workflow_incident_type_incident_type_id_fkey", "workflow_incident_type", type_="foreignkey"
    )
    op.drop_constraint(
        "workflow_incident_type_workflow_id_fkey", "workflow_incident_type", type_="foreignkey"
    )
    op.create_foreign_key(
        None,
        "workflow_incident_type",
        "incident_type",
        ["incident_type_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.create_foreign_key(
        None, "workflow_incident_type", "workflow", ["workflow_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint("workflow_instance_creator_id_fkey", "workflow_instance", type_="foreignkey")
    op.drop_constraint(
        "workflow_instance_incident_id_fkey", "workflow_instance", type_="foreignkey"
    )
    op.drop_constraint(
        "workflow_instance_workflow_id_fkey", "workflow_instance", type_="foreignkey"
    )
    op.create_foreign_key(None, "workflow_instance", "participant", ["creator_id"], ["id"])
    op.create_foreign_key(None, "workflow_instance", "workflow", ["workflow_id"], ["id"])
    op.create_foreign_key(
        None, "workflow_instance", "incident", ["incident_id"], ["id"], ondelete="CASCADE"
    )
    op.drop_constraint(
        "workflow_instance_artifact_document_id_fkey",
        "workflow_instance_artifact",
        type_="foreignkey",
    )
    op.drop_constraint(
        "workflow_instance_artifact_workflow_instance_id_fkey",
        "workflow_instance_artifact",
        type_="foreignkey",
    )
    op.create_foreign_key(
        None, "workflow_instance_artifact", "document", ["document_id"], ["id"], ondelete="CASCADE"
    )
    op.create_foreign_key(
        None,
        "workflow_instance_artifact",
        "workflow_instance",
        ["workflow_instance_id"],
        ["id"],
        ondelete="CASCADE",
    )
    op.drop_constraint("workflow_term_workflow_id_fkey", "workflow_term", type_="foreignkey")
    op.drop_constraint("workflow_term_term_id_fkey", "workflow_term", type_="foreignkey")
    op.create_foreign_key(None, "workflow_term", "term", ["term_id"], ["id"], ondelete="CASCADE")
    op.create_foreign_key(
        None, "workflow_term", "workflow", ["workflow_id"], ["id"], ondelete="CASCADE"
    )