-- Indexes. Partial indexes become function-based CASE indexes,
-- which is the Oracle equivalent (an all-NULL key is not stored).

CREATE INDEX ACTIVITY_LOG_ACTION_TYPE_IDX ON ACTIVITY_LOG (ACTION_TYPE, CREATED_AT DESC);
-- partial: WHERE (company_domain IS NOT NULL)
CREATE INDEX ACTIVITY_LOG_COMPANY_DOMAIN_IDX ON ACTIVITY_LOG (CASE WHEN COMPANY_DOMAIN IS NOT NULL THEN COMPANY_DOMAIN END, CASE WHEN COMPANY_DOMAIN IS NOT NULL THEN CREATED_AT END);
-- partial: WHERE (connection_id IS NOT NULL)
CREATE INDEX ACTIVITY_LOG_CONNECTION_ID_IDX ON ACTIVITY_LOG (CASE WHEN CONNECTION_ID IS NOT NULL THEN CONNECTION_ID END, CASE WHEN CONNECTION_ID IS NOT NULL THEN CREATED_AT END);
CREATE INDEX ACTIVITY_LOG_CREATED_AT_IDX ON ACTIVITY_LOG (CREATED_AT DESC);
CREATE INDEX ACTIVITY_LOG_RESULT_IDX ON ACTIVITY_LOG (RESULT, CREATED_AT DESC);
-- partial: WHERE (user_id IS NOT NULL)
CREATE INDEX ACTIVITY_LOG_USER_ID_IDX ON ACTIVITY_LOG (CASE WHEN USER_ID IS NOT NULL THEN USER_ID END, CASE WHEN USER_ID IS NOT NULL THEN CREATED_AT END);
CREATE INDEX ADDM_RUNS_CONNECTION_CREATED ON ADDM_RUNS (CONNECTION_ID, CREATED_AT DESC);
CREATE INDEX ADDM_RUNS_CREATED_AT ON ADDM_RUNS (CREATED_AT DESC);
CREATE INDEX IDX_ADMIN_EXPORTS_STARTED_AT ON ADMIN_EXPORTS (STARTED_AT DESC);
CREATE UNIQUE INDEX ADVISOR_FINDINGS_CONNECTION_UNIQUE ON ADVISOR_FINDINGS (CONNECTION_ID);
CREATE INDEX ADVISOR_FINDINGS_FETCHED_AT ON ADVISOR_FINDINGS (FETCHED_AT DESC);
CREATE INDEX IDX_AGENT_CHANNEL_STATE_CLAIM_EXPIRES ON AGENT_CHANNEL_STATE (AGENT_ID, CLAIM_EXPIRES_AT);
-- partial: WHERE (status = 'claimed'::text)
CREATE INDEX IDX_AGENT_COMMAND_QUEUE_EXPIRED_CLAIMS ON AGENT_COMMAND_QUEUE (CASE WHEN STATUS = 'claimed' THEN STATUS END, CASE WHEN STATUS = 'claimed' THEN CLAIM_EXPIRES_AT END);
CREATE INDEX IDX_AGENT_COMMAND_QUEUE_LOOKUP ON AGENT_COMMAND_QUEUE (AGENT_ID, STATUS, ENQUEUED_AT);
CREATE INDEX IDX_AGENT_CMD_RESULTS_CONN ON AGENT_COMMAND_RESULTS (CONNECTION_ID, REQUESTED_AT DESC);
CREATE INDEX IDX_AGENT_DIAGNOSE_RUNS_CONN_CREATED ON AGENT_DIAGNOSE_RUNS (CONNECTION_ID, CREATED_AT DESC);
CREATE INDEX IDX_AGENT_INSTALL_FAILURES_CONN ON AGENT_INSTALL_FAILURES (CONNECTION_ID, CREATED_AT DESC);
CREATE INDEX IDX_AGENT_INSTALL_FAILURES_CREATED ON AGENT_INSTALL_FAILURES (CREATED_AT DESC);
-- partial: WHERE (resolved_at IS NULL)
CREATE INDEX IDX_AGENT_INSTALL_FAILURES_RESOLVED ON AGENT_INSTALL_FAILURES (CASE WHEN RESOLVED_AT IS NULL THEN RESOLVED_AT END);
CREATE INDEX AGENT_REG_TOKENS_EXPIRES ON AGENT_REG_TOKENS (EXPIRES_AT);
CREATE INDEX IDX_AGENT_RESTART_EVENTS_CONN_TIME ON AGENT_RESTART_EVENTS (CONNECTION_ID, RECORDED_AT DESC);
CREATE UNIQUE INDEX AGENT_TUNNELS_CONNECTION_UNIQUE ON AGENT_TUNNELS (CONNECTION_ID);
CREATE INDEX IDX_AGENT_TUNNELS_AGENT_STATUS ON AGENT_TUNNELS (AGENT_STATUS);
-- partial: WHERE (status = 'uninstalled'::text)
CREATE INDEX IDX_AGENT_TUNNELS_UNINSTALLED ON AGENT_TUNNELS (CASE WHEN STATUS = 'uninstalled' THEN STATUS END, CASE WHEN STATUS = 'uninstalled' THEN UNINSTALLED_AT END);
-- partial: WHERE (verified_at IS NOT NULL)
CREATE INDEX IDX_AGENT_UPGRADE_AUDIT_CONNECTION_VERIFIED ON AGENT_UPGRADE_AUDIT (CASE WHEN VERIFIED_AT IS NOT NULL THEN CONNECTION_ID END, CASE WHEN VERIFIED_AT IS NOT NULL THEN VERIFIED_AT END);
CREATE INDEX IDX_UPGRADE_AUDIT_CONNECTION_ID ON AGENT_UPGRADE_AUDIT (CONNECTION_ID, TRIGGERED_AT DESC);
-- partial: WHERE (status = 'failed'::text)
CREATE INDEX IDX_UPGRADE_AUDIT_FAILURES ON AGENT_UPGRADE_AUDIT (CASE WHEN STATUS = 'failed' THEN CONNECTION_ID END, CASE WHEN STATUS = 'failed' THEN TRIGGERED_AT END);
-- idx_agents_log_buffer_conn: omitted; Oracle's agents_log_buffer_connection_id_key index already covers (CONNECTION_ID)
CREATE INDEX IDX_ALERT_EVENTS_CONNECTION_ID ON ALERT_EVENTS (CONNECTION_ID, STATUS);
-- partial: WHERE (status = ANY (ARRAY['triggered'::text, 'escalated'::text]))
CREATE INDEX IDX_ALERT_EVENTS_OPEN ON ALERT_EVENTS (CASE WHEN STATUS IN ('triggered', 'escalated') THEN STATUS END, CASE WHEN STATUS IN ('triggered', 'escalated') THEN NEXT_ESCALATION_AT END);
CREATE INDEX IDX_ALERT_EVENTS_POLICY_ID ON ALERT_EVENTS (POLICY_ID, STATUS);
CREATE INDEX IDX_ALERT_POLICIES_CONNECTION_ID ON ALERT_POLICIES (CONNECTION_ID);
CREATE INDEX IDX_ALERT_POLICIES_USER_ID ON ALERT_POLICIES (USER_ID, IS_ACTIVE);
CREATE INDEX ANALYSIS_RUNS_HC_IDX ON ANALYSIS_RUNS (HEALTH_CHECK_ID);
CREATE INDEX ANALYTICS_EVENTS_EVENT_NAME_IDX ON ANALYTICS_EVENTS (EVENT_NAME, OCCURRED_AT DESC);
-- partial: WHERE (ip IS NOT NULL)
CREATE INDEX ANALYTICS_EVENTS_IP_IDX ON ANALYTICS_EVENTS (CASE WHEN IP IS NOT NULL THEN IP END, CASE WHEN IP IS NOT NULL THEN OCCURRED_AT END);
-- partial: WHERE (session_id IS NOT NULL)
CREATE INDEX ANALYTICS_EVENTS_SESSION_IDX ON ANALYTICS_EVENTS (CASE WHEN SESSION_ID IS NOT NULL THEN SESSION_ID END, CASE WHEN SESSION_ID IS NOT NULL THEN OCCURRED_AT END);
-- partial: WHERE (user_id IS NOT NULL)
CREATE INDEX ANALYTICS_EVENTS_USER_ID_IDX ON ANALYTICS_EVENTS (CASE WHEN USER_ID IS NOT NULL THEN USER_ID END, CASE WHEN USER_ID IS NOT NULL THEN OCCURRED_AT END);
CREATE INDEX API_KEYS_KEY_PREFIX_IDX ON API_KEYS (KEY_PREFIX);
CREATE INDEX API_KEYS_USER_ID_IDX ON API_KEYS (USER_ID);
CREATE INDEX IDX_APPROVAL_REQUESTS_REQUESTER ON APPROVAL_REQUESTS (REQUESTER_ID);
CREATE INDEX IDX_APPROVAL_REQUESTS_ROLE ON APPROVAL_REQUESTS (APPROVER_ROLE_ID);
-- partial: WHERE ((status)::text = 'pending'::text)
CREATE INDEX IDX_APPROVAL_REQUESTS_STATUS ON APPROVAL_REQUESTS (CASE WHEN STATUS= 'pending' THEN STATUS END);
CREATE INDEX IDX_AUDIT_LOG_OCCURRED_AT ON AUDIT_LOG (OCCURRED_AT DESC);
CREATE INDEX IDX_AUDIT_LOG_SLUG ON AUDIT_LOG (SLUG);
CREATE INDEX IDX_AUTO_REMEDIATION_CONN ON AUTO_REMEDIATION_LOG (CONNECTION_ID, EXECUTED_AT DESC);
CREATE INDEX IDX_BLOG_POSTS_PUBLISHED_AT ON BLOG_POSTS (PUBLISHED_AT);
-- idx_blog_posts_slug: omitted; Oracle's blog_posts_slug_key index already covers (SLUG)
CREATE INDEX IDX_CFB_CONNECTION_CREATED ON CHECK_FAILURE_BUNDLES (CONNECTION_ID, CREATED_AT DESC);
CREATE INDEX IDX_CFB_CREATED_AT ON CHECK_FAILURE_BUNDLES (CREATED_AT DESC);
CREATE INDEX IDX_CHECK_RESULTS_CONN_CHECK_TIME ON CHECK_RESULTS (CONNECTION_ID, CHECK_ID, EXECUTED_AT DESC);
CREATE INDEX IDX_CHECK_RESULTS_RUN ON CHECK_RESULTS (RUN_ID);
-- partial: WHERE (status = ANY (ARRAY['amber'::text, 'red'::text]))
CREATE INDEX IDX_CHECK_RESULTS_STATUS_TIME ON CHECK_RESULTS (CASE WHEN STATUS IN ('amber', 'red') THEN CONNECTION_ID END, CASE WHEN STATUS IN ('amber', 'red') THEN STATUS END, CASE WHEN STATUS IN ('amber', 'red') THEN EXECUTED_AT END);
CREATE INDEX IDX_CHECKS_CATALOGUE_CATEGORY ON CHECKS_CATALOGUE (CATEGORY);
CREATE INDEX IDX_CHECKS_CATALOGUE_STATUS ON CHECKS_CATALOGUE (STATUS);
-- partial: WHERE (company_id IS NOT NULL)
CREATE INDEX IDX_CLONE_HISTORY_COMPANY ON CLONE_HISTORY (CASE WHEN COMPANY_ID IS NOT NULL THEN COMPANY_ID END);
CREATE INDEX IDX_CLONE_HISTORY_RECIPE ON CLONE_HISTORY (RECIPE_ID);
-- partial: WHERE (company_id IS NOT NULL)
CREATE INDEX IDX_CLONE_RECIPES_COMPANY ON CLONE_RECIPES (CASE WHEN COMPANY_ID IS NOT NULL THEN COMPANY_ID END);
CREATE INDEX IDX_CLONE_RECIPES_SOURCE ON CLONE_RECIPES (SOURCE_CONNECTION_ID);
CREATE INDEX IDX_CLONE_RECIPES_TARGET ON CLONE_RECIPES (TARGET_CONNECTION_ID);
CREATE INDEX IDX_COMPLIANCE_REPORTS_COMPANY_DOMAIN ON COMPLIANCE_REPORTS (COMPANY_DOMAIN, GENERATED_AT DESC);
CREATE INDEX IDX_COMPLIANCE_REPORTS_USER_ID ON COMPLIANCE_REPORTS (USER_ID, GENERATED_AT DESC);
CREATE INDEX IDX_CHR_CONNECTION_RAN ON CONNECTION_HEALTH_RUNS (CONNECTION_ID, RAN_AT DESC);
-- partial: WHERE (enabled = true)
CREATE INDEX IDX_SCHEDULES_DUE ON CONNECTION_SCHEDULES (CASE WHEN ENABLED = true THEN NEXT_RUN_AT END);
CREATE UNIQUE INDEX IDX_SSH_PROFILES_CONN_ROLE ON CONNECTION_SSH_PROFILES (CONNECTION_ID, ROLE);
CREATE INDEX IDX_SSH_PROFILES_CONNECTION ON CONNECTION_SSH_PROFILES (CONNECTION_ID);
CREATE INDEX CREDENTIAL_ACCESS_LOG_ACCESSED_AT_IDX ON CREDENTIAL_ACCESS_LOG (ACCESSED_AT DESC);
CREATE INDEX CREDENTIAL_ACCESS_LOG_CONNECTION_ID_IDX ON CREDENTIAL_ACCESS_LOG (CONNECTION_ID);
-- partial: WHERE (patching = true)
CREATE INDEX IDX_EBS_ADOP_STATE_PATCHING ON EBS_ADOP_STATE (CASE WHEN PATCHING = true THEN PATCHING END);
CREATE INDEX EBS_CREDENTIALS_CONNECTION_ID_IDX ON EBS_CREDENTIALS (CONNECTION_ID);
CREATE INDEX IDX_EBS_DEEP_REPORTS_CONNECTION_ID ON EBS_DEEP_REPORTS (CONNECTION_ID);
CREATE INDEX IDX_EBS_DEEP_REPORTS_CREATED_AT ON EBS_DEEP_REPORTS (CREATED_AT DESC);
CREATE INDEX IDX_EBS_DEEP_REPORTS_USER_ID ON EBS_DEEP_REPORTS (USER_ID);
CREATE INDEX EBS_JOBS_CONN_STATUS ON EBS_JOBS (CONNECTION_ID, STATUS);
CREATE INDEX IDX_EBS_MODULE_RUNS_CONN_AT ON EBS_MODULE_RUNS (CONNECTION_ID, RUN_AT DESC);
CREATE INDEX IDX_EBS_SANITY_RUNS_CONNECTION_ID ON EBS_SANITY_RUNS (CONNECTION_ID);
CREATE INDEX IDX_EBS_SANITY_RUNS_RUN_AT ON EBS_SANITY_RUNS (RUN_AT DESC);
CREATE INDEX IDX_EBS_VALIDATION_RUNS_RUN_AT ON EBS_VALIDATION_RUNS (RUN_AT DESC);
CREATE INDEX IDX_EMAIL_DRIP_STATE_STEP ON EMAIL_DRIP_STATE (SEQUENCE_STEP);
CREATE INDEX IDX_EMAIL_DRIP_STATE_USER_ID ON EMAIL_DRIP_STATE (USER_ID);
CREATE INDEX IDX_EMAIL_LOG_HC_ID ON EMAIL_LOG (HC_ID);
CREATE INDEX IDX_EMAIL_LOG_SENT_AT ON EMAIL_LOG (SENT_AT DESC);
CREATE INDEX IDX_EMAIL_LOG_TEMPLATE ON EMAIL_LOG (TEMPLATE);
CREATE INDEX IDX_EMAIL_LOG_USER_ID ON EMAIL_LOG (USER_ID);
CREATE INDEX IDX_FINDING_HISTORY_CONNECTION ON FINDING_HISTORY (CONNECTION_ID);
CREATE INDEX IDX_FINDING_HISTORY_FIRST_SEEN_AT ON FINDING_HISTORY (FIRST_SEEN_AT);
-- partial: WHERE (resolved_at IS NOT NULL)
CREATE INDEX IDX_FINDING_HISTORY_RESOLVED_AT ON FINDING_HISTORY (CASE WHEN RESOLVED_AT IS NOT NULL THEN RESOLVED_AT END);
CREATE INDEX IDX_FNDLOAD_HISTORY_ACTION ON FNDLOAD_HISTORY (ACTION);
CREATE INDEX IDX_FNDLOAD_HISTORY_EXECUTED_AT ON FNDLOAD_HISTORY (EXECUTED_AT DESC);
CREATE INDEX IDX_FNDLOAD_HISTORY_SOURCE_CONN ON FNDLOAD_HISTORY (SOURCE_CONN_ID);
CREATE INDEX IDX_FNDLOAD_HISTORY_TARGET_CONN ON FNDLOAD_HISTORY (TARGET_CONN_ID);
CREATE INDEX IDX_FNDLOAD_HISTORY_USER_ID ON FNDLOAD_HISTORY (USER_ID);
CREATE INDEX HEALTH_CHECK_REQUESTS_CREATED_AT_IDX ON HEALTH_CHECK_REQUESTS (CREATED_AT DESC);
CREATE INDEX HEALTH_CHECK_REQUESTS_STATUS_IDX ON HEALTH_CHECK_REQUESTS (STATUS);
CREATE INDEX HEALTH_CHECKS_CREATED_AT_IDX ON HEALTH_CHECKS (CREATED_AT DESC);
CREATE INDEX HEALTH_CHECKS_STATUS_IDX ON HEALTH_CHECKS (STATUS);
CREATE INDEX IDX_INSTALL_JOBS_CONN_ID ON INSTALL_JOBS (CONNECTION_ID);
CREATE INDEX IDX_INSTALL_JOBS_CREATED ON INSTALL_JOBS (CREATED_AT DESC);
CREATE INDEX IDX_INSTALL_JOBS_STATUS ON INSTALL_JOBS (STATUS);
CREATE INDEX IDX_INSTALL_JOBS_USER_ID ON INSTALL_JOBS (USER_ID);
CREATE INDEX IDX_INSTALLER_SMOKE_RUNS_RUN_ID ON INSTALLER_SMOKE_RUNS (RUN_ID);
CREATE INDEX IDX_INSTALLER_SMOKE_RUNS_STARTED_AT ON INSTALLER_SMOKE_RUNS (STARTED_AT DESC);
-- partial: WHERE (used_at IS NULL)
CREATE INDEX IDX_INSTALLER_SMOKE_TOKENS_TOKEN ON INSTALLER_SMOKE_TOKENS (CASE WHEN USED_AT IS NULL THEN TOKEN END);
CREATE INDEX IDX_INSTALLER_RUNS_OS_STARTED ON INSTALLER_VALIDATION_RUNS (OS, STARTED_AT DESC);
CREATE INDEX IDX_INSTALLER_RUNS_OVERALL ON INSTALLER_VALIDATION_RUNS (OVERALL, STARTED_AT DESC);
CREATE INDEX IDX_INSTALLER_RUNS_RUN_ID ON INSTALLER_VALIDATION_RUNS (RUN_ID);
-- partial: WHERE (topology IS NOT NULL)
CREATE INDEX IDX_INSTALLER_RUNS_TOPOLOGY_STARTED ON INSTALLER_VALIDATION_RUNS (CASE WHEN TOPOLOGY IS NOT NULL THEN TOPOLOGY END, CASE WHEN TOPOLOGY IS NOT NULL THEN STARTED_AT END);
CREATE INDEX IDX_JOB_LOG_LINES_JOB_SEQ ON JOB_LOG_LINES (JOB_ID, SEQ);
CREATE INDEX IDX_PREFLIGHT_RUNS_CONN_CREATED ON LISTENER_PREFLIGHT_RUNS (CONNECTION_ID, CREATED_AT);
CREATE INDEX IDX_PREFLIGHT_RUNS_USER ON LISTENER_PREFLIGHT_RUNS (USER_ID);
CREATE INDEX MAGIC_LINK_TOKENS_EMAIL_IDX ON MAGIC_LINK_TOKENS (EMAIL);
-- magic_link_tokens_token_idx: omitted; Oracle's magic_link_tokens_token_key index already covers (TOKEN)
CREATE INDEX IDX_MFA_ATTEMPTS_USER_ID_TIME ON MFA_ATTEMPTS (USER_ID, ATTEMPTED_AT DESC);
CREATE INDEX OPTION_CONSENT_LOG_CONN_OPTION ON OPTION_CONSENT_LOG (CONNECTION_ID, OPTION_KEY, CREATED_AT DESC);
-- partial: WHERE (key_rotation_status <> 'idle'::text)
CREATE INDEX IDX_CONNECTIONS_KEY_ROTATION_STATUS ON ORACLE_CONNECTIONS (CASE WHEN KEY_ROTATION_STATUS <> 'idle' THEN KEY_ROTATION_STATUS END);
-- partial: WHERE (schedule_enabled = true)
CREATE INDEX IDX_CONNECTIONS_SCHEDULE_DUE ON ORACLE_CONNECTIONS (CASE WHEN SCHEDULE_ENABLED = true THEN NEXT_SCHEDULED_RUN_AT END);
-- partial: WHERE (ebs_instance_name IS NOT NULL)
CREATE INDEX IDX_OC_EBS_INSTANCE_NAME ON ORACLE_CONNECTIONS (CASE WHEN EBS_INSTANCE_NAME IS NOT NULL THEN EBS_INSTANCE_NAME END);
-- partial: WHERE (first_run_completed_at IS NULL)
CREATE INDEX IDX_ORACLE_CONNECTIONS_FIRST_RUN ON ORACLE_CONNECTIONS (CASE WHEN FIRST_RUN_COMPLETED_AT IS NULL THEN FIRST_RUN_COMPLETED_AT END);
-- partial: WHERE ((install_token_issued_at IS NOT NULL) AND (first_heartbeat_at IS NULL))
CREATE INDEX IDX_ORACLE_CONNECTIONS_INSTALL_STALLED ON ORACLE_CONNECTIONS (CASE WHEN (INSTALL_TOKEN_ISSUED_AT IS NOT NULL) AND (FIRST_HEARTBEAT_AT IS NULL) THEN INSTALL_TOKEN_ISSUED_AT END);
-- partial: WHERE (status = 'pending_registration'::text)
CREATE INDEX IDX_ORACLE_CONNECTIONS_STATUS ON ORACLE_CONNECTIONS (CASE WHEN STATUS = 'pending_registration' THEN STATUS END);
CREATE INDEX ORACLE_CONNECTIONS_CREATED_AT_IDX ON ORACLE_CONNECTIONS (CREATED_AT DESC);
CREATE UNIQUE INDEX ORACLE_DOC_CHUNKS_DOC_CHUNK_UIDX ON ORACLE_DOC_CHUNKS (DOC_NAME, CHUNK_INDEX);
-- pgvector IVFFLAT -> Oracle 26ai vector index
CREATE VECTOR INDEX ORACLE_DOC_CHUNKS_EMBEDDING_IDX ON ORACLE_DOC_CHUNKS (EMBEDDING)
  ORGANIZATION NEIGHBOR PARTITIONS DISTANCE COSINE WITH TARGET ACCURACY 95;
