Constraints

27 Foreign Key Constraints

Constraint Name Child Column Parent Column Delete Rule
catalog_item_lots_catalog_item_id_fkey
catalog_item_lots.catalog_item_id
catalog_items.id
Cascade on delete
native_payment_transactions_payment_gateway_config_id_fkey
native_payment_transactions.payment_gateway_config_id
payment_gateway_configs.id
Restrict delete
promotion_linked_items_promotion_definition_id_fkey
promotion_linked_items.promotion_definition_id
promotion_definitions.id
Cascade on delete
gift_card_ledger_entries_gift_card_id_fkey
gift_card_ledger_entries.gift_card_id
gift_cards.id
Restrict delete
package_items_package_definition_id_fkey
package_items.package_definition_id
package_definitions.id
Cascade on delete
patient_portal_provider_links_account_id_fkey
patient_portal_provider_links.account_id
patient_portal_accounts.id
Cascade on delete
loyalty_point_adjustments_loyalty_profile_id_fkey
loyalty_point_adjustments.loyalty_profile_id
loyalty_profiles.id
Cascade on delete
catalog_item_provider_mappings_catalog_item_id_fkey
catalog_item_provider_mappings.catalog_item_id
catalog_items.id
Cascade on delete
package_ledger_entries_package_definition_id_fkey
package_ledger_entries.package_definition_id
package_definitions.id
Restrict delete
package_ledger_entries_package_item_id_fkey
package_ledger_entries.package_item_id
package_items.id
Restrict delete
package_ledger_entries_patient_package_instance_id_fkey
package_ledger_entries.patient_package_instance_id
patient_package_instances.id
Restrict delete
package_ledger_entries_patient_package_item_balance_id_fkey
package_ledger_entries.patient_package_item_balance_id
patient_package_item_balances.id
Restrict delete
gift_cards_gift_card_definition_id_fkey
gift_cards.gift_card_definition_id
gift_card_definitions.id
Restrict delete
package_definition_location_prices_package_definition_id_fkey
package_definition_location_prices.package_definition_id
package_definitions.id
Cascade on delete
notification_user_states_notification_id_fkey
notification_user_states.notification_id
notifications.id
Cascade on delete
patient_package_item_balances_package_item_id_fkey
patient_package_item_balances.package_item_id
package_items.id
Restrict delete
patient_package_item_balances_patient_package_instance_id_fkey
patient_package_item_balances.patient_package_instance_id
patient_package_instances.id
Cascade on delete
promotion_applications_promotion_definition_id_fkey
promotion_applications.promotion_definition_id
promotion_definitions.id
Restrict delete
rbac_user_roles_user_id_fkey
rbac_user_roles.user_id
rbac_users.id
Cascade on delete
rbac_user_roles_role_id_fkey
rbac_user_roles.role_id
rbac_roles.id
Cascade on delete
patient_package_instances_package_definition_id_fkey
patient_package_instances.package_definition_id
package_definitions.id
Restrict delete
rbac_role_emulation_grants_role_id_fkey
rbac_role_emulation_grants.role_id
rbac_roles.id
Cascade on delete
catalog_item_location_pricing_catalog_item_id_fkey
catalog_item_location_pricing.catalog_item_id
catalog_items.id
Cascade on delete
rbac_role_permissions_feature_key_fkey
rbac_role_permissions.feature_key
rbac_feature_catalog.feature_key
Restrict delete
rbac_role_permissions_role_id_fkey
rbac_role_permissions.role_id
rbac_roles.id
Cascade on delete
gift_card_definition_locations_gift_card_definition_id_fkey
gift_card_definition_locations.gift_card_definition_id
gift_card_definitions.id
Cascade on delete
rbac_user_locations_user_id_fkey
rbac_user_locations.user_id
rbac_users.id
Cascade on delete

Check Constraints

