-- Foreign keys — applied after all tables exist.

ALTER TABLE ACTIVITY_LOG ADD CONSTRAINT ACTIVITY_LOG_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE ACTIVITY_LOG ADD CONSTRAINT ACTIVITY_LOG_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE ADDM_RUNS ADD CONSTRAINT ADDM_RUNS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE ADDM_RUNS ADD CONSTRAINT ADDM_RUNS_CREATED_BY_FKEY
  FOREIGN KEY (CREATED_BY) REFERENCES USERS (ID);
ALTER TABLE ADVISOR_FINDINGS ADD CONSTRAINT ADVISOR_FINDINGS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENT_CHANNEL_STATE ADD CONSTRAINT AGENT_CHANNEL_STATE_AGENT_ID_FKEY
  FOREIGN KEY (AGENT_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENT_COMMAND_QUEUE ADD CONSTRAINT AGENT_COMMAND_QUEUE_AGENT_ID_FKEY
  FOREIGN KEY (AGENT_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENT_COMMAND_RESULTS ADD CONSTRAINT AGENT_COMMAND_RESULTS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENT_COMMAND_RESULTS ADD CONSTRAINT AGENT_COMMAND_RESULTS_REQUESTED_BY_FKEY
  FOREIGN KEY (REQUESTED_BY) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE AGENT_CRASH_ALERTS_SENT ADD CONSTRAINT AGENT_CRASH_ALERTS_SENT_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENT_DIAGNOSE_RUNS ADD CONSTRAINT AGENT_DIAGNOSE_RUNS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENT_INSTALL_FAILURES ADD CONSTRAINT AGENT_INSTALL_FAILURES_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE AGENT_REG_TOKENS ADD CONSTRAINT AGENT_REG_TOKENS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENT_RESTART_EVENTS ADD CONSTRAINT AGENT_RESTART_EVENTS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENT_TUNNELS ADD CONSTRAINT AGENT_TUNNELS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENT_UPGRADE_AUDIT ADD CONSTRAINT AGENT_UPGRADE_AUDIT_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE AGENTS_LOG_BUFFER ADD CONSTRAINT AGENTS_LOG_BUFFER_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE ALERT_EVENTS ADD CONSTRAINT ALERT_EVENTS_ACKNOWLEDGED_BY_FKEY
  FOREIGN KEY (ACKNOWLEDGED_BY) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE ALERT_EVENTS ADD CONSTRAINT ALERT_EVENTS_CHECK_RUN_ID_FKEY
  FOREIGN KEY (CHECK_RUN_ID) REFERENCES HEALTH_CHECKS (ID) ON DELETE SET NULL;
ALTER TABLE ALERT_EVENTS ADD CONSTRAINT ALERT_EVENTS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE ALERT_EVENTS ADD CONSTRAINT ALERT_EVENTS_POLICY_ID_FKEY
  FOREIGN KEY (POLICY_ID) REFERENCES ALERT_POLICIES (ID) ON DELETE CASCADE;
ALTER TABLE ALERT_POLICIES ADD CONSTRAINT ALERT_POLICIES_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE ALERT_POLICIES ADD CONSTRAINT ALERT_POLICIES_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE ANALYSIS_RUNS ADD CONSTRAINT ANALYSIS_RUNS_HEALTH_CHECK_ID_FKEY
  FOREIGN KEY (HEALTH_CHECK_ID) REFERENCES HEALTH_CHECKS (ID);
ALTER TABLE API_KEYS ADD CONSTRAINT API_KEYS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE APPROVAL_REQUESTS ADD CONSTRAINT APPROVAL_REQUESTS_APPROVED_BY_FKEY
  FOREIGN KEY (APPROVED_BY) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE APPROVAL_REQUESTS ADD CONSTRAINT APPROVAL_REQUESTS_APPROVER_ROLE_ID_FKEY
  FOREIGN KEY (APPROVER_ROLE_ID) REFERENCES ROLES (ID) ON DELETE CASCADE;
ALTER TABLE APPROVAL_REQUESTS ADD CONSTRAINT APPROVAL_REQUESTS_REQUESTER_ID_FKEY
  FOREIGN KEY (REQUESTER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE AUTO_REMEDIATION_LOG ADD CONSTRAINT AUTO_REMEDIATION_LOG_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE CHECK_FAILURE_BUNDLES ADD CONSTRAINT CHECK_FAILURE_BUNDLES_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE CHECK_FAILURE_BUNDLES ADD CONSTRAINT CHECK_FAILURE_BUNDLES_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE CHECK_RESULTS ADD CONSTRAINT CHECK_RESULTS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE CLONE_HISTORY ADD CONSTRAINT CLONE_HISTORY_RECIPE_ID_FKEY
  FOREIGN KEY (RECIPE_ID) REFERENCES CLONE_RECIPES (ID) ON DELETE SET NULL;
ALTER TABLE CLONE_HISTORY ADD CONSTRAINT CLONE_HISTORY_SOURCE_CONNECTION_ID_FKEY
  FOREIGN KEY (SOURCE_CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE CLONE_HISTORY ADD CONSTRAINT CLONE_HISTORY_STARTED_BY_FKEY
  FOREIGN KEY (STARTED_BY) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE CLONE_HISTORY ADD CONSTRAINT CLONE_HISTORY_TARGET_CONNECTION_ID_FKEY
  FOREIGN KEY (TARGET_CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE CLONE_RECIPES ADD CONSTRAINT CLONE_RECIPES_CREATED_BY_FKEY
  FOREIGN KEY (CREATED_BY) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE CLONE_RECIPES ADD CONSTRAINT CLONE_RECIPES_SOURCE_CONNECTION_ID_FKEY
  FOREIGN KEY (SOURCE_CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE CLONE_RECIPES ADD CONSTRAINT CLONE_RECIPES_TARGET_CONNECTION_ID_FKEY
  FOREIGN KEY (TARGET_CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE COMPLIANCE_REPORTS ADD CONSTRAINT COMPLIANCE_REPORTS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE CONNECTION_HEALTH_RUNS ADD CONSTRAINT CONNECTION_HEALTH_RUNS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE CONNECTION_OPTION_CONSENT ADD CONSTRAINT CONNECTION_OPTION_CONSENT_ACKNOWLEDGED_BY_FKEY
  FOREIGN KEY (ACKNOWLEDGED_BY) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE CONNECTION_OPTION_CONSENT ADD CONSTRAINT CONNECTION_OPTION_CONSENT_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE CONNECTION_SCHEDULES ADD CONSTRAINT CONNECTION_SCHEDULES_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE CONNECTION_SSH_PROFILES ADD CONSTRAINT CONNECTION_SSH_PROFILES_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE DEMO_RUNS ADD CONSTRAINT DEMO_RUNS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE EBS_ADOP_STATE ADD CONSTRAINT EBS_ADOP_STATE_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE EBS_CREDENTIALS ADD CONSTRAINT EBS_CREDENTIALS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE EBS_DEEP_REPORTS ADD CONSTRAINT EBS_DEEP_REPORTS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE EBS_DEEP_REPORTS ADD CONSTRAINT EBS_DEEP_REPORTS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE EBS_JOBS ADD CONSTRAINT EBS_JOBS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE EBS_SANITY_RUNS ADD CONSTRAINT EBS_SANITY_RUNS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE EMAIL_DRIP_STATE ADD CONSTRAINT EMAIL_DRIP_STATE_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE EMAIL_LOG ADD CONSTRAINT EMAIL_LOG_HC_ID_FKEY
  FOREIGN KEY (HC_ID) REFERENCES HEALTH_CHECKS (ID) ON DELETE SET NULL;
ALTER TABLE EMAIL_LOG ADD CONSTRAINT EMAIL_LOG_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE FINDING_HISTORY ADD CONSTRAINT FINDING_HISTORY_SCHEDULE_ID_FKEY
  FOREIGN KEY (SCHEDULE_ID) REFERENCES CONNECTION_SCHEDULES (ID) ON DELETE CASCADE;
ALTER TABLE FNDLOAD_HISTORY ADD CONSTRAINT FNDLOAD_HISTORY_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE HEALTH_CHECKS ADD CONSTRAINT HEALTH_CHECKS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID);
ALTER TABLE HEALTH_CHECKS ADD CONSTRAINT HEALTH_CHECKS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID);
ALTER TABLE INSTALL_JOBS ADD CONSTRAINT INSTALL_JOBS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE JOB_LOG_LINES ADD CONSTRAINT JOB_LOG_LINES_JOB_ID_FKEY
  FOREIGN KEY (JOB_ID) REFERENCES INSTALL_JOBS (ID) ON DELETE CASCADE;
ALTER TABLE LISTENER_PREFLIGHT_RUNS ADD CONSTRAINT LISTENER_PREFLIGHT_RUNS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE LISTENER_PREFLIGHT_RUNS ADD CONSTRAINT LISTENER_PREFLIGHT_RUNS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE MFA_ATTEMPTS ADD CONSTRAINT MFA_ATTEMPTS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE ORACLE_CONNECTIONS ADD CONSTRAINT ORACLE_CONNECTIONS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID);
ALTER TABLE OUTREACH_BATCHES ADD CONSTRAINT OUTREACH_BATCHES_APPROVED_BY_FKEY
  FOREIGN KEY (APPROVED_BY) REFERENCES USERS (ID);
ALTER TABLE OUTREACH_RECIPIENTS ADD CONSTRAINT OUTREACH_RECIPIENTS_BATCH_ID_FKEY
  FOREIGN KEY (BATCH_ID) REFERENCES OUTREACH_BATCHES (ID) ON DELETE CASCADE;
ALTER TABLE PAYMENTS ADD CONSTRAINT PAYMENTS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE PROXY_EXEC_AUDIT ADD CONSTRAINT PROXY_EXEC_AUDIT_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE PROXY_EXEC_AUDIT ADD CONSTRAINT PROXY_EXEC_AUDIT_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE RBAC_AUDIT_LOG ADD CONSTRAINT RBAC_AUDIT_LOG_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE ROLES ADD CONSTRAINT ROLES_APPROVAL_REQUIRED_FROM_FKEY
  FOREIGN KEY (APPROVAL_REQUIRED_FROM) REFERENCES ROLES (ID) ON DELETE SET NULL;
ALTER TABLE ROLES ADD CONSTRAINT ROLES_TEAM_ID_FKEY
  FOREIGN KEY (TEAM_ID) REFERENCES TEAMS (ID) ON DELETE CASCADE;
ALTER TABLE SELF_HOSTED_LICENSES ADD CONSTRAINT SELF_HOSTED_LICENSES_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID);
ALTER TABLE SERVICE_HEARTBEAT_STATE ADD CONSTRAINT SERVICE_HEARTBEAT_STATE_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE SMOKE_TEST_RUNS ADD CONSTRAINT SMOKE_TEST_RUNS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE SMOKE_TEST_RUNS ADD CONSTRAINT SMOKE_TEST_RUNS_TRIGGERED_BY_USER_ID_FKEY
  FOREIGN KEY (TRIGGERED_BY_USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE SQL_AUDIT_LOG ADD CONSTRAINT SQL_AUDIT_LOG_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE SQL_TUNING_FINDINGS ADD CONSTRAINT SQL_TUNING_FINDINGS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE SSH_AUDIT ADD CONSTRAINT SSH_AUDIT_TARGET_ID_FKEY
  FOREIGN KEY (TARGET_ID) REFERENCES SSH_TARGETS (ID) ON DELETE CASCADE;
ALTER TABLE SSH_INSTALL_CREDENTIALS ADD CONSTRAINT SSH_INSTALL_CREDENTIALS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE SSH_INSTALL_CREDENTIALS ADD CONSTRAINT SSH_INSTALL_CREDENTIALS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE SSH_TARGETS ADD CONSTRAINT SSH_TARGETS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE SSH_TARGETS ADD CONSTRAINT SSH_TARGETS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE SUBSCRIPTIONS ADD CONSTRAINT SUBSCRIPTIONS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE TEAM_INVITES ADD CONSTRAINT TEAM_INVITES_INVITED_BY_FKEY
  FOREIGN KEY (INVITED_BY) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE TEAM_INVITES ADD CONSTRAINT TEAM_INVITES_TEAM_ID_FKEY
  FOREIGN KEY (TEAM_ID) REFERENCES TEAMS (ID) ON DELETE CASCADE;
ALTER TABLE TEAM_MEMBERS ADD CONSTRAINT TEAM_MEMBERS_ROLE_ID_FKEY
  FOREIGN KEY (ROLE_ID) REFERENCES ROLES (ID) ON DELETE SET NULL;
ALTER TABLE TEAM_MEMBERS ADD CONSTRAINT TEAM_MEMBERS_TEAM_ID_FKEY
  FOREIGN KEY (TEAM_ID) REFERENCES TEAMS (ID) ON DELETE CASCADE;
ALTER TABLE TEAM_MEMBERS ADD CONSTRAINT TEAM_MEMBERS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE TEAMS ADD CONSTRAINT TEAMS_OWNER_ID_FKEY
  FOREIGN KEY (OWNER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE TNS_TOPOLOGY_SNAPSHOTS ADD CONSTRAINT TNS_TOPOLOGY_SNAPSHOTS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE TUNEOPS_NOTIFICATION_MUTES ADD CONSTRAINT TUNEOPS_NOTIFICATION_MUTES_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE TUNEOPS_NOTIFICATION_PREFS ADD CONSTRAINT TUNEOPS_NOTIFICATION_PREFS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE TUNEOPS_TICKETS ADD CONSTRAINT TUNEOPS_TICKETS_APPROVED_BY_FKEY
  FOREIGN KEY (APPROVED_BY) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE TUNEOPS_TICKETS ADD CONSTRAINT TUNEOPS_TICKETS_ASSIGNED_TO_FKEY
  FOREIGN KEY (ASSIGNED_TO) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE TUNEOPS_TICKETS ADD CONSTRAINT TUNEOPS_TICKETS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE SET NULL;
ALTER TABLE TUNEOPS_TICKETS ADD CONSTRAINT TUNEOPS_TICKETS_EXECUTED_BY_FKEY
  FOREIGN KEY (EXECUTED_BY) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE TUNEOPS_TICKETS ADD CONSTRAINT TUNEOPS_TICKETS_RESOLVED_BY_FKEY
  FOREIGN KEY (RESOLVED_BY) REFERENCES USERS (ID) ON DELETE SET NULL;
ALTER TABLE USER_CREDITS ADD CONSTRAINT USER_CREDITS_SUBSCRIPTION_ID_FKEY
  FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES SUBSCRIPTIONS (ID) ON DELETE SET NULL;
ALTER TABLE USER_CREDITS ADD CONSTRAINT USER_CREDITS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE USER_MFA ADD CONSTRAINT USER_MFA_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE USER_PREFERENCES ADD CONSTRAINT USER_PREFERENCES_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE CASCADE;
ALTER TABLE USERS ADD CONSTRAINT USERS_TEAM_ID_FKEY
  FOREIGN KEY (TEAM_ID) REFERENCES TEAMS (ID) ON DELETE SET NULL;
ALTER TABLE VALIDATION_RUNS ADD CONSTRAINT VALIDATION_RUNS_CONNECTION_ID_FKEY
  FOREIGN KEY (CONNECTION_ID) REFERENCES ORACLE_CONNECTIONS (ID) ON DELETE CASCADE;
ALTER TABLE VALIDATION_RUNS ADD CONSTRAINT VALIDATION_RUNS_USER_ID_FKEY
  FOREIGN KEY (USER_ID) REFERENCES USERS (ID) ON DELETE SET NULL;
