-- Indexes -- Gerado automaticamente em 2026-04-17T12:23:05.235Z -- Total: 270 CREATE INDEX agenda_bloqueios_owner_data_idx ON public.agenda_bloqueios USING btree (owner_id, data_inicio, data_fim); CREATE INDEX agenda_bloqueios_owner_id_idx ON public.agenda_bloqueios USING btree (owner_id); CREATE INDEX agenda_bloqueios_recorrente_idx ON public.agenda_bloqueios USING btree (owner_id, dia_semana) WHERE (recorrente = true); CREATE INDEX agenda_bloqueios_tenant_id_idx ON public.agenda_bloqueios USING btree (tenant_id); CREATE INDEX agenda_configuracoes_tenant_idx ON public.agenda_configuracoes USING btree (tenant_id); CREATE INDEX agenda_configuracoes_tenant_owner_idx ON public.agenda_configuracoes USING btree (tenant_id, owner_id); CREATE INDEX agenda_eventos_billing_contract_idx ON public.agenda_eventos USING btree (billing_contract_id) WHERE (billing_contract_id IS NOT NULL); CREATE INDEX agenda_eventos_insurance_plan_idx ON public.agenda_eventos USING btree (insurance_plan_id); CREATE INDEX agenda_eventos_owner_inicio_idx ON public.agenda_eventos USING btree (owner_id, inicio_em); CREATE INDEX agenda_eventos_owner_terapeuta_inicio_idx ON public.agenda_eventos USING btree (owner_id, terapeuta_id, inicio_em); CREATE INDEX agenda_eventos_recurrence_idx ON public.agenda_eventos USING btree (recurrence_id) WHERE (recurrence_id IS NOT NULL); CREATE INDEX agenda_eventos_tenant_inicio_idx ON public.agenda_eventos USING btree (tenant_id, inicio_em); CREATE INDEX agenda_eventos_tenant_owner_inicio_idx ON public.agenda_eventos USING btree (tenant_id, owner_id, inicio_em); CREATE INDEX agenda_excecoes_owner_data_idx ON public.agenda_excecoes USING btree (owner_id, data); CREATE INDEX agenda_excecoes_tenant_idx ON public.agenda_excecoes USING btree (tenant_id); CREATE INDEX agenda_excecoes_tenant_owner_idx ON public.agenda_excecoes USING btree (tenant_id, owner_id); CREATE INDEX agenda_online_slots_owner_weekday_idx ON public.agenda_online_slots USING btree (owner_id, weekday); CREATE INDEX agenda_online_slots_tenant_idx ON public.agenda_online_slots USING btree (tenant_id); CREATE INDEX agenda_online_slots_tenant_owner_idx ON public.agenda_online_slots USING btree (tenant_id, owner_id); CREATE INDEX agenda_regras_semanais_owner_dia_idx ON public.agenda_regras_semanais USING btree (owner_id, dia_semana); CREATE INDEX agenda_regras_semanais_tenant_idx ON public.agenda_regras_semanais USING btree (tenant_id); CREATE INDEX agenda_regras_semanais_tenant_owner_idx ON public.agenda_regras_semanais USING btree (tenant_id, owner_id); CREATE INDEX agenda_slots_bloqueados_semanais_tenant_idx ON public.agenda_slots_bloqueados_semanais USING btree (tenant_id); CREATE INDEX agenda_slots_bloqueados_semanais_tenant_owner_idx ON public.agenda_slots_bloqueados_semanais USING btree (tenant_id, owner_id); CREATE INDEX agenda_slots_regras_tenant_idx ON public.agenda_slots_regras USING btree (tenant_id); CREATE INDEX agenda_slots_regras_tenant_owner_idx ON public.agenda_slots_regras USING btree (tenant_id, owner_id); CREATE INDEX agendador_cfg_tenant_idx ON public.agendador_configuracoes USING btree (tenant_id); CREATE INDEX agendador_sol_data_idx ON public.agendador_solicitacoes USING btree (data_solicitada, hora_solicitada); CREATE INDEX agendador_sol_owner_idx ON public.agendador_solicitacoes USING btree (owner_id, status); CREATE INDEX agendador_sol_tenant_idx ON public.agendador_solicitacoes USING btree (tenant_id); CREATE INDEX billing_contracts_owner_idx ON public.billing_contracts USING btree (owner_id); CREATE INDEX billing_contracts_patient_idx ON public.billing_contracts USING btree (patient_id); CREATE INDEX billing_contracts_tenant_idx ON public.billing_contracts USING btree (tenant_id); CREATE INDEX commitment_services_commitment_idx ON public.commitment_services USING btree (commitment_id); CREATE INDEX commitment_services_service_idx ON public.commitment_services USING btree (service_id); CREATE INDEX commitment_time_logs_calendar_event_idx ON public.commitment_time_logs USING btree (calendar_event_id); CREATE INDEX commitment_time_logs_commitment_idx ON public.commitment_time_logs USING btree (commitment_id, created_at DESC); CREATE INDEX commitment_time_logs_tenant_idx ON public.commitment_time_logs USING btree (tenant_id, created_at DESC); CREATE INDEX dal_documento_idx ON public.document_access_logs USING btree (documento_id, acessado_em DESC); CREATE INDEX dal_tenant_idx ON public.document_access_logs USING btree (tenant_id, acessado_em DESC); CREATE INDEX dal_user_idx ON public.document_access_logs USING btree (user_id, acessado_em DESC); CREATE INDEX determined_commitment_fields_commitment_idx ON public.determined_commitment_fields USING btree (commitment_id, sort_order); CREATE UNIQUE INDEX determined_commitment_fields_key_uniq ON public.determined_commitment_fields USING btree (commitment_id, key); CREATE INDEX determined_commitment_fields_tenant_idx ON public.determined_commitment_fields USING btree (tenant_id); CREATE INDEX determined_commitments_active_idx ON public.determined_commitments USING btree (tenant_id, active); CREATE INDEX determined_commitments_tenant_idx ON public.determined_commitments USING btree (tenant_id); CREATE UNIQUE INDEX determined_commitments_tenant_name_uniq ON public.determined_commitments USING btree (tenant_id, lower(name)); CREATE INDEX dg_gerado_por_idx ON public.document_generated USING btree (gerado_por, gerado_em DESC); CREATE INDEX dg_patient_idx ON public.document_generated USING btree (patient_id, gerado_em DESC); CREATE INDEX dg_template_idx ON public.document_generated USING btree (template_id); CREATE INDEX dg_tenant_idx ON public.document_generated USING btree (tenant_id, gerado_em DESC); CREATE INDEX docs_active_idx ON public.documents USING btree (patient_id, uploaded_at DESC) WHERE (deleted_at IS NULL); CREATE INDEX docs_nome_trgm_idx ON public.documents USING gin (nome_original public.gin_trgm_ops); CREATE INDEX docs_owner_idx ON public.documents USING btree (owner_id); CREATE INDEX docs_patient_idx ON public.documents USING btree (patient_id); CREATE INDEX docs_tags_idx ON public.documents USING gin (tags); CREATE INDEX docs_tenant_idx ON public.documents USING btree (tenant_id); CREATE INDEX docs_tipo_idx ON public.documents USING btree (patient_id, tipo_documento); CREATE INDEX docs_uploaded_at_idx ON public.documents USING btree (patient_id, uploaded_at DESC); CREATE INDEX ds_documento_idx ON public.document_signatures USING btree (documento_id, ordem); CREATE INDEX ds_status_idx ON public.document_signatures USING btree (documento_id, status); CREATE INDEX ds_tenant_idx ON public.document_signatures USING btree (tenant_id); CREATE INDEX dsl_documento_idx ON public.document_share_links USING btree (documento_id); CREATE INDEX dsl_expira_idx ON public.document_share_links USING btree (expira_em) WHERE (ativo = true); CREATE INDEX dsl_token_idx ON public.document_share_links USING btree (token) WHERE (ativo = true); CREATE INDEX dt_global_idx ON public.document_templates USING btree (is_global) WHERE (is_global = true); CREATE INDEX dt_nome_trgm_idx ON public.document_templates USING gin (nome_template public.gin_trgm_ops); CREATE INDEX dt_owner_idx ON public.document_templates USING btree (owner_id); CREATE INDEX dt_tenant_idx ON public.document_templates USING btree (tenant_id); CREATE INDEX dt_tipo_idx ON public.document_templates USING btree (tipo); CREATE UNIQUE INDEX feriados_global_unique ON public.feriados USING btree (data, nome) WHERE (tenant_id IS NULL); CREATE INDEX financial_exceptions_owner_idx ON public.financial_exceptions USING btree (owner_id); CREATE INDEX financial_exceptions_tenant_idx ON public.financial_exceptions USING btree (tenant_id); CREATE INDEX idx_addon_credits_tenant ON public.addon_credits USING btree (tenant_id) WHERE (is_active = true); CREATE INDEX idx_addon_credits_type ON public.addon_credits USING btree (addon_type) WHERE (is_active = true); CREATE INDEX idx_addon_products_active ON public.addon_products USING btree (is_active, is_visible) WHERE (deleted_at IS NULL); CREATE INDEX idx_addon_products_type ON public.addon_products USING btree (addon_type) WHERE (deleted_at IS NULL); CREATE INDEX idx_addon_tx_created ON public.addon_transactions USING btree (created_at DESC); CREATE INDEX idx_addon_tx_queue ON public.addon_transactions USING btree (queue_id) WHERE (queue_id IS NOT NULL); CREATE INDEX idx_addon_tx_tenant ON public.addon_transactions USING btree (tenant_id, addon_type); CREATE INDEX idx_addon_tx_type ON public.addon_transactions USING btree (type); CREATE INDEX idx_agenda_eventos_determined_commitment_id ON public.agenda_eventos USING btree (determined_commitment_id); CREATE INDEX idx_agenda_excecoes_owner_data ON public.agenda_excecoes USING btree (owner_id, data); CREATE INDEX idx_agenda_slots_regras_owner_dia ON public.agenda_slots_regras USING btree (owner_id, dia_semana); CREATE INDEX idx_email_templates_global_domain ON public.email_templates_global USING btree (domain) WHERE (is_active = true); CREATE INDEX idx_email_templates_global_key ON public.email_templates_global USING btree (key) WHERE (is_active = true); CREATE INDEX idx_email_templates_tenant_lookup ON public.email_templates_tenant USING btree (tenant_id, template_key) WHERE (enabled = true); CREATE INDEX idx_email_templates_tenant_owner ON public.email_templates_tenant USING btree (owner_id, template_key) WHERE ((enabled = true) AND (owner_id IS NOT NULL)); CREATE INDEX idx_financial_categories_user_id ON public.financial_categories USING btree (user_id); CREATE INDEX idx_financial_records_active ON public.financial_records USING btree (owner_id, paid_at DESC) WHERE (deleted_at IS NULL); CREATE INDEX idx_financial_records_agenda_evento_id ON public.financial_records USING btree (agenda_evento_id) WHERE (agenda_evento_id IS NOT NULL); CREATE INDEX idx_financial_records_category_id ON public.financial_records USING btree (category_id) WHERE (category_id IS NOT NULL); CREATE INDEX idx_financial_records_due_date ON public.financial_records USING btree (due_date); CREATE INDEX idx_financial_records_installment_group ON public.financial_records USING btree (installment_group) WHERE (installment_group IS NOT NULL); CREATE INDEX idx_financial_records_owner_id ON public.financial_records USING btree (owner_id); CREATE INDEX idx_financial_records_paid_at ON public.financial_records USING btree (paid_at DESC); CREATE INDEX idx_financial_records_patient_id ON public.financial_records USING btree (patient_id); CREATE INDEX idx_financial_records_status ON public.financial_records USING btree (status) WHERE (deleted_at IS NULL); CREATE INDEX idx_financial_records_tenant_active ON public.financial_records USING btree (tenant_id, paid_at DESC) WHERE ((deleted_at IS NULL) AND (tenant_id IS NOT NULL)); CREATE INDEX idx_financial_records_tenant_id ON public.financial_records USING btree (tenant_id); CREATE INDEX idx_financial_records_type_status ON public.financial_records USING btree (type, status); CREATE INDEX idx_global_notices_active_priority ON public.global_notices USING btree (is_active, priority DESC, starts_at, ends_at); CREATE INDEX idx_intakes_converted_patient_id ON public.patient_intake_requests USING btree (converted_patient_id); CREATE INDEX idx_intakes_owner_cpf ON public.patient_intake_requests USING btree (owner_id, cpf); CREATE INDEX idx_intakes_owner_created ON public.patient_intake_requests USING btree (owner_id, created_at DESC); CREATE INDEX idx_intakes_owner_status_created ON public.patient_intake_requests USING btree (owner_id, status, created_at DESC); CREATE INDEX idx_intakes_status_created ON public.patient_intake_requests USING btree (status, created_at DESC); CREATE INDEX idx_notice_dismissals_user ON public.notice_dismissals USING btree (user_id, notice_id); CREATE INDEX idx_notif_channels_owner_active ON public.notification_channels USING btree (owner_id, channel) WHERE ((is_active = true) AND (deleted_at IS NULL)); CREATE INDEX idx_notif_channels_tenant ON public.notification_channels USING btree (tenant_id) WHERE (deleted_at IS NULL); CREATE INDEX idx_notif_logs_owner_date ON public.notification_logs USING btree (owner_id, created_at DESC); CREATE INDEX idx_notif_logs_patient ON public.notification_logs USING btree (patient_id, created_at DESC); CREATE INDEX idx_notif_logs_provider_msg ON public.notification_logs USING btree (provider_message_id) WHERE (provider_message_id IS NOT NULL); CREATE INDEX idx_notif_logs_status ON public.notification_logs USING btree (status, created_at DESC); CREATE INDEX idx_notif_logs_tenant_date ON public.notification_logs USING btree (tenant_id, created_at DESC); CREATE INDEX idx_notif_prefs_owner ON public.notification_preferences USING btree (owner_id) WHERE (deleted_at IS NULL); CREATE INDEX idx_notif_prefs_patient ON public.notification_preferences USING btree (patient_id) WHERE (deleted_at IS NULL); CREATE INDEX idx_notif_prefs_whatsapp_active ON public.notification_preferences USING btree (owner_id, patient_id) WHERE ((whatsapp_opt_in = true) AND (deleted_at IS NULL)); CREATE INDEX idx_notif_queue_evento ON public.notification_queue USING btree (agenda_evento_id) WHERE (status = ANY (ARRAY['pendente'::text, 'processando'::text])); CREATE INDEX idx_notif_queue_patient ON public.notification_queue USING btree (patient_id, channel) WHERE (status = 'pendente'::text); CREATE INDEX idx_notif_queue_pending ON public.notification_queue USING btree (scheduled_at) WHERE (status = 'pendente'::text); CREATE INDEX idx_notif_queue_processing ON public.notification_queue USING btree (status, updated_at) WHERE (status = 'processando'::text); CREATE INDEX idx_notif_queue_retry ON public.notification_queue USING btree (next_retry_at) WHERE ((status = 'pendente'::text) AND (attempts > 0)); CREATE INDEX idx_notif_queue_tenant ON public.notification_queue USING btree (tenant_id, created_at DESC); CREATE INDEX idx_notif_schedules_owner_active ON public.notification_schedules USING btree (owner_id, event_type) WHERE ((is_active = true) AND (deleted_at IS NULL)); CREATE INDEX idx_notif_templates_default ON public.notification_templates USING btree (channel, event_type) WHERE ((is_default = true) AND (deleted_at IS NULL) AND (tenant_id IS NULL)); CREATE INDEX idx_notif_templates_lookup ON public.notification_templates USING btree (channel, event_type, is_active) WHERE (deleted_at IS NULL); CREATE INDEX idx_notif_templates_tenant ON public.notification_templates USING btree (tenant_id, channel, event_type) WHERE ((deleted_at IS NULL) AND (is_active = true)); CREATE INDEX idx_notification_channels_twilio_subaccount_sid ON public.notification_channels USING btree (twilio_subaccount_sid) WHERE (twilio_subaccount_sid IS NOT NULL); CREATE INDEX idx_patient_contacts_patient ON public.patient_contacts USING btree (patient_id); CREATE INDEX idx_patient_contacts_tenant ON public.patient_contacts USING btree (tenant_id); CREATE INDEX idx_patient_group_patient_group_id ON public.patient_group_patient USING btree (patient_group_id); CREATE INDEX idx_patient_groups_owner ON public.patient_groups USING btree (owner_id); CREATE INDEX idx_patient_groups_owner_system_nome ON public.patient_groups USING btree (owner_id, is_system, nome); CREATE INDEX idx_patient_tags_owner ON public.patient_tags USING btree (owner_id); CREATE INDEX idx_patients_created_at ON public.patients USING btree (created_at DESC); CREATE INDEX idx_patients_last_attended ON public.patients USING btree (last_attended_at DESC); CREATE INDEX idx_patients_origem ON public.patients USING btree (tenant_id, origem) WHERE (origem IS NOT NULL); CREATE INDEX idx_patients_owner_email_principal ON public.patients USING btree (owner_id, email_principal); CREATE INDEX idx_patients_owner_id ON public.patients USING btree (owner_id); CREATE INDEX idx_patients_owner_nome ON public.patients USING btree (owner_id, nome_completo); CREATE INDEX idx_patients_responsible_member ON public.patients USING btree (responsible_member_id); CREATE INDEX idx_patients_risco_elevado ON public.patients USING btree (tenant_id, risco_elevado) WHERE (risco_elevado = true); CREATE INDEX idx_patients_status ON public.patients USING btree (status); CREATE INDEX idx_patients_status_tenant ON public.patients USING btree (tenant_id, status); CREATE INDEX idx_patients_tenant ON public.patients USING btree (tenant_id); CREATE INDEX idx_patients_tenant_email_norm ON public.patients USING btree (tenant_id, lower(TRIM(BOTH FROM email_principal))); CREATE INDEX idx_pgp_group ON public.patient_group_patient USING btree (patient_group_id); CREATE INDEX idx_pgp_patient ON public.patient_group_patient USING btree (patient_id); CREATE INDEX idx_ppt_patient ON public.patient_patient_tag USING btree (patient_id); CREATE INDEX idx_ppt_tag ON public.patient_patient_tag USING btree (tag_id); CREATE INDEX idx_psh_patient ON public.patient_status_history USING btree (patient_id, alterado_em DESC); CREATE INDEX idx_psh_tenant ON public.patient_status_history USING btree (tenant_id, alterado_em DESC); CREATE INDEX idx_pt_evento_tipo ON public.patient_timeline USING btree (patient_id, evento_tipo); CREATE INDEX idx_pt_patient_ocorrido ON public.patient_timeline USING btree (patient_id, ocorrido_em DESC); CREATE INDEX idx_pt_tenant ON public.patient_timeline USING btree (tenant_id, ocorrido_em DESC); CREATE INDEX idx_slots_bloq_owner_dia ON public.agenda_slots_bloqueados_semanais USING btree (owner_id, dia_semana); CREATE INDEX idx_subscription_intents_plan_interval ON public.subscription_intents_legacy USING btree (plan_key, "interval"); CREATE INDEX idx_subscription_intents_status ON public.subscription_intents_legacy USING btree (status); CREATE INDEX idx_subscription_intents_user_id ON public.subscription_intents_legacy USING btree (user_id); CREATE INDEX idx_tenant_features_tenant ON public.tenant_features USING btree (tenant_id); CREATE INDEX idx_tenant_invites_tenant ON public.tenant_invites USING btree (tenant_id); CREATE INDEX idx_tenant_invites_token ON public.tenant_invites USING btree (token); CREATE INDEX idx_therapist_payout_records_financial_record_id ON public.therapist_payout_records USING btree (financial_record_id); CREATE INDEX idx_therapist_payouts_owner_id ON public.therapist_payouts USING btree (owner_id); CREATE INDEX idx_therapist_payouts_period ON public.therapist_payouts USING btree (period_start, period_end); CREATE INDEX idx_therapist_payouts_status ON public.therapist_payouts USING btree (status) WHERE (status = 'pending'::text); CREATE INDEX idx_therapist_payouts_tenant_id ON public.therapist_payouts USING btree (tenant_id); CREATE INDEX idx_twilio_usage_channel ON public.twilio_subaccount_usage USING btree (channel_id, period_start DESC); CREATE INDEX idx_twilio_usage_tenant_period ON public.twilio_subaccount_usage USING btree (tenant_id, period_start DESC); CREATE UNIQUE INDEX idx_twilio_usage_unique_period ON public.twilio_subaccount_usage USING btree (channel_id, period_start, period_end); CREATE INDEX insurance_plans_owner_idx ON public.insurance_plans USING btree (owner_id); CREATE INDEX insurance_plans_tenant_idx ON public.insurance_plans USING btree (tenant_id); CREATE INDEX ix_plan_prices_plan ON public.plan_prices USING btree (plan_id); CREATE INDEX ix_plan_public_bullets_plan ON public.plan_public_bullets USING btree (plan_id); CREATE INDEX ix_plan_public_sort ON public.plan_public USING btree (sort_order); CREATE INDEX medicos_especialidade_idx ON public.medicos USING btree (especialidade); CREATE INDEX medicos_nome_idx ON public.medicos USING btree (nome); CREATE INDEX medicos_nome_trgm_idx ON public.medicos USING gin (nome public.gin_trgm_ops); CREATE INDEX medicos_owner_idx ON public.medicos USING btree (owner_id); CREATE INDEX medicos_tenant_idx ON public.medicos USING btree (tenant_id); CREATE INDEX notifications_owner_created ON public.notifications USING btree (owner_id, created_at DESC); CREATE INDEX notifications_owner_unread ON public.notifications USING btree (owner_id, read_at) WHERE (read_at IS NULL); CREATE INDEX patient_discounts_owner_idx ON public.patient_discounts USING btree (owner_id); CREATE INDEX patient_discounts_patient_idx ON public.patient_discounts USING btree (patient_id); CREATE INDEX patient_discounts_tenant_idx ON public.patient_discounts USING btree (tenant_id); CREATE INDEX patient_group_patient_tenant_idx ON public.patient_group_patient USING btree (tenant_id); CREATE UNIQUE INDEX patient_groups_owner_nome_uniq ON public.patient_groups USING btree (owner_id, nome); CREATE INDEX patient_groups_tenant_idx ON public.patient_groups USING btree (tenant_id); CREATE INDEX patient_intake_owner_id_idx ON public.patient_intake_requests USING btree (owner_id); CREATE INDEX patient_intake_requests_tenant_idx ON public.patient_intake_requests USING btree (tenant_id); CREATE INDEX patient_intake_status_idx ON public.patient_intake_requests USING btree (status); CREATE INDEX patient_intake_token_idx ON public.patient_intake_requests USING btree (token); CREATE UNIQUE INDEX patient_invites_one_active_per_owner ON public.patient_invites USING btree (owner_id) WHERE (active = true); CREATE INDEX patient_invites_owner_id_idx ON public.patient_invites USING btree (owner_id); CREATE INDEX patient_invites_tenant_idx ON public.patient_invites USING btree (tenant_id); CREATE INDEX patient_invites_token_idx ON public.patient_invites USING btree (token); CREATE INDEX patient_patient_tag_tenant_idx ON public.patient_patient_tag USING btree (tenant_id); CREATE UNIQUE INDEX patient_tags_owner_name_uq ON public.patient_tags USING btree (owner_id, lower(nome)); CREATE INDEX patient_tags_tenant_idx ON public.patient_tags USING btree (tenant_id); CREATE INDEX patients_convenio_id_idx ON public.patients USING btree (convenio_id); CREATE INDEX patients_etnia_idx ON public.patients USING btree (etnia); CREATE INDEX patients_pronomes_idx ON public.patients USING btree (pronomes); CREATE INDEX payment_settings_tenant_id_idx ON public.payment_settings USING btree (tenant_id); CREATE INDEX ppt_owner_idx ON public.patient_patient_tag USING btree (owner_id); CREATE INDEX ppt_patient_idx ON public.patient_patient_tag USING btree (patient_id); CREATE INDEX ppt_tag_idx ON public.patient_patient_tag USING btree (tag_id); CREATE INDEX professional_pricing_tenant_idx ON public.professional_pricing USING btree (tenant_id); CREATE INDEX profiles_work_description_idx ON public.profiles USING btree (work_description) WHERE (work_description IS NOT NULL); CREATE INDEX psc_owner_idx ON public.patient_support_contacts USING btree (owner_id); CREATE INDEX psc_patient_idx ON public.patient_support_contacts USING btree (patient_id); CREATE INDEX recurrence_exceptions_rule_idx ON public.recurrence_exceptions USING btree (recurrence_id); CREATE INDEX recurrence_exceptions_tenant_idx ON public.recurrence_exceptions USING btree (tenant_id); CREATE INDEX recurrence_rule_services_rule_idx ON public.recurrence_rule_services USING btree (rule_id); CREATE INDEX recurrence_rule_services_service_idx ON public.recurrence_rule_services USING btree (service_id); CREATE INDEX recurrence_rules_active_idx ON public.recurrence_rules USING btree (owner_id, status) WHERE (status = 'ativo'::text); CREATE INDEX recurrence_rules_owner_idx ON public.recurrence_rules USING btree (owner_id); CREATE INDEX recurrence_rules_patient_idx ON public.recurrence_rules USING btree (patient_id); CREATE INDEX recurrence_rules_tenant_idx ON public.recurrence_rules USING btree (tenant_id); CREATE INDEX saas_doc_votos_doc_id_idx ON public.saas_doc_votos USING btree (doc_id); CREATE INDEX saas_doc_votos_user_id_idx ON public.saas_doc_votos USING btree (user_id); CREATE INDEX saas_docs_categoria_idx ON public.saas_docs USING btree (categoria); CREATE INDEX saas_docs_exibir_no_faq_idx ON public.saas_docs USING btree (exibir_no_faq) WHERE (exibir_no_faq = true); CREATE INDEX saas_docs_path_ativo_idx ON public.saas_docs USING btree (pagina_path, ativo); CREATE INDEX saas_faq_ativo_idx ON public.saas_faq USING btree (ativo); CREATE INDEX saas_faq_categoria_idx ON public.saas_faq USING btree (categoria); CREATE INDEX saas_faq_fts_idx ON public.saas_faq USING gin (to_tsvector('portuguese'::regconfig, ((COALESCE(pergunta, ''::text) || ' '::text) || COALESCE(conteudo, ''::text)))); CREATE INDEX saas_faq_itens_ativo_idx ON public.saas_faq_itens USING btree (ativo); CREATE INDEX saas_faq_itens_doc_id_idx ON public.saas_faq_itens USING btree (doc_id); CREATE INDEX saas_faq_pagina_path_idx ON public.saas_faq USING btree (pagina_path); CREATE INDEX saas_faq_publico_idx ON public.saas_faq USING btree (publico); CREATE INDEX saas_faq_votos_idx ON public.saas_faq USING btree (votos DESC); CREATE INDEX services_owner_idx ON public.services USING btree (owner_id); CREATE INDEX services_tenant_idx ON public.services USING btree (tenant_id); CREATE INDEX sint_personal_created_idx ON public.subscription_intents_personal USING btree (created_at DESC); CREATE INDEX sint_personal_status_idx ON public.subscription_intents_personal USING btree (status); CREATE INDEX sint_tenant_created_idx ON public.subscription_intents_tenant USING btree (created_at DESC); CREATE INDEX sint_tenant_status_idx ON public.subscription_intents_tenant USING btree (status); CREATE INDEX sint_tenant_tenant_idx ON public.subscription_intents_tenant USING btree (tenant_id); CREATE INDEX subscription_events_created_at_idx ON public.subscription_events USING btree (created_at DESC); CREATE INDEX subscription_events_owner_ref_idx ON public.subscription_events USING btree (owner_type, owner_ref); CREATE INDEX subscription_events_sub_created_idx ON public.subscription_events USING btree (subscription_id, created_at DESC); CREATE INDEX subscription_events_subscription_id_idx ON public.subscription_events USING btree (subscription_id); CREATE UNIQUE INDEX subscriptions_one_active_per_tenant ON public.subscriptions USING btree (tenant_id) WHERE (status = 'active'::text); CREATE UNIQUE INDEX subscriptions_one_active_per_user ON public.subscriptions USING btree (user_id) WHERE (status = 'active'::text); CREATE UNIQUE INDEX subscriptions_one_active_per_user_personal ON public.subscriptions USING btree (user_id) WHERE ((tenant_id IS NULL) AND (status = 'active'::text)); CREATE INDEX subscriptions_owner_idx ON public.subscriptions USING btree (user_id); CREATE INDEX subscriptions_plan_key_idx ON public.subscriptions USING btree (plan_key); CREATE INDEX subscriptions_status_idx ON public.subscriptions USING btree (status); CREATE INDEX subscriptions_tenant_id_idx ON public.subscriptions USING btree (tenant_id); CREATE INDEX subscriptions_tenant_period_end_idx ON public.subscriptions USING btree (tenant_id, current_period_end); CREATE INDEX subscriptions_tenant_status_idx ON public.subscriptions USING btree (tenant_id, status); CREATE INDEX subscriptions_user_status_idx ON public.subscriptions USING btree (user_id, status, created_at DESC); CREATE INDEX support_sessions_expires_idx ON public.support_sessions USING btree (expires_at); CREATE INDEX support_sessions_tenant_idx ON public.support_sessions USING btree (tenant_id); CREATE INDEX support_sessions_token_idx ON public.support_sessions USING btree (token); CREATE INDEX tenant_members_tenant_idx ON public.tenant_members USING btree (tenant_id); CREATE INDEX tenant_members_user_idx ON public.tenant_members USING btree (user_id); CREATE INDEX tenant_modules_owner_idx ON public.tenant_modules USING btree (owner_id); CREATE UNIQUE INDEX unique_member_per_tenant ON public.tenant_members USING btree (tenant_id, user_id); CREATE UNIQUE INDEX uq_patient_contacts_primario ON public.patient_contacts USING btree (patient_id) WHERE ((is_primario = true) AND (ativo = true)); CREATE UNIQUE INDEX uq_patients_tenant_user ON public.patients USING btree (tenant_id, user_id) WHERE (user_id IS NOT NULL); CREATE UNIQUE INDEX uq_plan_price_active ON public.plan_prices USING btree (plan_id, "interval", currency) WHERE ((is_active = true) AND (active_to IS NULL)); CREATE UNIQUE INDEX uq_plan_prices_active ON public.plan_prices USING btree (plan_id, "interval") WHERE (is_active = true); CREATE UNIQUE INDEX uq_subscriptions_active_by_tenant ON public.subscriptions USING btree (tenant_id) WHERE ((tenant_id IS NOT NULL) AND (status = 'active'::text)); CREATE UNIQUE INDEX uq_subscriptions_active_personal_by_user ON public.subscriptions USING btree (user_id) WHERE ((tenant_id IS NULL) AND (status = 'active'::text)); CREATE UNIQUE INDEX uq_tenant_invites_pending ON public.tenant_invites USING btree (tenant_id, lower(email), role) WHERE ((accepted_at IS NULL) AND (revoked_at IS NULL)); CREATE UNIQUE INDEX uq_tenant_members_tenant_user ON public.tenant_members USING btree (tenant_id, user_id); CREATE UNIQUE INDEX ux_subscriptions_active_per_personal_user ON public.subscriptions USING btree (user_id) WHERE ((status = 'active'::text) AND (tenant_id IS NULL)); CREATE UNIQUE INDEX ux_subscriptions_active_per_tenant ON public.subscriptions USING btree (tenant_id) WHERE ((status = 'active'::text) AND (tenant_id IS NOT NULL));