Table Constraint Name Constraint
catalog_item_lots catalog_item_lots_check ((remaining_quantity <= received_quantity))
catalog_item_lots catalog_item_lots_received_quantity_check ((received_quantity > 0))
catalog_item_lots catalog_item_lots_remaining_quantity_check ((remaining_quantity >= 0))
native_payment_transactions native_payment_transactions_amount_cents_check ((amount_cents > 0))
native_payment_transactions native_payment_transactions_currency_code_check ((currency_code ~ '^[A-Z]{3}$'::text))
native_payment_transactions native_payment_transactions_gateway_check ((gateway = 'fluidpay'::text))
native_payment_transactions native_payment_transactions_gateway_environment_check ((gateway_environment = ANY (ARRAY['sandbox'::text, 'production'::text])))
native_payment_transactions native_payment_transactions_payment_method_type_check ((payment_method_type = 'card_token'::text))
native_payment_transactions native_payment_transactions_practice_id_check ((practice_id <> ''::text))
native_payment_transactions native_payment_transactions_status_check ((status = ANY (ARRAY['pending'::text, 'approved'::text, 'declined'::text, 'gateway_declined'::text, 'processor_error'::text, 'gateway_error'::text])))
patient_files patient_files_category_check ((category = ANY (ARRAY['documents'::text, 'photos'::text, 'media'::text])))
patient_files patient_files_file_name_check ((file_name <> ''::text))
patient_files patient_files_size_bytes_check (((size_bytes IS NULL) OR (size_bytes >= 0)))
patient_files patient_files_storage_provider_check ((storage_provider = ANY (ARRAY['s3'::text, 'r2'::text])))
patient_files patient_files_upload_status_check ((upload_status = ANY (ARRAY['pending'::text, 'uploaded'::text])))
promotion_linked_items promotion_linked_items_catalog_item_kind_check ((catalog_item_kind = ANY (ARRAY['product'::text, 'service'::text])))
promotion_definitions promotion_definitions_check (((ends_at IS NULL) OR (starts_at IS NULL) OR (ends_at > starts_at)))
promotion_definitions promotion_definitions_check1 ((((discount_type = 'percent'::text) AND (discount_percent IS NOT NULL) AND (discount_amount_cents IS NULL)) OR ((discount_type = 'fixed_amount'::text) AND (discount_amount_cents IS NOT NULL) AND (discount_percent IS NULL))))
promotion_definitions promotion_definitions_currency_code_check ((currency_code ~ '^[A-Z]{3}$'::text))
promotion_definitions promotion_definitions_discount_amount_cents_check (((discount_amount_cents IS NULL) OR (discount_amount_cents > 0)))
promotion_definitions promotion_definitions_discount_percent_check (((discount_percent IS NULL) OR ((discount_percent > (0)::numeric) AND (discount_percent <= (100)::numeric))))
promotion_definitions promotion_definitions_discount_type_check ((discount_type = ANY (ARRAY['percent'::text, 'fixed_amount'::text])))
promotion_definitions promotion_definitions_name_check ((name <> ''::text))
gift_card_definitions gift_card_definitions_amount_mode_check ((amount_mode = ANY (ARRAY['fixed'::text, 'custom'::text])))
gift_card_definitions gift_card_definitions_check ((((amount_mode = 'fixed'::text) AND (fixed_amount_cents IS NOT NULL)) OR ((amount_mode = 'custom'::text) AND (fixed_amount_cents IS NULL))))
gift_card_definitions gift_card_definitions_currency_code_check ((currency_code ~ '^[A-Z]{3}$'::text))
gift_card_definitions gift_card_definitions_fixed_amount_cents_check (((fixed_amount_cents IS NULL) OR (fixed_amount_cents > 0)))
rbac_audit_events rbac_audit_events_action_check ((action <> ''::text))
rbac_audit_events rbac_audit_events_target_type_check ((target_type <> ''::text))
gift_card_ledger_entries gift_card_ledger_entries_balance_after_cents_check ((balance_after_cents >= 0))
gift_card_ledger_entries gift_card_ledger_entries_check ((((event_kind = ANY (ARRAY['issue'::text, 'reload'::text])) AND (amount_delta_cents > 0)) OR ((event_kind = ANY (ARRAY['redemption'::text, 'void'::text, 'refund'::text])) AND (amount_delta_cents < 0)) OR ((event_kind = 'adjustment'::text) AND (amount_delta_cents <> 0))))
gift_card_ledger_entries gift_card_ledger_entries_event_kind_check ((event_kind = ANY (ARRAY['issue'::text, 'redemption'::text, 'reload'::text, 'adjustment'::text, 'void'::text, 'refund'::text])))
gift_card_ledger_entries gift_card_ledger_entries_source_kind_check ((source_kind = ANY (ARRAY['checkout'::text, 'invoice'::text, 'payment'::text, 'manual'::text, 'system'::text])))
payment_gateway_configs payment_gateway_configs_gateway_check ((gateway = 'fluidpay'::text))
payment_gateway_configs payment_gateway_configs_gateway_environment_check ((gateway_environment = ANY (ARRAY['sandbox'::text, 'production'::text])))
payment_gateway_configs payment_gateway_configs_practice_id_check ((practice_id <> ''::text))
payment_gateway_configs payment_gateway_configs_public_key_check (((public_key IS NULL) OR (public_key ~~ 'pub_%'::text)))
payment_gateway_configs payment_gateway_configs_status_check ((status = ANY (ARRAY['active'::text, 'inactive'::text])))
package_items package_items_catalog_item_kind_check ((catalog_item_kind = ANY (ARRAY['product'::text, 'service'::text])))
package_items package_items_quantity_check ((quantity > 0))
loyalty_point_adjustments loyalty_point_adjustments_eligible_amount_cents_check (((eligible_amount_cents IS NULL) OR (eligible_amount_cents >= 0)))
loyalty_point_adjustments loyalty_point_adjustments_points_balance_after_check ((points_balance_after >= 0))
loyalty_point_adjustments loyalty_point_adjustments_points_delta_check ((points_delta <> 0))
package_ledger_entries package_ledger_entries_check ((((event_kind = 'purchase'::text) AND (quantity_delta > 0)) OR ((event_kind = 'redemption'::text) AND (quantity_delta < 0)) OR ((event_kind = ANY (ARRAY['void'::text, 'refund'::text, 'expiration'::text])) AND (quantity_delta <= 0)) OR ((event_kind = 'adjustment'::text) AND (quantity_delta <> 0))))
package_ledger_entries package_ledger_entries_check1 ((((patient_package_item_balance_id IS NULL) AND (remaining_quantity_after IS NULL)) OR ((patient_package_item_balance_id IS NOT NULL) AND (remaining_quantity_after IS NOT NULL))))
package_ledger_entries package_ledger_entries_event_kind_check ((event_kind = ANY (ARRAY['purchase'::text, 'redemption'::text, 'adjustment'::text, 'void'::text, 'refund'::text, 'expiration'::text])))
package_ledger_entries package_ledger_entries_remaining_quantity_after_check (((remaining_quantity_after IS NULL) OR (remaining_quantity_after >= 0)))
package_ledger_entries package_ledger_entries_source_kind_check ((source_kind = ANY (ARRAY['checkout'::text, 'invoice'::text, 'payment'::text, 'manual'::text, 'system'::text, 'migration'::text])))
catalog_items catalog_items_kind_check ((kind = ANY (ARRAY['product'::text, 'service'::text, 'fee'::text])))
catalog_items catalog_items_service_duration_minutes_check (((service_duration_minutes IS NULL) OR (service_duration_minutes > 0)))
notifications notifications_priority_check ((priority = ANY (ARRAY['low'::text, 'normal'::text, 'high'::text, 'urgent'::text])))
notifications notifications_source_system_check ((source_system = ANY (ARRAY['legacy_hpt'::text, 'revique'::text])))
notifications notifications_source_type_check ((source_type = ANY (ARRAY['patient_message'::text, 'lead_message'::text, 'form_submission'::text, 'alert'::text])))
gift_cards gift_cards_check ((current_balance_cents <= original_amount_cents))
gift_cards gift_cards_currency_code_check ((currency_code ~ '^[A-Z]{3}$'::text))
gift_cards gift_cards_current_balance_cents_check ((current_balance_cents >= 0))
gift_cards gift_cards_original_amount_cents_check ((original_amount_cents > 0))
gift_cards gift_cards_status_check ((status = ANY (ARRAY['active'::text, 'exhausted'::text, 'voided'::text, 'refunded'::text])))
loyalty_program_products loyalty_program_products_sku_check ((sku <> ''::text))
loyalty_program_products loyalty_program_products_upc_check (((upc IS NULL) OR (upc ~ '^[0-9]+$'::text)))
loyalty_profiles loyalty_profiles_birth_day_check (((birth_day IS NULL) OR ((birth_day >= 1) AND (birth_day <= 31))))
loyalty_profiles loyalty_profiles_birth_month_check (((birth_month IS NULL) OR ((birth_month >= 1) AND (birth_month <= 12))))
loyalty_profiles loyalty_profiles_points_balance_check ((points_balance >= 0))
loyalty_profiles loyalty_profiles_status_check ((status = ANY (ARRAY['registered'::text, 'inactive'::text])))
package_definition_location_prices package_definition_location_prices_price_cents_check ((price_cents >= 0))
patient_package_item_balances patient_package_item_balances_catalog_item_kind_check ((catalog_item_kind = ANY (ARRAY['product'::text, 'service'::text])))
patient_package_item_balances patient_package_item_balances_check ((remaining_quantity <= original_quantity))
patient_package_item_balances patient_package_item_balances_original_quantity_check ((original_quantity > 0))
patient_package_item_balances patient_package_item_balances_remaining_quantity_check ((remaining_quantity >= 0))
package_definitions package_definitions_currency_code_check ((currency_code ~ '^[A-Z]{3}$'::text))
package_definitions package_definitions_expires_after_days_check (((expires_after_days IS NULL) OR (expires_after_days > 0)))
package_definitions package_definitions_price_cents_check ((price_cents >= 0))
promotion_applications promotion_applications_catalog_item_kind_check (((catalog_item_kind IS NULL) OR (catalog_item_kind = ANY (ARRAY['product'::text, 'service'::text]))))
promotion_applications promotion_applications_discount_cents_check ((discount_cents > 0))
promotion_applications promotion_applications_source_kind_check ((source_kind = ANY (ARRAY['checkout'::text, 'invoice'::text, 'payment'::text, 'manual'::text, 'system'::text])))
patient_package_instances patient_package_instances_check (((expires_at IS NULL) OR (expires_at > purchased_at)))
patient_package_instances patient_package_instances_currency_code_check ((currency_code ~ '^[A-Z]{3}$'::text))
patient_package_instances patient_package_instances_price_paid_cents_check ((price_paid_cents >= 0))
patient_package_instances patient_package_instances_status_check ((status = ANY (ARRAY['active'::text, 'exhausted'::text, 'expired'::text, 'voided'::text, 'refunded'::text])))
rbac_role_emulation_grants rbac_role_emulation_grants_check ((expires_at > created_at))
rbac_role_emulation_grants rbac_role_emulation_grants_kind_check ((((emulation_kind = 'role'::text) AND (role_id IS NOT NULL)) OR ((emulation_kind = 'super_admin'::text) AND (role_id IS NULL))))
rbac_role_emulation_grants rbac_role_emulation_grants_token_hash_check ((token_hash <> ''::text))
patient_portal_accounts patient_portal_accounts_status_check ((status = ANY (ARRAY['active'::text, 'disabled'::text])))
rbac_roles rbac_roles_name_check ((name <> ''::text))
rbac_roles rbac_roles_normalized_name_check ((normalized_name <> ''::text))
rbac_roles rbac_roles_normalized_name_check1 ((normalized_name <> 'master'::text))
catalog_item_location_pricing catalog_item_location_pricing_card_price_cents_check (((card_price_cents IS NULL) OR (card_price_cents >= 0)))
catalog_item_location_pricing catalog_item_location_pricing_cash_price_cents_check ((cash_price_cents >= 0))
catalog_item_location_pricing catalog_item_location_pricing_cost_cents_check (((cost_cents IS NULL) OR (cost_cents >= 0)))
catalog_item_location_pricing catalog_item_location_pricing_discount_cents_check (((discount_cents IS NULL) OR (discount_cents >= 0)))
catalog_item_location_pricing catalog_item_location_pricing_discount_percent_check (((discount_percent IS NULL) OR ((discount_percent >= (0)::numeric) AND (discount_percent <= (100)::numeric))))
catalog_item_location_pricing catalog_item_location_pricing_discount_type_check (((discount_type IS NULL) OR (discount_type = ANY (ARRAY['amount'::text, 'percent'::text]))))
catalog_item_location_pricing catalog_item_location_pricing_overhead_cents_check (((overhead_cents IS NULL) OR (overhead_cents >= 0)))
catalog_item_location_pricing catalog_item_location_pricing_tax_percent_check ((tax_percent >= (0)::numeric))
catalog_item_location_pricing catalog_item_location_pricing_unit_price_cents_check ((unit_price_cents >= 0))
rbac_users rbac_users_normalized_user_name_check ((normalized_user_name <> ''::text))
rbac_users rbac_users_user_name_check ((user_name <> ''::text))
rbac_role_permissions rbac_role_permissions_action_check ((action = ANY (ARRAY['view'::text, 'create'::text, 'edit'::text, 'delete'::text, 'export'::text, 'manage'::text, 'assign'::text, 'refund'::text])))
rbac_user_locations rbac_user_locations_practice_location_id_check ((practice_location_id <> ''::text))
rbac_feature_catalog rbac_feature_catalog_actions_check ((array_length(actions, 1) > 0))
rbac_feature_catalog rbac_feature_catalog_actions_check1 ((actions <@ ARRAY['view'::text, 'create'::text, 'edit'::text, 'delete'::text, 'export'::text, 'manage'::text, 'assign'::text, 'refund'::text]))
rbac_feature_catalog rbac_feature_catalog_feature_key_check ((feature_key <> ''::text))
rbac_feature_catalog rbac_feature_catalog_module_key_check ((module_key <> ''::text))
rbac_feature_catalog rbac_feature_catalog_name_check ((name <> ''::text))