CREATE INDEX IDX_OUTREACH_ATTEMPTS_AT ON OUTREACH_ATTEMPTS (ATTEMPTED_AT DESC);
CREATE INDEX OUTREACH_SEND_LOG_ATTEMPTED_AT_IDX ON OUTREACH_SEND_LOG (ATTEMPTED_AT DESC);
CREATE INDEX OUTREACH_SEND_LOG_BATCH_ID_IDX ON OUTREACH_SEND_LOG (BATCH_ID);
CREATE INDEX IDX_PAGE_EVENTS_NAME_CREATED ON PAGE_EVENTS (EVENT_NAME, CREATED_AT);
CREATE INDEX IDX_PAGE_EVENTS_TYPE_CREATED ON PAGE_EVENTS (EVENT_TYPE, CREATED_AT);
CREATE INDEX PMTR_RAN_AT_IDX ON PAYMENT_METHOD_TEST_RUNS (RAN_AT DESC);
CREATE INDEX IDX_PAYMENT_RECONCILIATION_OCCURRED_AT ON PAYMENT_RECONCILIATION (OCCURRED_AT DESC);
CREATE INDEX IDX_PAYMENT_RECONCILIATION_USER_ID ON PAYMENT_RECONCILIATION (USER_ID);
CREATE INDEX PAYMENT_TEST_RUNS_RAN_AT_IDX ON PAYMENT_TEST_RUNS (RAN_AT);
-- idx_payments_razorpay_order_id: omitted; Oracle's payments_razorpay_order_id_key index already covers (RAZORPAY_ORDER_ID)
CREATE INDEX IDX_PAYMENTS_RAZORPAY_PAYMENT_ID ON PAYMENTS (RAZORPAY_PAYMENT_ID);
CREATE INDEX IDX_PAYMENTS_STATUS ON PAYMENTS (STATUS);
CREATE INDEX IDX_PAYMENTS_USER_ID ON PAYMENTS (USER_ID);
CREATE INDEX PROXY_EXEC_AUDIT_CONN_IDX ON PROXY_EXEC_AUDIT (CONNECTION_ID, EXECUTED_AT DESC);
CREATE INDEX PROXY_EXEC_AUDIT_USER_IDX ON PROXY_EXEC_AUDIT (USER_ID, EXECUTED_AT DESC);
CREATE INDEX RBAC_AUDIT_LOG_DENIED_AT_IDX ON RBAC_AUDIT_LOG (DENIED_AT DESC);
CREATE INDEX RBAC_AUDIT_LOG_USER_ID_IDX ON RBAC_AUDIT_LOG (USER_ID);
CREATE INDEX ROADMAP_REMINDERS_DISMISSED_AT_IDX ON ROADMAP_REMINDERS (DISMISSED_AT);
CREATE INDEX IDX_ROLES_TEAM_ID ON ROLES (TEAM_ID);
CREATE INDEX IDX_SAMPLE_REPORT_LEADS_EMAIL ON SAMPLE_REPORT_LEADS (EMAIL);
CREATE INDEX SELF_HOSTED_DOWNLOAD_LEADS_CREATED_AT ON SELF_HOSTED_DOWNLOAD_LEADS (CREATED_AT DESC);
-- idx_licenses_key: omitted; Oracle's self_hosted_licenses_license_key_key index already covers (LICENSE_KEY)
CREATE INDEX IDX_LICENSES_USER ON SELF_HOSTED_LICENSES (USER_ID);
-- partial: WHERE (((plan_tier)::text = 'free'::text) AND ((status)::text = 'active'::text) AND (user_id IS NOT NULL))
CREATE UNIQUE INDEX SELF_HOSTED_LICENSES_ONE_FREE_PER_USER ON SELF_HOSTED_LICENSES (CASE WHEN (PLAN_TIER= 'free') AND (STATUS= 'active') AND (USER_ID IS NOT NULL) THEN USER_ID END);
CREATE INDEX IDX_HEARTBEAT_CONN ON SERVICE_HEARTBEAT_STATE (CONNECTION_ID);
CREATE INDEX IDX_SMOKE_TEST_RUNS_CONNECTION ON SMOKE_TEST_RUNS (CONNECTION_ID, STARTED_AT DESC);
CREATE INDEX IDX_SQL_AUDIT_LOG_ALLOWED ON SQL_AUDIT_LOG (ALLOWED);
CREATE INDEX IDX_SQL_AUDIT_LOG_CONNECTION_ID ON SQL_AUDIT_LOG (CONNECTION_ID);
CREATE INDEX IDX_SQL_AUDIT_LOG_EXECUTED_AT ON SQL_AUDIT_LOG (EXECUTED_AT);
CREATE INDEX IDX_SQL_AUDIT_LOG_USER_ID ON SQL_AUDIT_LOG (USER_ID);
CREATE INDEX IDX_SQL_CONSOLE_HISTORY_EXECUTED_AT ON SQL_CONSOLE_HISTORY (EXECUTED_AT);
CREATE INDEX IDX_SQL_CONSOLE_HISTORY_USER_CONN ON SQL_CONSOLE_HISTORY (USER_ID, CONNECTION_ID, EXECUTED_AT DESC);
CREATE INDEX IDX_SQL_FIX_CACHE_EXPIRES ON SQL_FIX_CACHE (EXPIRES_AT);
CREATE UNIQUE INDEX IDX_SQL_FIX_CACHE_KEY ON SQL_FIX_CACHE (SQL_ID, PLAN_HASH_VALUE);
CREATE INDEX IDX_SQL_TUNING_CONNECTION_CREATED ON SQL_TUNING_FINDINGS (CONNECTION_ID, CREATED_AT DESC);
CREATE INDEX IDX_SQL_TUNING_CONNECTION_SQL ON SQL_TUNING_FINDINGS (CONNECTION_ID, SQL_ID);
CREATE INDEX IDX_SSH_AUDIT_TARGET ON SSH_AUDIT (TARGET_ID);
CREATE INDEX IDX_SSH_AUDIT_TS ON SSH_AUDIT (TS DESC);
-- idx_ssh_install_creds_conn: omitted; Oracle's ssh_install_credentials_connection_id_key index already covers (CONNECTION_ID)
CREATE INDEX IDX_SSH_INSTALL_CREDS_USER ON SSH_INSTALL_CREDENTIALS (USER_ID);
CREATE INDEX IDX_SSH_TARGETS_CONNECTION ON SSH_TARGETS (CONNECTION_ID);
CREATE INDEX IDX_SSH_TARGETS_USER ON SSH_TARGETS (USER_ID);
-- idx_sso_configs_domain: omitted; Oracle's sso_configs_company_domain_key index already covers (COMPANY_DOMAIN)
CREATE INDEX IDX_SSO_LOGIN_LOG_DOMAIN_TIME ON SSO_LOGIN_LOG (COMPANY_DOMAIN, ATTEMPTED_AT DESC);
-- idx_subscriptions_razorpay_id: omitted; Oracle's subscriptions_razorpay_subscription_id_key index already covers (RAZORPAY_SUBSCRIPTION_ID)
CREATE INDEX IDX_SUBSCRIPTIONS_STATUS ON SUBSCRIPTIONS (STATUS);
CREATE INDEX IDX_SUBSCRIPTIONS_USER_ID ON SUBSCRIPTIONS (USER_ID);
CREATE INDEX IDX_TEAM_INVITES_EMAIL ON TEAM_INVITES (EMAIL);
CREATE INDEX IDX_TEAM_INVITES_TEAM_ID ON TEAM_INVITES (TEAM_ID);
-- idx_team_invites_token: omitted; Oracle's team_invites_token_key index already covers (TOKEN)
CREATE INDEX IDX_TEAM_MEMBERS_TEAM_ID ON TEAM_MEMBERS (TEAM_ID);
CREATE INDEX IDX_TEAM_MEMBERS_USER_ID ON TEAM_MEMBERS (USER_ID);
CREATE INDEX IDX_TNS_TOPOLOGY_SNAPSHOTS_CONN_CREATED ON TNS_TOPOLOGY_SNAPSHOTS (CONNECTION_ID, CREATED_AT);
-- partial: WHERE (share_token IS NOT NULL)
CREATE INDEX IDX_TNS_TOPOLOGY_SNAPSHOTS_SHARE_TOKEN ON TNS_TOPOLOGY_SNAPSHOTS (CASE WHEN SHARE_TOKEN IS NOT NULL THEN SHARE_TOKEN END);
CREATE INDEX IDX_TUNEOPS_NOTIF_LOG_DEDUP ON TUNEOPS_NOTIFICATION_LOG (TICKET_NUMBER, EVENT_TYPE, RECIPIENT_EMAIL, SENT_AT);
CREATE INDEX IDX_TUNEOPS_NOTIF_LOG_TICKET ON TUNEOPS_NOTIFICATION_LOG (TICKET_NUMBER, SENT_AT);
CREATE INDEX IDX_TUNEOPS_NOTIF_MUTES_LOOKUP ON TUNEOPS_NOTIFICATION_MUTES (USER_ID, CONNECTION_ID);
-- idx_tuneops_notif_prefs_user_id: omitted; Oracle's tuneops_notification_prefs_user_id_key index already covers (USER_ID)
-- partial: WHERE (canonical_key IS NOT NULL)
CREATE INDEX IDX_TUNEOPS_TICKETS_CANONICAL ON TUNEOPS_TICKETS (CASE WHEN CANONICAL_KEY IS NOT NULL THEN CANONICAL_KEY END);
-- partial: WHERE (company_id IS NOT NULL)
CREATE INDEX IDX_TUNEOPS_TICKETS_COMPANY ON TUNEOPS_TICKETS (CASE WHEN COMPANY_ID IS NOT NULL THEN COMPANY_ID END);
CREATE INDEX IDX_TUNEOPS_TICKETS_CONNECTION ON TUNEOPS_TICKETS (CONNECTION_ID);
CREATE UNIQUE INDEX IDX_TUNEOPS_TICKETS_NUMBER ON TUNEOPS_TICKETS (TICKET_NUMBER);
CREATE INDEX IDX_TUNEOPS_TICKETS_STATUS ON TUNEOPS_TICKETS (STATUS);
-- idx_user_credits_user_id: omitted; Oracle's user_credits_user_id_key index already covers (USER_ID)
CREATE INDEX IDX_USER_HC_USAGE_EMAIL ON USER_HC_USAGE (LOWER(USER_EMAIL));
-- idx_user_mfa_user_id: omitted; Oracle's user_mfa_user_id_key index already covers (USER_ID)
-- idx_user_preferences_user_id: omitted; Oracle's user_preferences_user_id_key index already covers (USER_ID)
CREATE UNIQUE INDEX USERS_EMAIL_UNIQUE_IDX ON USERS (LOWER(EMAIL));
-- partial: WHERE (google_id IS NOT NULL)
CREATE UNIQUE INDEX USERS_GOOGLE_ID_IDX ON USERS (CASE WHEN GOOGLE_ID IS NOT NULL THEN GOOGLE_ID END);
CREATE INDEX USERS_STRIPE_SUBSCRIPTION_ID_IDX ON USERS (STRIPE_SUBSCRIPTION_ID);
CREATE INDEX IDX_VALIDATION_RUNS_CONNECTION ON VALIDATION_RUNS (CONNECTION_ID, STARTED_AT DESC);
-- partial: WHERE (share_token IS NOT NULL)
CREATE INDEX IDX_VALIDATION_RUNS_SHARE_TOKEN ON VALIDATION_RUNS (CASE WHEN SHARE_TOKEN IS NOT NULL THEN SHARE_TOKEN END);
