Skip to content

Tables

Generated by pnpm docs:reference from the local database (BE-M0-31). Never edit this page by hand (D27).

Column Type Null Default Note
id bigint not null
organization_id uuid
pool_id uuid
table_name text not null
record_id text
action audit_action not null
changed_fields text[]
old_data jsonb
new_data jsonb
actor_id uuid
source audit_source not null 'app'::audit_source
db_user text
transaction_id bigint not null ((pg_current_xact_id())::text)::bigint
at timestamp with time zone not null now()
Constraint Definition
audit_log_pkey PRIMARY KEY (id)
Index Definition
audit_log_org_at_idx CREATE INDEX audit_log_org_at_idx ON public.audit_log USING btree (organization_id, at DESC)
audit_log_pool_at_idx CREATE INDEX audit_log_pool_at_idx ON public.audit_log USING btree (pool_id, at DESC)
audit_log_record_idx CREATE INDEX audit_log_record_idx ON public.audit_log USING btree (table_name, record_id, at DESC)
audit_log_transaction_idx CREATE INDEX audit_log_transaction_idx ON public.audit_log USING btree (transaction_id)
Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
check_id uuid not null
kind check_photo_kind not null
storage_path storage_path not null
uploaded_at timestamp with time zone not null now()
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
background_check_photos_check_id_fkey FOREIGN KEY (check_id) REFERENCES background_checks(id) ON DELETE CASCADE
background_check_photos_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
background_check_photos_pkey PRIMARY KEY (id)
Index Definition
background_check_photos_check_id_fk_idx CREATE INDEX background_check_photos_check_id_fk_idx ON public.background_check_photos USING btree (check_id)
background_check_photos_organization_id_fk_idx CREATE INDEX background_check_photos_organization_id_fk_idx ON public.background_check_photos USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
kind check_kind not null
status check_status not null 'scheduled'::check_status
due_by date
surveyor_id uuid
guarantor_name text
scheduled_on date
decided_at timestamp with time zone
decided_by uuid
recommended_model_id uuid
reject_reason text
refund_admin_fee boolean not null false
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
background_checks_decided CHECK (((status = ANY (ARRAY['scheduled'::check_status, 'cancelled'::check_status])) OR (decided_at IS NOT NULL)))
background_checks_due_by_visit_only CHECK (((kind = 'visit'::check_kind) OR (due_by IS NULL)))
background_checks_decided_by_fkey FOREIGN KEY (decided_by) REFERENCES profiles(id)
background_checks_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id)
background_checks_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
background_checks_recommended_model_id_fkey FOREIGN KEY (recommended_model_id) REFERENCES vehicle_models(id)
background_checks_surveyor_id_fkey FOREIGN KEY (surveyor_id) REFERENCES profiles(id)
background_checks_pkey PRIMARY KEY (id)
Index Definition
background_checks_decided_by_fk_idx CREATE INDEX background_checks_decided_by_fk_idx ON public.background_checks USING btree (decided_by)
background_checks_driver_id_fk_idx CREATE INDEX background_checks_driver_id_fk_idx ON public.background_checks USING btree (driver_id)
background_checks_organization_id_fk_idx CREATE INDEX background_checks_organization_id_fk_idx ON public.background_checks USING btree (organization_id)
background_checks_recommended_model_id_fk_idx CREATE INDEX background_checks_recommended_model_id_fk_idx ON public.background_checks USING btree (recommended_model_id)
background_checks_surveyor_id_fk_idx CREATE INDEX background_checks_surveyor_id_fk_idx ON public.background_checks USING btree (surveyor_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
code text not null
name text not null
name_en text
area panel_area not null
vehicle_class vehicle_class not null 'car'::vehicle_class
is_system boolean not null false
is_active boolean not null true
sort_order smallint not null 100
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
body_panels_code_format CHECK ((code ~ '^[a-z0-9_]+$'::text))
body_panels_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
body_panels_pkey PRIMARY KEY (id)
body_panels_code_unique UNIQUE (organization_id, code)
body_panels_id_org_unique UNIQUE (id, organization_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
charge_id uuid not null
kind adjustment_kind not null
amount bigint not null
reason text not null
proof_path storage_path
created_by uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
charge_adjustments_amount_positive CHECK ((amount > 0))
charge_adjustments_charge_id_fkey FOREIGN KEY (charge_id) REFERENCES charges(id)
charge_adjustments_created_by_fkey FOREIGN KEY (created_by) REFERENCES profiles(id)
charge_adjustments_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
charge_adjustments_pkey PRIMARY KEY (id)
Index Definition
charge_adjustments_charge_id_fk_idx CREATE INDEX charge_adjustments_charge_id_fk_idx ON public.charge_adjustments USING btree (charge_id)
charge_adjustments_created_by_fk_idx CREATE INDEX charge_adjustments_created_by_fk_idx ON public.charge_adjustments USING btree (created_by)
charge_adjustments_organization_id_fk_idx CREATE INDEX charge_adjustments_organization_id_fk_idx ON public.charge_adjustments USING btree (organization_id)

Triggers: audit_row (app.audit_row), refresh_charge_status (app.after_allocation_change), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
code text not null
name text not null
name_en text
is_system boolean not null false
default_amount bigint
default_due_days smallint not null 3
needs_rental boolean not null false
is_active boolean not null true
sort_order smallint not null 100
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
charge_types_code_format CHECK ((code ~ '^[a-z_]+$'::text))
charge_types_default_amount_check CHECK ((default_amount >= 0))
charge_types_default_due_days_check CHECK ((default_due_days >= 0))
charge_types_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
charge_types_pkey PRIMARY KEY (id)
charge_types_code_unique UNIQUE (organization_id, code)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
rental_id uuid
legal_entity_id uuid
charge_type_id uuid not null
description text not null ''::text
charge_date date not null
billing_day date
due_date date not null
amount bigint not null
company_amount bigint
margin bigint generated
status charge_status not null 'open'::charge_status Computed by app.refresh_charge_status() from allocations and adjustments.
insurance_claim_id uuid
inspection_id uuid
payout_id uuid
created_by uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
charges_amount_positive CHECK ((amount > 0))
charges_billing_day_needs_rental CHECK (((billing_day IS NULL) OR (rental_id IS NOT NULL)))
charges_company_amount_check CHECK ((company_amount >= 0))
charges_due_after_charge CHECK ((due_date >= charge_date))
charges_charge_type_id_fkey FOREIGN KEY (charge_type_id) REFERENCES charge_types(id)
charges_created_by_fkey FOREIGN KEY (created_by) REFERENCES profiles(id)
charges_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id)
charges_inspection_id_fkey FOREIGN KEY (inspection_id) REFERENCES inspections(id)
charges_insurance_claim_id_fkey FOREIGN KEY (insurance_claim_id) REFERENCES insurance_claims(id)
charges_legal_entity_id_fkey FOREIGN KEY (legal_entity_id) REFERENCES legal_entities(id)
charges_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
charges_payout_id_fkey FOREIGN KEY (payout_id) REFERENCES payouts(id)
charges_rental_id_fkey FOREIGN KEY (rental_id) REFERENCES rentals(id)
charges_pkey PRIMARY KEY (id)
Index Definition
charges_charge_type_id_fk_idx CREATE INDEX charges_charge_type_id_fk_idx ON public.charges USING btree (charge_type_id)
charges_created_by_fk_idx CREATE INDEX charges_created_by_fk_idx ON public.charges USING btree (created_by)
charges_driver_status_idx CREATE INDEX charges_driver_status_idx ON public.charges USING btree (driver_id, status, due_date)
charges_inspection_id_fk_idx CREATE INDEX charges_inspection_id_fk_idx ON public.charges USING btree (inspection_id)
charges_insurance_claim_id_fk_idx CREATE INDEX charges_insurance_claim_id_fk_idx ON public.charges USING btree (insurance_claim_id)
charges_legal_entity_id_fk_idx CREATE INDEX charges_legal_entity_id_fk_idx ON public.charges USING btree (legal_entity_id)
charges_one_rent_per_day CREATE UNIQUE INDEX charges_one_rent_per_day ON public.charges USING btree (rental_id, billing_day) WHERE (billing_day IS NOT NULL)
charges_organization_id_fk_idx CREATE INDEX charges_organization_id_fk_idx ON public.charges USING btree (organization_id)
charges_payout_id_fk_idx CREATE INDEX charges_payout_id_fk_idx ON public.charges USING btree (payout_id)

Triggers: audit_row (app.audit_row), guard_inspection (app.guard_charge_inspection), guard_status (app.guard_charge_status), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
called_by uuid
called_at timestamp with time zone not null now()
outcome call_outcome not null
promised_amount bigint
promised_on date
note text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
collection_calls_promise_date CHECK (((outcome <> 'promised'::call_outcome) OR (promised_on IS NOT NULL)))
collection_calls_promised_amount_check CHECK ((promised_amount > 0))
collection_calls_called_by_fkey FOREIGN KEY (called_by) REFERENCES profiles(id)
collection_calls_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id)
collection_calls_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
collection_calls_pkey PRIMARY KEY (id)
Index Definition
collection_calls_called_by_fk_idx CREATE INDEX collection_calls_called_by_fk_idx ON public.collection_calls USING btree (called_by)
collection_calls_driver_id_fk_idx CREATE INDEX collection_calls_driver_id_fk_idx ON public.collection_calls USING btree (driver_id)
collection_calls_organization_id_fk_idx CREATE INDEX collection_calls_organization_id_fk_idx ON public.collection_calls USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
legal_entity_id uuid not null
label text not null
bank text not null
account_number text not null
account_name text not null
is_active boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
company_bank_accounts_legal_entity_id_fkey FOREIGN KEY (legal_entity_id) REFERENCES legal_entities(id)
company_bank_accounts_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
company_bank_accounts_pkey PRIMARY KEY (id)
company_bank_accounts_number_unique UNIQUE (organization_id, bank, account_number)
Index Definition
company_bank_accounts_legal_entity_id_fk_idx CREATE INDEX company_bank_accounts_legal_entity_id_fk_idx ON public.company_bank_accounts USING btree (legal_entity_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
legal_entity_id uuid not null
platform ride_platform not null
name text not null
version smallint not null 1
body text not null
is_active boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
contract_templates_body_no_inline_files CHECK ((NOT app.has_inline_file(body)))
contract_templates_version_check CHECK ((version > 0))
contract_templates_legal_entity_id_fkey FOREIGN KEY (legal_entity_id) REFERENCES legal_entities(id)
contract_templates_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
contract_templates_pkey PRIMARY KEY (id)
contract_templates_version_unique UNIQUE (organization_id, legal_entity_id, platform, version)
Index Definition
contract_templates_legal_entity_id_fk_idx CREATE INDEX contract_templates_legal_entity_id_fk_idx ON public.contract_templates USING btree (legal_entity_id)
contract_templates_one_active CREATE UNIQUE INDEX contract_templates_one_active ON public.contract_templates USING btree (organization_id, legal_entity_id, platform) WHERE is_active

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
number text not null
rental_id uuid not null
template_id uuid not null
status agreement_status not null 'draft'::agreement_status
effective_on date not null
term_months smallint 6
ends_on date
admin_fee bigint not null 0
billing_frequency billing_frequency not null 'daily'::billing_frequency
document_path storage_path
signed_file_path storage_path
driver_signed_at timestamp with time zone
company_signed_by uuid
company_signed_at timestamp with time zone
renews_contract_id uuid
legacy_updated_at timestamp with time zone v1's contracts.updated_at: v1 edits a contract in place, so its last edit (D84, R-RNT-70). Written by the migration, read by nobody in v2 (R-RNT-71).
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
contracts_admin_fee_check CHECK ((admin_fee >= 0))
contracts_dates CHECK (((ends_on IS NULL) OR (ends_on >= effective_on)))
contracts_term_months_check CHECK ((term_months > 0))
contracts_company_signed_by_fkey FOREIGN KEY (company_signed_by) REFERENCES profiles(id)
contracts_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
contracts_renews_contract_id_fkey FOREIGN KEY (renews_contract_id) REFERENCES contracts(id)
contracts_rental_id_fkey FOREIGN KEY (rental_id) REFERENCES rentals(id)
contracts_template_id_fkey FOREIGN KEY (template_id) REFERENCES contract_templates(id)
contracts_pkey PRIMARY KEY (id)
contracts_number_unique UNIQUE (organization_id, number)
Index Definition
contracts_company_signed_by_fk_idx CREATE INDEX contracts_company_signed_by_fk_idx ON public.contracts USING btree (company_signed_by)
contracts_renews_contract_id_fk_idx CREATE INDEX contracts_renews_contract_id_fk_idx ON public.contracts USING btree (renews_contract_id)
contracts_rental_id_fk_idx CREATE INDEX contracts_rental_id_fk_idx ON public.contracts USING btree (rental_id)
contracts_template_id_fk_idx CREATE INDEX contracts_template_id_fk_idx ON public.contracts USING btree (template_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
debt_letter_id uuid not null
charge_id uuid not null
legacy_amount bigint
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
debt_letter_items_legacy_amount_check CHECK ((legacy_amount >= 0))
debt_letter_items_charge_id_fkey FOREIGN KEY (charge_id) REFERENCES charges(id)
debt_letter_items_debt_letter_id_fkey FOREIGN KEY (debt_letter_id) REFERENCES debt_letters(id) ON DELETE CASCADE
debt_letter_items_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
debt_letter_items_pkey PRIMARY KEY (id)
debt_letter_items_unique UNIQUE (debt_letter_id, charge_id)
Index Definition
debt_letter_items_charge_id_fk_idx CREATE INDEX debt_letter_items_charge_id_fk_idx ON public.debt_letter_items USING btree (charge_id)
debt_letter_items_organization_id_fk_idx CREATE INDEX debt_letter_items_organization_id_fk_idx ON public.debt_letter_items USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
number text not null
driver_id uuid not null
rental_id uuid
issued_on date not null
due_on date not null
status letter_status not null 'draft'::letter_status
issued_by uuid
notes text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
debt_letters_dates CHECK ((due_on >= issued_on))
debt_letters_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id)
debt_letters_issued_by_fkey FOREIGN KEY (issued_by) REFERENCES profiles(id)
debt_letters_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
debt_letters_rental_id_fkey FOREIGN KEY (rental_id) REFERENCES rentals(id)
debt_letters_pkey PRIMARY KEY (id)
debt_letters_number_unique UNIQUE (organization_id, number)
Index Definition
debt_letters_driver_id_fk_idx CREATE INDEX debt_letters_driver_id_fk_idx ON public.debt_letters USING btree (driver_id)
debt_letters_issued_by_fk_idx CREATE INDEX debt_letters_issued_by_fk_idx ON public.debt_letters USING btree (issued_by)
debt_letters_rental_id_fk_idx CREATE INDEX debt_letters_rental_id_fk_idx ON public.debt_letters USING btree (rental_id)

Triggers: audit_row (app.audit_row), default_issued_on (app.default_debt_letters_issued_on), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
legal_entity_id uuid
kind doc_kind not null
period text not null
last_no integer not null 0
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
document_sequences_last_no_check CHECK ((last_no >= 0))
document_sequences_period_format CHECK ((period ~ '^[0-9]{4}(-[0-9]{2})?$'::text))
document_sequences_legal_entity_id_fkey FOREIGN KEY (legal_entity_id) REFERENCES legal_entities(id)
document_sequences_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
document_sequences_pkey PRIMARY KEY (id)
document_sequences_unique UNIQUE NULLS NOT DISTINCT (organization_id, legal_entity_id, kind, period)
Index Definition
document_sequences_legal_entity_id_fk_idx CREATE INDEX document_sequences_legal_entity_id_fk_idx ON public.document_sequences USING btree (legal_entity_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
kind address_kind not null
street text not null
rt smallint
rw smallint
kelurahan_desa text
kecamatan text
kota_kabupaten text
postal_code character(5)
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
driver_addresses_postal_code_check CHECK ((postal_code ~ '^[0-9]{5}$'::text))
driver_addresses_rt_check CHECK ((rt >= 0))
driver_addresses_rw_check CHECK ((rw >= 0))
driver_addresses_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id) ON DELETE CASCADE
driver_addresses_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
driver_addresses_pkey PRIMARY KEY (id)
driver_addresses_kind_unique UNIQUE (driver_id, kind)
Index Definition
driver_addresses_organization_id_fk_idx CREATE INDEX driver_addresses_organization_id_fk_idx ON public.driver_addresses USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
doc_type driver_doc_type not null
doc_number text
storage_path storage_path
verified_at timestamp with time zone
expires_on date
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
driver_documents_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id) ON DELETE CASCADE
driver_documents_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
driver_documents_pkey PRIMARY KEY (id)
Index Definition
driver_documents_driver_id_fk_idx CREATE INDEX driver_documents_driver_id_fk_idx ON public.driver_documents USING btree (driver_id)
driver_documents_organization_id_fk_idx CREATE INDEX driver_documents_organization_id_fk_idx ON public.driver_documents USING btree (organization_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
full_name text not null
relationship text not null
phone text not null
is_primary boolean not null false
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
driver_emergency_contacts_phone_62 CHECK ((phone ~ '^628[0-9]{7,12}$'::text))
driver_emergency_contacts_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id) ON DELETE CASCADE
driver_emergency_contacts_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
driver_emergency_contacts_pkey PRIMARY KEY (id)
Index Definition
driver_emergency_contacts_one_primary CREATE UNIQUE INDEX driver_emergency_contacts_one_primary ON public.driver_emergency_contacts USING btree (driver_id) WHERE is_primary
driver_emergency_contacts_organization_id_fk_idx CREATE INDEX driver_emergency_contacts_organization_id_fk_idx ON public.driver_emergency_contacts USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
author_id uuid
body text not null
source note_source not null 'staff'::note_source
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
driver_notes_body_no_inline_files CHECK ((NOT app.has_inline_file(body)))
driver_notes_author_id_fkey FOREIGN KEY (author_id) REFERENCES profiles(id)
driver_notes_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id) ON DELETE CASCADE
driver_notes_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
driver_notes_pkey PRIMARY KEY (id)
Index Definition
driver_notes_author_id_fk_idx CREATE INDEX driver_notes_author_id_fk_idx ON public.driver_notes USING btree (author_id)
driver_notes_driver_id_fk_idx CREATE INDEX driver_notes_driver_id_fk_idx ON public.driver_notes USING btree (driver_id)
driver_notes_organization_id_fk_idx CREATE INDEX driver_notes_organization_id_fk_idx ON public.driver_notes USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
platform ride_platform not null
account_ref text
status platform_account_status not null 'none'::platform_account_status
checked_at timestamp with time zone
checked_by uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
driver_platform_accounts_checked_by_fkey FOREIGN KEY (checked_by) REFERENCES profiles(id)
driver_platform_accounts_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id) ON DELETE CASCADE
driver_platform_accounts_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
driver_platform_accounts_pkey PRIMARY KEY (id)
driver_platform_accounts_unique UNIQUE (driver_id, platform)
Index Definition
driver_platform_accounts_checked_by_fk_idx CREATE INDEX driver_platform_accounts_checked_by_fk_idx ON public.driver_platform_accounts USING btree (checked_by)
driver_platform_accounts_organization_id_fk_idx CREATE INDEX driver_platform_accounts_organization_id_fk_idx ON public.driver_platform_accounts USING btree (organization_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
kind training_kind not null
scheduled_at timestamp with time zone
attended_at timestamp with time zone
trainer_id uuid
result training_result
note text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
driver_trainings_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id) ON DELETE CASCADE
driver_trainings_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
driver_trainings_trainer_id_fkey FOREIGN KEY (trainer_id) REFERENCES profiles(id)
driver_trainings_pkey PRIMARY KEY (id)
Index Definition
driver_trainings_driver_id_fk_idx CREATE INDEX driver_trainings_driver_id_fk_idx ON public.driver_trainings USING btree (driver_id)
driver_trainings_organization_id_fk_idx CREATE INDEX driver_trainings_organization_id_fk_idx ON public.driver_trainings USING btree (organization_id)
driver_trainings_trainer_id_fk_idx CREATE INDEX driver_trainings_trainer_id_fk_idx ON public.driver_trainings USING btree (trainer_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
pool_id uuid not null
profile_id uuid
legacy_id integer
full_name text not null
phone text not null
secondary_phone text
email citext
nik character(16)
birth_date date
birth_place text
education text
occupation text
lead_source_id uuid not null
source_note text
referred_by_driver_id uuid
preferred_platform ride_platform
preferred_model_id uuid
service_tier service_tier
stage driver_stage not null 'lead'::driver_stage Changed only through app.set_driver_stage() and the module actions (P9).
stage_changed_at timestamp with time zone not null now()
on_leave_until date
registered_on date not null
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
drivers_nik_format CHECK ((nik ~ '^[0-9]{16}$'::text))
drivers_phone_62 CHECK ((phone ~ '^628[0-9]{7,12}$'::text))
drivers_secondary_phone_62 CHECK ((secondary_phone ~ '^628[0-9]{7,12}$'::text))
drivers_lead_source_id_fkey FOREIGN KEY (lead_source_id) REFERENCES lead_sources(id)
drivers_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
drivers_pool_id_fkey FOREIGN KEY (pool_id) REFERENCES pools(id)
drivers_preferred_model_id_fkey FOREIGN KEY (preferred_model_id) REFERENCES vehicle_models(id)
drivers_profile_id_fkey FOREIGN KEY (profile_id) REFERENCES profiles(id)
drivers_referred_by_driver_id_fkey FOREIGN KEY (referred_by_driver_id) REFERENCES drivers(id)
drivers_pkey PRIMARY KEY (id)
drivers_legacy_unique UNIQUE (organization_id, legacy_id)
drivers_nik_unique UNIQUE (organization_id, nik)
drivers_organization_id_id_unique UNIQUE (organization_id, id)
drivers_profile_unique UNIQUE (profile_id)
Index Definition
drivers_lead_source_id_fk_idx CREATE INDEX drivers_lead_source_id_fk_idx ON public.drivers USING btree (lead_source_id)
drivers_name_idx CREATE INDEX drivers_name_idx ON public.drivers USING btree (organization_id, lower(full_name))
drivers_phone_idx CREATE INDEX drivers_phone_idx ON public.drivers USING btree (organization_id, phone)
drivers_pool_id_fk_idx CREATE INDEX drivers_pool_id_fk_idx ON public.drivers USING btree (pool_id)
drivers_preferred_model_id_fk_idx CREATE INDEX drivers_preferred_model_id_fk_idx ON public.drivers USING btree (preferred_model_id)
drivers_referred_by_driver_id_fk_idx CREATE INDEX drivers_referred_by_driver_id_fk_idx ON public.drivers USING btree (referred_by_driver_id)
drivers_secondary_phone_idx CREATE INDEX drivers_secondary_phone_idx ON public.drivers USING btree (organization_id, secondary_phone) WHERE (secondary_phone IS NOT NULL)

Triggers: audit_row (app.audit_row), default_registered_on (app.default_drivers_registered_on), guard_stage (app.guard_status_column), secondary_phone_differs (app.check_driver_secondary_phone), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
vehicle_id uuid not null
plate_checked text not null
scanned_at timestamp with time zone not null now()
result etle_scan_result not null
error text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
etle_scans_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
etle_scans_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
etle_scans_pkey PRIMARY KEY (id)
etle_scans_id_org_unique UNIQUE (id, organization_id)
Index Definition
etle_scans_organization_id_fk_idx CREATE INDEX etle_scans_organization_id_fk_idx ON public.etle_scans USING btree (organization_id)
etle_scans_vehicle_id_fk_idx CREATE INDEX etle_scans_vehicle_id_fk_idx ON public.etle_scans USING btree (vehicle_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
vehicle_id uuid not null
rental_id uuid
scan_id uuid
ticket_no text not null
violated_at timestamp with time zone not null
location text
violation text
amount bigint
photo_path storage_path
detail_url text
status etle_status not null 'detected'::etle_status
payer etle_payer not null 'driver'::etle_payer
charge_id uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
etle_violations_amount_check CHECK ((amount >= 0))
etle_violations_charge_fk FOREIGN KEY (charge_id) REFERENCES charges(id)
etle_violations_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
etle_violations_rental_fk FOREIGN KEY (rental_id, organization_id) REFERENCES rentals(id, organization_id)
etle_violations_scan_fk FOREIGN KEY (scan_id, organization_id) REFERENCES etle_scans(id, organization_id)
etle_violations_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
etle_violations_pkey PRIMARY KEY (id)
etle_violations_ticket_unique UNIQUE (organization_id, ticket_no)
Index Definition
etle_violations_charge_id_fk_idx CREATE INDEX etle_violations_charge_id_fk_idx ON public.etle_violations USING btree (charge_id)
etle_violations_rental_id_fk_idx CREATE INDEX etle_violations_rental_id_fk_idx ON public.etle_violations USING btree (rental_id)
etle_violations_scan_id_fk_idx CREATE INDEX etle_violations_scan_id_fk_idx ON public.etle_violations USING btree (scan_id)
etle_violations_vehicle_id_fk_idx CREATE INDEX etle_violations_vehicle_id_fk_idx ON public.etle_violations USING btree (vehicle_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
code text not null
name text not null
address text
phone text
kind garage_kind not null 'general'::garage_kind
is_active boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
garages_phone_62 CHECK ((phone ~ '^62[1-9][0-9]{6,12}$'::text))
garages_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
garages_pkey PRIMARY KEY (id)
garages_code_unique UNIQUE (organization_id, code)
garages_id_org_unique UNIQUE (id, organization_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
gate_pass_id uuid not null
aspect gate_aspect not null
approved_by uuid not null
approved_at timestamp with time zone not null now()
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
gate_pass_approvals_approved_by_fkey FOREIGN KEY (approved_by) REFERENCES profiles(id)
gate_pass_approvals_gate_pass_fk FOREIGN KEY (gate_pass_id, organization_id) REFERENCES gate_passes(id, organization_id) ON DELETE CASCADE
gate_pass_approvals_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
gate_pass_approvals_pkey PRIMARY KEY (id)
gate_pass_approvals_unique UNIQUE (gate_pass_id, aspect)
Index Definition
gate_pass_approvals_approved_by_fk_idx CREATE INDEX gate_pass_approvals_approved_by_fk_idx ON public.gate_pass_approvals USING btree (approved_by)
gate_pass_approvals_organization_id_fk_idx CREATE INDEX gate_pass_approvals_organization_id_fk_idx ON public.gate_pass_approvals USING btree (organization_id)

Triggers: approval_stamp (app.gate_approval_stamp), audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
pool_id uuid not null
vehicle_id uuid
plate_text text not null
rental_id uuid
work_order_id uuid
in_purpose gate_purpose
in_at timestamp with time zone
in_by uuid
in_typed boolean not null false
out_purpose gate_purpose
out_requested_at timestamp with time zone
out_requested_by uuid
team_membership_id uuid
team_reason text
out_at timestamp with time zone
out_by uuid
out_typed boolean not null false
snap_debt bigint not null 0
snap_cp_days smallint
snap_service_due boolean not null false
notes text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
gate_passes_guest CHECK ((((('guest'::gate_purpose <> COALESCE(in_purpose, 'rental'::gate_purpose)) AND ('guest'::gate_purpose <> COALESCE(out_purpose, 'rental'::gate_purpose))) OR ((vehicle_id IS NULL) AND (btrim(plate_text) <> ''::text))) AND ((in_purpose IS DISTINCT FROM 'guest'::gate_purpose) OR (out_purpose IS NULL) OR (out_purpose = 'guest'::gate_purpose))))
gate_passes_in_or_out_request CHECK (((in_at IS NOT NULL) OR (out_requested_at IS NOT NULL)))
gate_passes_out_not_return CHECK ((out_purpose IS DISTINCT FROM 'return'::gate_purpose))
gate_passes_out_request_purpose CHECK (((out_requested_at IS NULL) OR (out_purpose IS NOT NULL)))
gate_passes_out_requested CHECK (((out_at IS NULL) OR (out_requested_at IS NOT NULL)))
gate_passes_snap_debt_check CHECK ((snap_debt >= 0))
gate_passes_team CHECK (((out_purpose IS DISTINCT FROM 'team'::gate_purpose) OR ((team_membership_id IS NOT NULL) AND (COALESCE(btrim(team_reason), ''::text) <> ''::text))))
gate_passes_in_by_fkey FOREIGN KEY (in_by) REFERENCES profiles(id)
gate_passes_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
gate_passes_out_by_fkey FOREIGN KEY (out_by) REFERENCES profiles(id)
gate_passes_out_requested_by_fkey FOREIGN KEY (out_requested_by) REFERENCES profiles(id)
gate_passes_pool_fk FOREIGN KEY (pool_id, organization_id) REFERENCES pools(id, organization_id)
gate_passes_rental_fk FOREIGN KEY (rental_id, organization_id) REFERENCES rentals(id, organization_id)
gate_passes_team_membership_fk FOREIGN KEY (team_membership_id, organization_id) REFERENCES memberships(id, organization_id)
gate_passes_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
gate_passes_work_order_fk FOREIGN KEY (work_order_id, vehicle_id, organization_id) REFERENCES work_orders(id, vehicle_id, organization_id)
gate_passes_work_order_org_fk FOREIGN KEY (work_order_id, organization_id) REFERENCES work_orders(id, organization_id)
gate_passes_pkey PRIMARY KEY (id)
gate_passes_id_org_unique UNIQUE (id, organization_id)
Index Definition
gate_passes_in_by_fk_idx CREATE INDEX gate_passes_in_by_fk_idx ON public.gate_passes USING btree (in_by)
gate_passes_organization_id_fk_idx CREATE INDEX gate_passes_organization_id_fk_idx ON public.gate_passes USING btree (organization_id)
gate_passes_out_by_fk_idx CREATE INDEX gate_passes_out_by_fk_idx ON public.gate_passes USING btree (out_by)
gate_passes_out_requested_by_fk_idx CREATE INDEX gate_passes_out_requested_by_fk_idx ON public.gate_passes USING btree (out_requested_by)
gate_passes_pool_id_fk_idx CREATE INDEX gate_passes_pool_id_fk_idx ON public.gate_passes USING btree (pool_id)
gate_passes_rental_id_fk_idx CREATE INDEX gate_passes_rental_id_fk_idx ON public.gate_passes USING btree (rental_id)
gate_passes_team_membership_id_fk_idx CREATE INDEX gate_passes_team_membership_id_fk_idx ON public.gate_passes USING btree (team_membership_id)
gate_passes_vehicle_open_unique CREATE UNIQUE INDEX gate_passes_vehicle_open_unique ON public.gate_passes USING btree (vehicle_id) WHERE ((out_at IS NULL) AND (vehicle_id IS NOT NULL))
gate_passes_work_order_id_fk_idx CREATE INDEX gate_passes_work_order_id_fk_idx ON public.gate_passes USING btree (work_order_id)

Triggers: audit_row (app.audit_row), default_pool (app.default_pool_from_vehicle), gate_pass_stamp (app.gate_pass_stamp), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
vehicle_id uuid
slot gps_slot not null 'primary'::gps_slot
is_active boolean not null true
provider text not null 'easygo'::text
external_id text not null
imei text
installed_on date
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
gps_devices_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
gps_devices_provider_fkey FOREIGN KEY (provider) REFERENCES gps_providers(code)
gps_devices_vehicle_id_fkey FOREIGN KEY (vehicle_id) REFERENCES vehicles(id)
gps_devices_pkey PRIMARY KEY (id)
gps_devices_external_unique UNIQUE (organization_id, provider, external_id)
gps_devices_vehicle_slot_unique UNIQUE (vehicle_id, slot)
Index Definition
gps_devices_linked_once CREATE UNIQUE INDEX gps_devices_linked_once ON public.gps_devices USING btree (provider, external_id) WHERE (vehicle_id IS NOT NULL)
gps_devices_one_active CREATE UNIQUE INDEX gps_devices_one_active ON public.gps_devices USING btree (vehicle_id) WHERE is_active

Triggers: audit_row (app.audit_row), backup_starts_on_standby (app.backup_starts_on_standby), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id bigint not null
organization_id uuid not null
gps_device_id uuid not null
recorded_at timestamp with time zone not null
location geography(Point,4326) not null
speed_kmh numeric(6,2)
raw jsonb not null One element exactly as the provider sent it, a JSON object; nothing filters or joins on its keys (R-GPS-08, D32).
Constraint Definition
gps_positions_raw_object CHECK ((jsonb_typeof(raw) = 'object'::text))
gps_positions_speed_kmh_check CHECK ((speed_kmh >= (0)::numeric))
gps_positions_gps_device_id_fkey FOREIGN KEY (gps_device_id) REFERENCES gps_devices(id) ON DELETE CASCADE
gps_positions_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
gps_positions_pkey PRIMARY KEY (id)
gps_positions_device_time_unique UNIQUE (gps_device_id, recorded_at)
Index Definition
gps_positions_device_time_idx CREATE INDEX gps_positions_device_time_idx ON public.gps_positions USING btree (gps_device_id, recorded_at DESC)
gps_positions_organization_id_fk_idx CREATE INDEX gps_positions_organization_id_fk_idx ON public.gps_positions USING btree (organization_id)
gps_positions_recorded_idx CREATE INDEX gps_positions_recorded_idx ON public.gps_positions USING btree (recorded_at)
Column Type Null Default Note
code text not null
transport text not null 'pull'::text
pull_interval_seconds integer not null 15
base_url text
organization_id uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
gps_providers_interval CHECK ((((pull_interval_seconds >= 1) AND (pull_interval_seconds <= 59)) OR (((pull_interval_seconds >= 60) AND (pull_interval_seconds <= 3540)) AND ((pull_interval_seconds % 60) = 0))))
gps_providers_transport_check CHECK ((transport = 'pull'::text))
gps_providers_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
gps_providers_pkey PRIMARY KEY (code)
Index Definition
gps_providers_organization_id_fk_idx CREATE INDEX gps_providers_organization_id_fk_idx ON public.gps_providers USING btree (organization_id)

Triggers: gps_schedule (app.gps_schedule), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id bigint not null
organization_id uuid
provider text not null
started_at timestamp with time zone not null now()
status text not null 'pending'::text
request_id bigint
body jsonb The answer of one pull as it arrived, for finding a fault in a provider; deleted with the pull at 90 days (R-GPS-13).
rows_ingested integer not null 0
rows_skipped integer not null 0
rows_rejected integer not null 0
error text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
gps_pulls_status_check CHECK ((status = ANY (ARRAY['pending'::text, 'succeeded'::text, 'failed'::text])))
gps_pulls_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
gps_pulls_provider_fkey FOREIGN KEY (provider) REFERENCES gps_providers(code)
gps_pulls_pkey PRIMARY KEY (id)
Index Definition
gps_pulls_organization_id_fk_idx CREATE INDEX gps_pulls_organization_id_fk_idx ON public.gps_pulls USING btree (organization_id)
gps_pulls_pending_idx CREATE INDEX gps_pulls_pending_idx ON public.gps_pulls USING btree (id) WHERE (status = 'pending'::text)
gps_pulls_provider_fk_idx CREATE INDEX gps_pulls_provider_fk_idx ON public.gps_pulls USING btree (provider)
gps_pulls_started_idx CREATE INDEX gps_pulls_started_idx ON public.gps_pulls USING btree (started_at)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
inspection_id uuid not null
panel_id uuid not null
description text
photo_path storage_path
charge_driver boolean not null true
charge_decided_by uuid
charge_note text
work_order_id uuid
charge_id uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
inspection_damages_waiver_by CHECK ((charge_driver OR (charge_decided_by IS NOT NULL)))
inspection_damages_charge_decided_by_fkey FOREIGN KEY (charge_decided_by) REFERENCES profiles(id)
inspection_damages_charge_fk FOREIGN KEY (charge_id) REFERENCES charges(id)
inspection_damages_inspection_fk FOREIGN KEY (inspection_id, organization_id) REFERENCES inspections(id, organization_id) ON DELETE CASCADE
inspection_damages_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
inspection_damages_panel_fk FOREIGN KEY (panel_id, organization_id) REFERENCES body_panels(id, organization_id)
inspection_damages_work_order_fk FOREIGN KEY (work_order_id, organization_id) REFERENCES work_orders(id, organization_id)
inspection_damages_pkey PRIMARY KEY (id)
inspection_damages_id_org_unique UNIQUE (id, organization_id)
Index Definition
inspection_damages_charge_decided_by_fk_idx CREATE INDEX inspection_damages_charge_decided_by_fk_idx ON public.inspection_damages USING btree (charge_decided_by)
inspection_damages_charge_id_fk_idx CREATE INDEX inspection_damages_charge_id_fk_idx ON public.inspection_damages USING btree (charge_id)
inspection_damages_inspection_id_fk_idx CREATE INDEX inspection_damages_inspection_id_fk_idx ON public.inspection_damages USING btree (inspection_id)
inspection_damages_organization_id_fk_idx CREATE INDEX inspection_damages_organization_id_fk_idx ON public.inspection_damages USING btree (organization_id)
inspection_damages_panel_id_fk_idx CREATE INDEX inspection_damages_panel_id_fk_idx ON public.inspection_damages USING btree (panel_id)
inspection_damages_work_order_id_fk_idx CREATE INDEX inspection_damages_work_order_id_fk_idx ON public.inspection_damages USING btree (work_order_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
code text not null
name text not null
name_en text
section item_section not null
answer item_answer not null
applies_to item_applies_to not null 'all'::item_applies_to
vehicle_class vehicle_class
is_system boolean not null false
is_active boolean not null true
sort_order smallint not null 100
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
inspection_item_types_code_format CHECK ((code ~ '^[a-z0-9_]+$'::text))
inspection_item_types_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
inspection_item_types_pkey PRIMARY KEY (id)
inspection_item_types_code_unique UNIQUE (organization_id, code)
inspection_item_types_id_org_unique UNIQUE (id, organization_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
inspection_id uuid not null
item_type_id uuid not null
grade item_grade
present boolean
value text
note text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
inspection_items_note_when_not_green CHECK (((grade IS NULL) OR (grade = 'h'::item_grade) OR (note IS NOT NULL)))
inspection_items_inspection_fk FOREIGN KEY (inspection_id, organization_id) REFERENCES inspections(id, organization_id) ON DELETE CASCADE
inspection_items_item_type_fk FOREIGN KEY (item_type_id, organization_id) REFERENCES inspection_item_types(id, organization_id)
inspection_items_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
inspection_items_pkey PRIMARY KEY (id)
inspection_items_unique UNIQUE (inspection_id, item_type_id)
Index Definition
inspection_items_item_type_id_fk_idx CREATE INDEX inspection_items_item_type_id_fk_idx ON public.inspection_items USING btree (item_type_id)
inspection_items_organization_id_fk_idx CREATE INDEX inspection_items_organization_id_fk_idx ON public.inspection_items USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
inspection_id uuid not null
kind photo_kind not null
damage_id uuid
storage_path storage_path not null
taken_at timestamp with time zone not null now()
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
inspection_photos_damage_fk FOREIGN KEY (damage_id, organization_id) REFERENCES inspection_damages(id, organization_id) ON DELETE CASCADE
inspection_photos_inspection_fk FOREIGN KEY (inspection_id, organization_id) REFERENCES inspections(id, organization_id) ON DELETE CASCADE
inspection_photos_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
inspection_photos_pkey PRIMARY KEY (id)
Index Definition
inspection_photos_damage_id_fk_idx CREATE INDEX inspection_photos_damage_id_fk_idx ON public.inspection_photos USING btree (damage_id)
inspection_photos_inspection_id_fk_idx CREATE INDEX inspection_photos_inspection_id_fk_idx ON public.inspection_photos USING btree (inspection_id)
inspection_photos_organization_id_fk_idx CREATE INDEX inspection_photos_organization_id_fk_idx ON public.inspection_photos USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
pool_id uuid not null
vehicle_id uuid not null
rental_id uuid
kind inspection_kind not null
inspected_at timestamp with time zone not null now()
inspector_id uuid
odometer_km integer
fuel_level smallint
battery_pct smallint
return_reason return_reason
outcome inspection_outcome
bastk_number text
gate_pass_id uuid
inspector_sign_path storage_path
driver_sign_path storage_path
notes text
document_path storage_path
legacy_data jsonb
work_order_id uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
inspections_battery_pct_check CHECK (((battery_pct >= 0) AND (battery_pct <= 100)))
inspections_fuel_level_check CHECK (((fuel_level >= 0) AND (fuel_level <= 100)))
inspections_legacy_data_no_inline_files CHECK ((NOT app.has_inline_file((legacy_data)::text)))
inspections_odometer_km_check CHECK ((odometer_km >= 0))
inspections_outcome_preparation CHECK (((kind = 'preparation'::inspection_kind) = (outcome IS NOT NULL)))
inspections_return_reason CHECK (((kind = 'return'::inspection_kind) OR (return_reason IS NULL)))
inspections_work_order_kind CHECK (((work_order_id IS NULL) OR (kind = ANY (ARRAY['return'::inspection_kind, 'preparation'::inspection_kind]))))
inspections_gate_pass_fk FOREIGN KEY (gate_pass_id, organization_id) REFERENCES gate_passes(id, organization_id)
inspections_inspector_id_fkey FOREIGN KEY (inspector_id) REFERENCES profiles(id)
inspections_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
inspections_pool_fk FOREIGN KEY (pool_id, organization_id) REFERENCES pools(id, organization_id)
inspections_rental_fk FOREIGN KEY (rental_id, organization_id) REFERENCES rentals(id, organization_id)
inspections_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
inspections_work_order_fk FOREIGN KEY (work_order_id, vehicle_id, organization_id) REFERENCES work_orders(id, vehicle_id, organization_id)
inspections_pkey PRIMARY KEY (id)
inspections_bastk_unique UNIQUE (organization_id, bastk_number)
inspections_id_org_unique UNIQUE (id, organization_id)
Index Definition
inspections_gate_pass_id_fk_idx CREATE INDEX inspections_gate_pass_id_fk_idx ON public.inspections USING btree (gate_pass_id)
inspections_inspector_id_fk_idx CREATE INDEX inspections_inspector_id_fk_idx ON public.inspections USING btree (inspector_id)
inspections_pool_id_fk_idx CREATE INDEX inspections_pool_id_fk_idx ON public.inspections USING btree (pool_id)
inspections_rental_id_fk_idx CREATE INDEX inspections_rental_id_fk_idx ON public.inspections USING btree (rental_id)
inspections_vehicle_kind_idx CREATE INDEX inspections_vehicle_kind_idx ON public.inspections USING btree (vehicle_id, kind, inspected_at DESC)
inspections_work_order_id_fk_idx CREATE INDEX inspections_work_order_id_fk_idx ON public.inspections USING btree (work_order_id)

Triggers: audit_row (app.audit_row), default_pool (app.default_pool_from_vehicle), return_reason (app.inspection_return_reason), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
claim_id uuid not null
kind claim_photo_kind not null
storage_path storage_path not null
taken_at timestamp with time zone not null now()
uploaded_by uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
insurance_claim_photos_claim_fk FOREIGN KEY (claim_id, organization_id) REFERENCES insurance_claims(id, organization_id)
insurance_claim_photos_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
insurance_claim_photos_uploaded_by_fkey FOREIGN KEY (uploaded_by) REFERENCES profiles(id)
insurance_claim_photos_pkey PRIMARY KEY (id)
Index Definition
insurance_claim_photos_claim_idx CREATE INDEX insurance_claim_photos_claim_idx ON public.insurance_claim_photos USING btree (claim_id)
insurance_claim_photos_organization_id_fk_idx CREATE INDEX insurance_claim_photos_organization_id_fk_idx ON public.insurance_claim_photos USING btree (organization_id)
insurance_claim_photos_uploaded_by_fk_idx CREATE INDEX insurance_claim_photos_uploaded_by_fk_idx ON public.insurance_claim_photos USING btree (uploaded_by)

Triggers: audit_row (app.audit_row), kind_only (app.claim_photo_kind_only), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
claim_code text not null
vehicle_id uuid not null
policy_id uuid
insurer_id uuid
garage_id uuid
driver_id uuid
accident_on date
severity laka_type
category claim_category
panel_count smallint
driver_share bigint
status claim_status not null 'submitted'::claim_status
work_order_id uuid
spk_on date
in_garage_on date
completed_on date
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
insurance_claims_driver_share_check CHECK ((driver_share >= 0))
insurance_claims_panel_count_check CHECK ((panel_count >= 0))
insurance_claims_driver_fk FOREIGN KEY (driver_id, organization_id) REFERENCES drivers(id, organization_id)
insurance_claims_garage_fk FOREIGN KEY (garage_id, organization_id) REFERENCES garages(id, organization_id)
insurance_claims_insurer_fk FOREIGN KEY (insurer_id, organization_id) REFERENCES insurers(id, organization_id)
insurance_claims_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
insurance_claims_partner_garage_fk FOREIGN KEY (insurer_id, garage_id) REFERENCES insurer_garages(insurer_id, garage_id)
insurance_claims_policy_fk FOREIGN KEY (policy_id, organization_id) REFERENCES insurance_policies(id, organization_id)
insurance_claims_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
insurance_claims_work_order_fk FOREIGN KEY (work_order_id, vehicle_id, organization_id) REFERENCES work_orders(id, vehicle_id, organization_id)
insurance_claims_pkey PRIMARY KEY (id)
insurance_claims_code_unique UNIQUE (organization_id, claim_code)
insurance_claims_id_org_unique UNIQUE (id, organization_id)
Index Definition
insurance_claims_driver_id_fk_idx CREATE INDEX insurance_claims_driver_id_fk_idx ON public.insurance_claims USING btree (driver_id)
insurance_claims_garage_id_fk_idx CREATE INDEX insurance_claims_garage_id_fk_idx ON public.insurance_claims USING btree (garage_id)
insurance_claims_insurer_id_fk_idx CREATE INDEX insurance_claims_insurer_id_fk_idx ON public.insurance_claims USING btree (insurer_id)
insurance_claims_policy_id_fk_idx CREATE INDEX insurance_claims_policy_id_fk_idx ON public.insurance_claims USING btree (policy_id)
insurance_claims_vehicle_id_fk_idx CREATE INDEX insurance_claims_vehicle_id_fk_idx ON public.insurance_claims USING btree (vehicle_id)
insurance_claims_work_order_id_fk_idx CREATE INDEX insurance_claims_work_order_id_fk_idx ON public.insurance_claims USING btree (work_order_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
vehicle_id uuid not null
insurer_id uuid not null
policy_number text not null
coverage text
starts_on date not null
ends_on date not null
premium bigint Whole rupiah, above zero; empty when not known (R-ASR-19).
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
insurance_policies_dates CHECK ((ends_on >= starts_on))
insurance_policies_premium_positive CHECK ((premium > 0))
insurance_policies_insurer_id_fkey FOREIGN KEY (insurer_id) REFERENCES insurers(id)
insurance_policies_insurer_org_fk FOREIGN KEY (insurer_id, organization_id) REFERENCES insurers(id, organization_id)
insurance_policies_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
insurance_policies_vehicle_id_fkey FOREIGN KEY (vehicle_id) REFERENCES vehicles(id)
insurance_policies_pkey PRIMARY KEY (id)
insurance_policies_id_org_unique UNIQUE (id, organization_id)
insurance_policies_number_unique UNIQUE (organization_id, insurer_id, policy_number)
Index Definition
insurance_policies_insurer_id_fk_idx CREATE INDEX insurance_policies_insurer_id_fk_idx ON public.insurance_policies USING btree (insurer_id)
insurance_policies_insurer_org_idx CREATE INDEX insurance_policies_insurer_org_idx ON public.insurance_policies USING btree (insurer_id, organization_id)
insurance_policies_vehicle_idx CREATE INDEX insurance_policies_vehicle_idx ON public.insurance_policies USING btree (vehicle_id, ends_on DESC)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
insurer_id uuid not null
garage_id uuid not null
partner_since date
is_active boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
insurer_garages_garage_fk FOREIGN KEY (garage_id, organization_id) REFERENCES garages(id, organization_id)
insurer_garages_insurer_fk FOREIGN KEY (insurer_id, organization_id) REFERENCES insurers(id, organization_id)
insurer_garages_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
insurer_garages_pkey PRIMARY KEY (id)
insurer_garages_unique UNIQUE (insurer_id, garage_id)
Index Definition
insurer_garages_garage_id_fk_idx CREATE INDEX insurer_garages_garage_id_fk_idx ON public.insurer_garages USING btree (garage_id)
insurer_garages_organization_id_fk_idx CREATE INDEX insurer_garages_organization_id_fk_idx ON public.insurer_garages USING btree (organization_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
name text not null
phone text
website text
is_active boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
insurers_phone_62 CHECK ((phone ~ '^62[1-9][0-9]{6,12}$'::text))
insurers_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
insurers_pkey PRIMARY KEY (id)
insurers_id_org_unique UNIQUE (id, organization_id)
insurers_name_unique UNIQUE (organization_id, name)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
organization_id uuid not null
invitation_id uuid not null
rental_company_id uuid not null
created_at timestamp with time zone not null now()
Constraint Definition
invitation_rental_companies_invitation_fk FOREIGN KEY (invitation_id, organization_id) REFERENCES invitations(id, organization_id) ON DELETE CASCADE
invitation_rental_companies_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
invitation_rental_companies_rental_company_fk FOREIGN KEY (rental_company_id, organization_id) REFERENCES rental_companies(id, organization_id) ON DELETE RESTRICT
invitation_rental_companies_pkey PRIMARY KEY (invitation_id, rental_company_id)
Index Definition
invitation_rental_companies_organization_id_fk_idx CREATE INDEX invitation_rental_companies_organization_id_fk_idx ON public.invitation_rental_companies USING btree (organization_id)
invitation_rental_companies_rental_company_id_fk_idx CREATE INDEX invitation_rental_companies_rental_company_id_fk_idx ON public.invitation_rental_companies USING btree (rental_company_id)

Triggers: audit_row (app.audit_row), rental_companies_with_flag (app.refuse_invitation_rental_companies_with_flag).

Staff invitations (D98): one email, one role, one pool. Pending until the invite link is opened; an expired one is pending past expires_at.

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
email citext not null
pool_id uuid not null
role_id uuid not null
invited_by uuid not null
all_rental_companies boolean not null false
status invitation_status not null 'pending'::invitation_status
void_reason invitation_void_reason
expires_at timestamp with time zone not null
accepted_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
invitations_accepted_has_time CHECK (((status = 'accepted'::invitation_status) = (accepted_at IS NOT NULL)))
invitations_voided_has_reason CHECK (((status = 'voided'::invitation_status) = (void_reason IS NOT NULL)))
invitations_invited_by_fkey FOREIGN KEY (invited_by) REFERENCES profiles(id)
invitations_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
invitations_pool_id_fkey FOREIGN KEY (pool_id) REFERENCES pools(id)
invitations_role_id_fkey FOREIGN KEY (role_id) REFERENCES roles(id)
invitations_pkey PRIMARY KEY (id)
invitations_id_org_unique UNIQUE (id, organization_id)
Index Definition
invitations_invited_by_fk_idx CREATE INDEX invitations_invited_by_fk_idx ON public.invitations USING btree (invited_by)
invitations_one_pending CREATE UNIQUE INDEX invitations_one_pending ON public.invitations USING btree (email) WHERE (status = 'pending'::invitation_status)
invitations_organization_id_fk_idx CREATE INDEX invitations_organization_id_fk_idx ON public.invitations USING btree (organization_id)
invitations_pool_id_fk_idx CREATE INDEX invitations_pool_id_fk_idx ON public.invitations USING btree (pool_id)
invitations_role_id_fk_idx CREATE INDEX invitations_role_id_fk_idx ON public.invitations USING btree (role_id)

Triggers: audit_row (app.audit_row), rental_companies_with_flag (app.refuse_invitation_rental_companies_with_flag), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
code text not null
name text not null
name_en text
channel lead_channel not null
needs_note boolean not null false
is_system boolean not null false
is_active boolean not null true
sort_order smallint not null 100
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
lead_sources_code_format CHECK ((code ~ '^[a-z_]+$'::text))
lead_sources_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
lead_sources_pkey PRIMARY KEY (id)
lead_sources_code_unique UNIQUE (organization_id, code)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
code text not null
legal_name text not null
address text
is_active boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
legal_entities_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
legal_entities_pkey PRIMARY KEY (id)
legal_entities_code_unique UNIQUE (organization_id, code)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
vehicle_id uuid not null
work_order_id uuid
garage_id uuid
kind maintenance_kind not null
mode maintenance_mode not null 'occurred'::maintenance_mode
priority priority_level not null 'medium'::priority_level
problem text not null
action text
estimated_cost bigint
actual_cost bigint
odometer_km integer
next_service_km integer
started_on date not null
completed_on date
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
maintenance_records_actual_cost_check CHECK ((actual_cost >= 0))
maintenance_records_dates CHECK (((completed_on IS NULL) OR (completed_on >= started_on)))
maintenance_records_estimated_cost_check CHECK ((estimated_cost >= 0))
maintenance_records_next_service_km_check CHECK ((next_service_km >= 0))
maintenance_records_odometer_km_check CHECK ((odometer_km >= 0))
maintenance_records_garage_fk FOREIGN KEY (garage_id, organization_id) REFERENCES garages(id, organization_id)
maintenance_records_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
maintenance_records_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
maintenance_records_work_order_fk FOREIGN KEY (work_order_id, vehicle_id, organization_id) REFERENCES work_orders(id, vehicle_id, organization_id)
maintenance_records_pkey PRIMARY KEY (id)
Index Definition
maintenance_records_garage_id_fk_idx CREATE INDEX maintenance_records_garage_id_fk_idx ON public.maintenance_records USING btree (garage_id)
maintenance_records_organization_id_fk_idx CREATE INDEX maintenance_records_organization_id_fk_idx ON public.maintenance_records USING btree (organization_id)
maintenance_records_vehicle_id_fk_idx CREATE INDEX maintenance_records_vehicle_id_fk_idx ON public.maintenance_records USING btree (vehicle_id)
maintenance_records_work_order_id_fk_idx CREATE INDEX maintenance_records_work_order_id_fk_idx ON public.maintenance_records USING btree (work_order_id)

Triggers: default_started_on (app.default_maintenance_records_started_on), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
membership_id uuid not null
permission_code text not null
effect override_effect not null
pool_id uuid not null
reason text
granted_by uuid
delegated boolean not null false
ends_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
member_permission_overrides_delegated_by CHECK (((NOT delegated) OR ((granted_by IS NOT NULL) AND (btrim(COALESCE(reason, ''::text)) <> ''::text))))
member_permission_overrides_delegated_grant CHECK (((NOT delegated) OR (effect = 'grant'::override_effect)))
member_permission_overrides_ends_at CHECK (((ends_at IS NULL) OR delegated))
member_permission_overrides_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES profiles(id)
member_permission_overrides_membership_id_fkey FOREIGN KEY (membership_id) REFERENCES memberships(id) ON DELETE CASCADE
member_permission_overrides_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
member_permission_overrides_permission_code_fkey FOREIGN KEY (permission_code) REFERENCES permissions(code) ON UPDATE CASCADE
member_permission_overrides_pool_id_fkey FOREIGN KEY (pool_id) REFERENCES pools(id)
member_permission_overrides_pkey PRIMARY KEY (id)
member_permission_overrides_unique UNIQUE (membership_id, permission_code, pool_id)
Index Definition
member_permission_overrides_granted_by_fk_idx CREATE INDEX member_permission_overrides_granted_by_fk_idx ON public.member_permission_overrides USING btree (granted_by)
member_permission_overrides_organization_id_fk_idx CREATE INDEX member_permission_overrides_organization_id_fk_idx ON public.member_permission_overrides USING btree (organization_id)
member_permission_overrides_permission_code_fk_idx CREATE INDEX member_permission_overrides_permission_code_fk_idx ON public.member_permission_overrides USING btree (permission_code)
member_permission_overrides_pool_id_fk_idx CREATE INDEX member_permission_overrides_pool_id_fk_idx ON public.member_permission_overrides USING btree (pool_id)

Triggers: audit_row (app.audit_row), end_sessions (app.end_sessions_on_access_change), guard_delegable (app.guard_delegable), guard_grant_held (app.guard_grant_held), guard_last_user_manager (app.guard_last_user_manager), set_updated_at (app.set_updated_at).

Column Type Null Default Note
organization_id uuid not null
membership_id uuid not null
rental_company_id uuid not null
created_at timestamp with time zone not null now()
Constraint Definition
member_rental_companies_membership_fk FOREIGN KEY (membership_id, organization_id) REFERENCES memberships(id, organization_id) ON DELETE CASCADE
member_rental_companies_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
member_rental_companies_rental_company_fk FOREIGN KEY (rental_company_id, organization_id) REFERENCES rental_companies(id, organization_id) ON DELETE CASCADE
member_rental_companies_pkey PRIMARY KEY (membership_id, rental_company_id)
Index Definition
member_rental_companies_organization_id_fk_idx CREATE INDEX member_rental_companies_organization_id_fk_idx ON public.member_rental_companies USING btree (organization_id)
member_rental_companies_rental_company_id_fk_idx CREATE INDEX member_rental_companies_rental_company_id_fk_idx ON public.member_rental_companies USING btree (rental_company_id)

Triggers: audit_row (app.audit_row), rental_companies_with_flag (app.refuse_rental_companies_with_flag).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
membership_id uuid not null
role_id uuid not null
pool_id uuid not null
granted_by uuid
granted_at timestamp with time zone not null now()
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
member_roles_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES profiles(id)
member_roles_membership_id_fkey FOREIGN KEY (membership_id) REFERENCES memberships(id) ON DELETE CASCADE
member_roles_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
member_roles_pool_id_fkey FOREIGN KEY (pool_id) REFERENCES pools(id)
member_roles_role_id_fkey FOREIGN KEY (role_id) REFERENCES roles(id)
member_roles_pkey PRIMARY KEY (id)
member_roles_unique UNIQUE (membership_id, role_id, pool_id)
Index Definition
member_roles_granted_by_fk_idx CREATE INDEX member_roles_granted_by_fk_idx ON public.member_roles USING btree (granted_by)
member_roles_organization_id_fk_idx CREATE INDEX member_roles_organization_id_fk_idx ON public.member_roles USING btree (organization_id)
member_roles_pool_id_fk_idx CREATE INDEX member_roles_pool_id_fk_idx ON public.member_roles USING btree (pool_id)
member_roles_role_id_fk_idx CREATE INDEX member_roles_role_id_fk_idx ON public.member_roles USING btree (role_id)

Triggers: audit_row (app.audit_row), end_sessions (app.end_sessions_on_access_change), guard_grant_held (app.guard_grant_held), guard_last_user_manager (app.guard_last_user_manager), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
profile_id uuid not null
status membership_status not null 'active'::membership_status
all_rental_companies boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
memberships_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
memberships_profile_id_fkey FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE
memberships_pkey PRIMARY KEY (id)
memberships_id_org_unique UNIQUE (id, organization_id)
memberships_unique UNIQUE (organization_id, profile_id)
Index Definition
memberships_profile_id_fk_idx CREATE INDEX memberships_profile_id_fk_idx ON public.memberships USING btree (profile_id)

Triggers: audit_row (app.audit_row), end_sessions_on_remove (app.end_sessions_on_membership_change), end_sessions_on_suspend (app.end_sessions_on_membership_change), guard_last_user_manager (app.guard_last_user_manager), rental_companies_with_flag (app.refuse_rental_companies_with_flag), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
membership_id uuid not null
module text
type_code text
delivery notification_delivery not null
min_live_severity notification_severity not null 'info'::notification_severity
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
notification_preferences_module_or_type CHECK (((module IS NULL) <> (type_code IS NULL)))
notification_preferences_membership_fk FOREIGN KEY (membership_id, organization_id) REFERENCES memberships(id, organization_id) ON DELETE CASCADE
notification_preferences_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
notification_preferences_type_code_fkey FOREIGN KEY (type_code) REFERENCES notification_types(code)
notification_preferences_pkey PRIMARY KEY (id)
notification_preferences_unique UNIQUE NULLS NOT DISTINCT (membership_id, module, type_code)
Index Definition
notification_preferences_organization_idx CREATE INDEX notification_preferences_organization_idx ON public.notification_preferences USING btree (organization_id)
notification_preferences_type_code_idx CREATE INDEX notification_preferences_type_code_idx ON public.notification_preferences USING btree (type_code)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
notification_id uuid not null
membership_id uuid not null
read_at timestamp with time zone
dismissed_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
notification_receipts_membership_fk FOREIGN KEY (membership_id, organization_id) REFERENCES memberships(id, organization_id) ON DELETE CASCADE
notification_receipts_notification_fk FOREIGN KEY (notification_id, organization_id) REFERENCES notifications(id, organization_id) ON DELETE CASCADE
notification_receipts_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
notification_receipts_pkey PRIMARY KEY (id)
notification_receipts_unique UNIQUE (notification_id, membership_id)
Index Definition
notification_receipts_membership_idx CREATE INDEX notification_receipts_membership_idx ON public.notification_receipts USING btree (membership_id)
notification_receipts_organization_idx CREATE INDEX notification_receipts_organization_idx ON public.notification_receipts USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
code text not null
module text not null
default_severity notification_severity not null
permission_code text not null
escalates boolean not null false
role_live_from jsonb not null '{"admin": "urgent", "satpam": "action", "viewer": "urgent", "checker": "action", "finance": "action", "asuransi": "action", "admin_fleet": "action", "maintenance": "action", "super_admin": "urgent", "admin_driver": "action", "background_check": "action"}'::jsonb
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
notification_types_code_format CHECK ((code ~ '^[a-z_]+\.[a-z_]+$'::text))
notification_types_role_live_from CHECK (app.role_live_from_valid(role_live_from))
notification_types_permission_code_fkey FOREIGN KEY (permission_code) REFERENCES permissions(code)
notification_types_pkey PRIMARY KEY (code)
Index Definition
notification_types_permission_code_idx CREATE INDEX notification_types_permission_code_idx ON public.notification_types USING btree (permission_code)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
pool_id uuid not null
type_code text not null
subject_table text not null
subject_id uuid not null
severity notification_severity not null
recipient_membership_id uuid
opened_at timestamp with time zone not null now()
acknowledged_by uuid
acknowledged_at timestamp with time zone
resolved_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
notifications_acknowledged CHECK (((acknowledged_by IS NULL) OR (acknowledged_at IS NOT NULL)))
notifications_subject_table_format CHECK ((subject_table ~ '^[a-z_]+$'::text))
notifications_acknowledged_by_fkey FOREIGN KEY (acknowledged_by) REFERENCES profiles(id) ON DELETE SET NULL
notifications_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
notifications_pool_fk FOREIGN KEY (organization_id, pool_id) REFERENCES pools(organization_id, id)
notifications_recipient_fk FOREIGN KEY (recipient_membership_id, organization_id) REFERENCES memberships(id, organization_id) ON DELETE CASCADE
notifications_type_code_fkey FOREIGN KEY (type_code) REFERENCES notification_types(code)
notifications_pkey PRIMARY KEY (id)
notifications_id_org_unique UNIQUE (id, organization_id)
Index Definition
notifications_acknowledged_by_idx CREATE INDEX notifications_acknowledged_by_idx ON public.notifications USING btree (acknowledged_by)
notifications_open_unique CREATE UNIQUE INDEX notifications_open_unique ON public.notifications USING btree (type_code, subject_table, subject_id) WHERE (resolved_at IS NULL)
notifications_pool_idx CREATE INDEX notifications_pool_idx ON public.notifications USING btree (organization_id, pool_id)
notifications_recipient_idx CREATE INDEX notifications_recipient_idx ON public.notifications USING btree (recipient_membership_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
organization_id uuid not null
checkpoint_interval_weeks smallint not null 2
cp_warning_days smallint not null 10
cp_critical_days smallint not null 14
service_interval_km_ev integer not null 20000
service_interval_km_ice integer not null 10000
queue_open boolean not null true
queue_opens_at time without time zone not null '08:00:00'::time without time zone
queue_closes_at time without time zone not null '16:00:00'::time without time zone
max_tickets_per_phone smallint not null 4
max_queue_miss smallint not null 3
overdue_limit_days smallint not null 3
panel_fee bigint not null 300000
repo_fine bigint not null 300000
allow_cross_entity_payments boolean not null true
allow_cross_pool_operations boolean not null false
default_contract_months smallint not null 6
visit_due_days smallint not null 3
require_visit_before_booking boolean not null false
notification_escalation_hours jsonb not null '{}'::jsonb
notification_digest_at time without time zone not null '07:00:00'::time without time zone
max_repossessions smallint not null 2
cp_skip_weeks_limit smallint not null 3
gps_stale_minutes smallint not null 15
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
organization_settings_checkpoint_interval_weeks_check CHECK ((checkpoint_interval_weeks > 0))
organization_settings_cp_critical_days_check CHECK ((cp_critical_days > 0))
organization_settings_cp_skip_weeks_limit_check CHECK ((cp_skip_weeks_limit > 0))
organization_settings_cp_warning_days_check CHECK ((cp_warning_days > 0))
organization_settings_default_contract_months_check CHECK ((default_contract_months > 0))
organization_settings_gps_stale_minutes_check CHECK ((gps_stale_minutes > 0))
organization_settings_max_queue_miss_check CHECK ((max_queue_miss > 0))
organization_settings_max_repossessions_check CHECK ((max_repossessions > 0))
organization_settings_max_tickets_per_phone_check CHECK ((max_tickets_per_phone > 0))
organization_settings_notification_escalation_hours_check CHECK ((jsonb_typeof(notification_escalation_hours) = 'object'::text))
organization_settings_overdue_limit_days_check CHECK ((overdue_limit_days >= 0))
organization_settings_panel_fee_check CHECK ((panel_fee >= 0))
organization_settings_repo_fine_check CHECK ((repo_fine >= 0))
organization_settings_service_interval_km_ev_check CHECK ((service_interval_km_ev > 0))
organization_settings_service_interval_km_ice_check CHECK ((service_interval_km_ice > 0))
organization_settings_visit_due_days_check CHECK ((visit_due_days >= 0))
organization_settings_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
organization_settings_pkey PRIMARY KEY (organization_id)

Triggers: audit_row (app.audit_row), check_escalation_hours (app.check_escalation_hours), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
name text not null
slug text not null
kind org_kind not null 'operator'::org_kind
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
organizations_pkey PRIMARY KEY (id)
organizations_slug_unique UNIQUE (slug)

Triggers: create_settings (app.create_organization_settings), seed_organization (app.seed_new_organization), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
payment_id uuid not null
charge_id uuid not null
amount bigint not null
cross_entity boolean not null false
allocated_by uuid
allocated_at timestamp with time zone not null now()
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
payment_allocations_amount_positive CHECK ((amount > 0))
payment_allocations_allocated_by_fkey FOREIGN KEY (allocated_by) REFERENCES profiles(id)
payment_allocations_charge_id_fkey FOREIGN KEY (charge_id) REFERENCES charges(id)
payment_allocations_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
payment_allocations_payment_id_fkey FOREIGN KEY (payment_id) REFERENCES payments(id)
payment_allocations_pkey PRIMARY KEY (id)
payment_allocations_unique UNIQUE (payment_id, charge_id)
Index Definition
payment_allocations_allocated_by_fk_idx CREATE INDEX payment_allocations_allocated_by_fk_idx ON public.payment_allocations USING btree (allocated_by)
payment_allocations_charge_id_fk_idx CREATE INDEX payment_allocations_charge_id_fk_idx ON public.payment_allocations USING btree (charge_id)
payment_allocations_organization_id_fk_idx CREATE INDEX payment_allocations_organization_id_fk_idx ON public.payment_allocations USING btree (organization_id)

Triggers: allocation_guard (app.allocation_guard), audit_row (app.audit_row), refresh_charge_status (app.after_allocation_change), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid not null
amount bigint not null
paid_at timestamp with time zone not null
method payment_method not null
bank_account_id uuid
sender_name text
sender_account text
proof_path storage_path
note text
recorded_by uuid
recorded_at timestamp with time zone not null now()
migrated_from text
voided_at timestamp with time zone
voided_by uuid
void_reason text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
payments_account_unless_cash CHECK (((migrated_from IS NOT NULL) OR (method = 'cash'::payment_method) OR (bank_account_id IS NOT NULL)))
payments_amount_positive CHECK ((amount > 0))
payments_migrated_from_known CHECK ((migrated_from = ANY (ARRAY['bills.data.pembayaran'::text, 'bills.data.dibayar'::text, 'payments'::text])))
payments_proof_unless_migrated CHECK (((migrated_from IS NOT NULL) OR (proof_path IS NOT NULL)))
payments_void_complete CHECK ((((voided_at IS NULL) = (voided_by IS NULL)) AND ((voided_at IS NULL) OR (void_reason IS NOT NULL))))
payments_bank_account_id_fkey FOREIGN KEY (bank_account_id) REFERENCES company_bank_accounts(id)
payments_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id)
payments_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
payments_recorded_by_fkey FOREIGN KEY (recorded_by) REFERENCES profiles(id)
payments_voided_by_fkey FOREIGN KEY (voided_by) REFERENCES profiles(id)
payments_pkey PRIMARY KEY (id)
Index Definition
payments_bank_account_id_fk_idx CREATE INDEX payments_bank_account_id_fk_idx ON public.payments USING btree (bank_account_id)
payments_driver_idx CREATE INDEX payments_driver_idx ON public.payments USING btree (driver_id, paid_at DESC)
payments_organization_id_fk_idx CREATE INDEX payments_organization_id_fk_idx ON public.payments USING btree (organization_id)
payments_recorded_by_fk_idx CREATE INDEX payments_recorded_by_fk_idx ON public.payments USING btree (recorded_by)
payments_voided_by_fk_idx CREATE INDEX payments_voided_by_fk_idx ON public.payments USING btree (voided_by)

Triggers: after_payment_void (app.after_payment_void), audit_row (app.audit_row), guard_migrated (app.guard_payment_migrated), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
rental_company_id uuid not null
period_start date not null
period_end date not null
total_amount bigint not null 0
status payout_status not null 'draft'::payout_status
paid_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
payouts_paid_at CHECK (((status <> 'paid'::payout_status) OR (paid_at IS NOT NULL)))
payouts_period CHECK ((period_end >= period_start))
payouts_total_amount_check CHECK ((total_amount >= 0))
payouts_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
payouts_rental_company_id_fkey FOREIGN KEY (rental_company_id) REFERENCES rental_companies(id)
payouts_pkey PRIMARY KEY (id)
Index Definition
payouts_organization_id_fk_idx CREATE INDEX payouts_organization_id_fk_idx ON public.payouts USING btree (organization_id)
payouts_rental_company_id_fk_idx CREATE INDEX payouts_rental_company_id_fk_idx ON public.payouts USING btree (rental_company_id)

Triggers: guard_company (app.guard_payout_company), set_updated_at (app.set_updated_at).

Column Type Null Default Note
code text not null
feature text not null
action permission_action not null
label text not null
delegable boolean not null false
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
permissions_code_format CHECK ((code ~ '^[a-z_]+:[a-z]+$'::text))
permissions_pkey PRIMARY KEY (code)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
pool_id uuid not null
queue_open boolean
queue_opens_at time without time zone
queue_closes_at time without time zone
max_tickets_per_phone smallint
checkpoint_interval_weeks smallint
max_queue_miss smallint
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
pool_settings_checkpoint_interval_weeks_check CHECK ((checkpoint_interval_weeks > 0))
pool_settings_max_queue_miss_check CHECK ((max_queue_miss > 0))
pool_settings_max_tickets_per_phone_check CHECK ((max_tickets_per_phone > 0))
pool_settings_pool_id_fkey FOREIGN KEY (pool_id) REFERENCES pools(id) ON DELETE CASCADE
pool_settings_pkey PRIMARY KEY (pool_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
subject transfer_subject not null
vehicle_id uuid
driver_id uuid
from_pool_id uuid not null
to_pool_id uuid not null
reason text not null
status transfer_status not null 'requested'::transfer_status
requested_by uuid
requested_at timestamp with time zone not null now()
decided_by uuid
decided_at timestamp with time zone
completed_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
pool_transfers_one_subject CHECK ((((subject = 'vehicle'::transfer_subject) AND (vehicle_id IS NOT NULL) AND (driver_id IS NULL)) OR ((subject = 'driver'::transfer_subject) AND (driver_id IS NOT NULL) AND (vehicle_id IS NULL))))
pool_transfers_other_pool CHECK ((from_pool_id <> to_pool_id))
pool_transfers_decided_by_fkey FOREIGN KEY (decided_by) REFERENCES profiles(id)
pool_transfers_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id)
pool_transfers_from_pool_id_fkey FOREIGN KEY (from_pool_id) REFERENCES pools(id)
pool_transfers_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
pool_transfers_requested_by_fkey FOREIGN KEY (requested_by) REFERENCES profiles(id)
pool_transfers_to_pool_id_fkey FOREIGN KEY (to_pool_id) REFERENCES pools(id)
pool_transfers_vehicle_id_fkey FOREIGN KEY (vehicle_id) REFERENCES vehicles(id)
pool_transfers_pkey PRIMARY KEY (id)
Index Definition
pool_transfers_decided_by_fk_idx CREATE INDEX pool_transfers_decided_by_fk_idx ON public.pool_transfers USING btree (decided_by)
pool_transfers_driver_id_fk_idx CREATE INDEX pool_transfers_driver_id_fk_idx ON public.pool_transfers USING btree (driver_id)
pool_transfers_from_pool_id_fk_idx CREATE INDEX pool_transfers_from_pool_id_fk_idx ON public.pool_transfers USING btree (from_pool_id)
pool_transfers_organization_id_fk_idx CREATE INDEX pool_transfers_organization_id_fk_idx ON public.pool_transfers USING btree (organization_id)
pool_transfers_requested_by_fk_idx CREATE INDEX pool_transfers_requested_by_fk_idx ON public.pool_transfers USING btree (requested_by)
pool_transfers_to_pool_id_fk_idx CREATE INDEX pool_transfers_to_pool_id_fk_idx ON public.pool_transfers USING btree (to_pool_id)
pool_transfers_vehicle_id_fk_idx CREATE INDEX pool_transfers_vehicle_id_fk_idx ON public.pool_transfers USING btree (vehicle_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
code text not null
name text not null
city text not null
timezone text not null 'Asia/Jakarta'::text Business dates of this pool are computed in this zone (P11, R-CONV-10).
address text
capacity integer
is_active boolean not null true
opened_on date
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
pools_capacity_check CHECK ((capacity >= 0))
pools_timezone_indonesia CHECK ((timezone = ANY (ARRAY['Asia/Jakarta'::text, 'Asia/Pontianak'::text, 'Asia/Makassar'::text, 'Asia/Jayapura'::text])))
pools_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
pools_pkey PRIMARY KEY (id)
pools_code_unique UNIQUE (organization_id, code)
pools_organization_id_id_unique UNIQUE (organization_id, id)

Triggers: audit_row (app.audit_row), grant_new_pool_to_super_admins (app.grant_new_pool_to_super_admins), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
name text not null
driver_daily_rate bigint not null
admin_fee bigint not null
is_active boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
pricing_groups_admin_fee_check CHECK ((admin_fee >= 0))
pricing_groups_driver_daily_rate_check CHECK ((driver_daily_rate >= 0))
pricing_groups_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
pricing_groups_pkey PRIMARY KEY (id)
pricing_groups_name_unique UNIQUE (organization_id, name)

Triggers: audit_row (app.audit_row), change_pricing_group_rate (app.change_pricing_group_rate), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null
full_name text not null ''::text
phone text
avatar_path storage_path
locale locale not null 'id'::locale The language the app shows this person (D7). Changed only through public.set_my_locale().
access_changed_at timestamp with time zone When this person's sessions were last ended for an access change: their roles or overrides, their membership, or a held role's permissions. A login token issued before it is not current (D37, D48, R-ACC-48).
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
profiles_phone_62 CHECK ((phone ~ '^628[0-9]{7,12}$'::text))
profiles_id_fkey FOREIGN KEY (id) REFERENCES auth.users(id) ON DELETE CASCADE
profiles_pkey PRIMARY KEY (id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
ticket_id uuid not null
action queue_action not null
actor_id uuid
note text
at timestamp with time zone not null now()
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
queue_events_actor_id_fkey FOREIGN KEY (actor_id) REFERENCES profiles(id)
queue_events_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
queue_events_ticket_id_fkey FOREIGN KEY (ticket_id) REFERENCES queue_tickets(id) ON DELETE CASCADE
queue_events_pkey PRIMARY KEY (id)
Index Definition
queue_events_actor_id_fk_idx CREATE INDEX queue_events_actor_id_fk_idx ON public.queue_events USING btree (actor_id)
queue_events_organization_id_fk_idx CREATE INDEX queue_events_organization_id_fk_idx ON public.queue_events USING btree (organization_id)
queue_events_ticket_id_fk_idx CREATE INDEX queue_events_ticket_id_fk_idx ON public.queue_events USING btree (ticket_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
pool_id uuid not null
queue_date date not null
ticket_no smallint not null
full_name text not null
phone text not null
lead_source_id uuid
emergency_contact_name text
emergency_contact_phone text
emergency_contact_relationship text
education text
birth_date date
status queue_status not null 'waiting'::queue_status
driver_id uuid
created_by uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
queue_tickets_emergency_contact_phone_62 CHECK ((emergency_contact_phone ~ '^628[0-9]{7,12}$'::text))
queue_tickets_phone_62 CHECK ((phone ~ '^628[0-9]{7,12}$'::text))
queue_tickets_ticket_no_check CHECK ((ticket_no > 0))
queue_tickets_created_by_fkey FOREIGN KEY (created_by) REFERENCES profiles(id)
queue_tickets_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id)
queue_tickets_lead_source_id_fkey FOREIGN KEY (lead_source_id) REFERENCES lead_sources(id)
queue_tickets_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
queue_tickets_pool_id_fkey FOREIGN KEY (pool_id) REFERENCES pools(id)
queue_tickets_pkey PRIMARY KEY (id)
queue_tickets_driver_unique UNIQUE (driver_id)
queue_tickets_number_unique UNIQUE (pool_id, queue_date, ticket_no)
Index Definition
queue_tickets_created_by_fk_idx CREATE INDEX queue_tickets_created_by_fk_idx ON public.queue_tickets USING btree (created_by)
queue_tickets_lead_source_id_fk_idx CREATE INDEX queue_tickets_lead_source_id_fk_idx ON public.queue_tickets USING btree (lead_source_id)
queue_tickets_organization_id_fk_idx CREATE INDEX queue_tickets_organization_id_fk_idx ON public.queue_tickets USING btree (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
name text not null
legal_name text
contact_phone text
bank_account_ref text
status company_status not null 'active'::company_status
is_operator boolean not null false The operator's own company (D108). Set by the migration and the seed; no app function sets or clears it (R-MD-85).
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
rental_companies_contact_phone_62 CHECK ((contact_phone ~ '^62[1-9][0-9]{6,12}$'::text))
rental_companies_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
rental_companies_pkey PRIMARY KEY (id)
rental_companies_id_org_unique UNIQUE (id, organization_id)
rental_companies_name_unique UNIQUE (organization_id, name)
Index Definition
rental_companies_operator_unique CREATE UNIQUE INDEX rental_companies_operator_unique ON public.rental_companies USING btree (organization_id) WHERE is_operator

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
pool_id uuid not null
driver_id uuid not null
vehicle_id uuid
starts_on date
ends_on date
driver_daily_rate bigint not null
company_daily_cost bigint not null 0
billing_frequency billing_frequency not null 'daily'::billing_frequency
billing_ends_on date
status rental_status not null 'pending'::rental_status Changed only through the module actions (P9).
end_reason return_reason
pause_reason text
previous_rental_id uuid The row this one continues after a rate change (D38, R-RNT-10). The rows of one chain count as one rental (R-RNT-17).
legacy_data jsonb v1's audit row (oleh, detail, plat_before, plat_after) of the fee change a migrated chain row begins at (D84, R-RNT-69). Written by the migration, read by nobody in v2 (R-RNT-71).
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
rentals_car_unless_pending CHECK (((status = ANY (ARRAY['pending'::rental_status, 'cancelled'::rental_status])) OR (vehicle_id IS NOT NULL)))
rentals_company_daily_cost_check CHECK ((company_daily_cost >= 0))
rentals_dates CHECK (((ends_on IS NULL) OR (starts_on IS NULL) OR (ends_on >= starts_on)))
rentals_driver_daily_rate_check CHECK ((driver_daily_rate >= 0))
rentals_legacy_data_no_inline_files CHECK ((NOT app.has_inline_file((legacy_data)::text)))
rentals_legacy_data_shape CHECK (((legacy_data IS NULL) OR ((jsonb_typeof(legacy_data) = 'object'::text) AND (legacy_data ?& ARRAY['oleh'::text, 'detail'::text, 'plat_before'::text, 'plat_after'::text]) AND ((legacy_data - ARRAY['oleh'::text, 'detail'::text, 'plat_before'::text, 'plat_after'::text]) = '{}'::jsonb) AND (jsonb_typeof((legacy_data -> 'oleh'::text)) = ANY (ARRAY['string'::text, 'null'::text])) AND (jsonb_typeof((legacy_data -> 'detail'::text)) = ANY (ARRAY['string'::text, 'null'::text])) AND (jsonb_typeof((legacy_data -> 'plat_before'::text)) = ANY (ARRAY['string'::text, 'null'::text])) AND (jsonb_typeof((legacy_data -> 'plat_after'::text)) = ANY (ARRAY['string'::text, 'null'::text])))))
rentals_pause_reason CHECK (((status <> 'paused'::rental_status) OR (COALESCE(btrim(pause_reason), ''::text) <> ''::text)))
rentals_driver_id_fkey FOREIGN KEY (driver_id) REFERENCES drivers(id)
rentals_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
rentals_pool_id_fkey FOREIGN KEY (pool_id) REFERENCES pools(id)
rentals_previous_rental_id_fkey FOREIGN KEY (previous_rental_id) REFERENCES rentals(id)
rentals_vehicle_id_fkey FOREIGN KEY (vehicle_id) REFERENCES vehicles(id)
rentals_pkey PRIMARY KEY (id)
rentals_id_org_unique UNIQUE (id, organization_id)
rentals_previous_unique UNIQUE (previous_rental_id)
Index Definition
rentals_one_live_per_driver CREATE UNIQUE INDEX rentals_one_live_per_driver ON public.rentals USING btree (driver_id) WHERE (status = ANY (ARRAY['pending'::rental_status, 'booked'::rental_status, 'active'::rental_status, 'paused'::rental_status, 'returning'::rental_status, 'repossessing'::rental_status, 'returned'::rental_status]))
rentals_one_live_per_vehicle CREATE UNIQUE INDEX rentals_one_live_per_vehicle ON public.rentals USING btree (vehicle_id) WHERE (status = ANY (ARRAY['booked'::rental_status, 'active'::rental_status, 'paused'::rental_status, 'returning'::rental_status, 'repossessing'::rental_status, 'returned'::rental_status]))
rentals_organization_id_fk_idx CREATE INDEX rentals_organization_id_fk_idx ON public.rentals USING btree (organization_id)
rentals_pool_id_fk_idx CREATE INDEX rentals_pool_id_fk_idx ON public.rentals USING btree (pool_id)

Triggers: audit_row (app.audit_row), guard_status (app.guard_status_column), rentals_end_reason (app.rentals_end_reason), rentals_pool_guard (app.rentals_pool_guard), set_updated_at (app.set_updated_at).

A repossession's request (D71): one live per rental (R-REP-05). The Repo Leader groups open ones into repo work orders (M5).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
rental_id uuid not null
status repo_request_status not null 'open'::repo_request_status open and assigned are live; collected and cancelled are closed (R-REP-01). Changed only by M5's functions (D3, R-REP-02).
reason repo_request_reason not null
opened_at timestamp with time zone not null now()
closed_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
repo_requests_closed_after_opened CHECK (((closed_at IS NULL) OR (closed_at >= opened_at)))
repo_requests_closed_at CHECK (((status = ANY (ARRAY['open'::repo_request_status, 'assigned'::repo_request_status])) = (closed_at IS NULL)))
repo_requests_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
repo_requests_rental_id_fkey FOREIGN KEY (rental_id) REFERENCES rentals(id)
repo_requests_pkey PRIMARY KEY (id)
Index Definition
repo_requests_one_live_per_rental CREATE UNIQUE INDEX repo_requests_one_live_per_rental ON public.repo_requests USING btree (rental_id) WHERE (status = ANY (ARRAY['open'::repo_request_status, 'assigned'::repo_request_status]))
repo_requests_organization_id_fk_idx CREATE INDEX repo_requests_organization_id_fk_idx ON public.repo_requests USING btree (organization_id)

Triggers: audit_row (app.audit_row), repo_requests_one_live (app.repo_requests_one_live), set_updated_at (app.set_updated_at).

The members of the Repo Team who carry out a work order; each sees every unit and may close any (D71, R-REP-25).

Column Type Null Default Note
organization_id uuid not null
work_order_id uuid not null
profile_id uuid not null
created_at timestamp with time zone not null now()
Constraint Definition
repo_work_order_pics_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
repo_work_order_pics_profile_id_fkey FOREIGN KEY (profile_id) REFERENCES profiles(id)
repo_work_order_pics_work_order_id_fkey FOREIGN KEY (work_order_id) REFERENCES repo_work_orders(id)
repo_work_order_pics_pkey PRIMARY KEY (work_order_id, profile_id)
Index Definition
repo_work_order_pics_organization_id_fk_idx CREATE INDEX repo_work_order_pics_organization_id_fk_idx ON public.repo_work_order_pics USING btree (organization_id)
repo_work_order_pics_profile_id_fk_idx CREATE INDEX repo_work_order_pics_profile_id_fk_idx ON public.repo_work_order_pics USING btree (profile_id)

One request in a work order (D71): pending until a PIC collects it or it fails. Changed only by M5's functions (D3, R-REP-27).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
work_order_id uuid not null
repo_request_id uuid not null
status repo_unit_status not null 'pending'::repo_unit_status
closed_by uuid The PIC who closed the unit; empty while pending and when the job at the deadline failed it (R-REP-24).
closed_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
repo_work_order_units_closed_at CHECK (((status = 'pending'::repo_unit_status) = (closed_at IS NULL)))
repo_work_order_units_closed_by CHECK ( CASE status WHEN 'pending'::repo_unit_status THEN (closed_by IS NULL) WHEN 'collected'::repo_unit_status THEN (closed_by IS NOT NULL) ELSE true END)
repo_work_order_units_closer_fk FOREIGN KEY (work_order_id, closed_by) REFERENCES repo_work_order_pics(work_order_id, profile_id)
repo_work_order_units_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
repo_work_order_units_repo_request_id_fkey FOREIGN KEY (repo_request_id) REFERENCES repo_requests(id)
repo_work_order_units_work_order_id_fkey FOREIGN KEY (work_order_id) REFERENCES repo_work_orders(id)
repo_work_order_units_pkey PRIMARY KEY (id)
repo_work_order_units_once UNIQUE (work_order_id, repo_request_id)
Index Definition
repo_work_order_units_one_pending_per_request CREATE UNIQUE INDEX repo_work_order_units_one_pending_per_request ON public.repo_work_order_units USING btree (repo_request_id) WHERE (status = 'pending'::repo_unit_status)
repo_work_order_units_organization_id_fk_idx CREATE INDEX repo_work_order_units_organization_id_fk_idx ON public.repo_work_order_units USING btree (organization_id)

Triggers: repo_work_order_units_guard (app.repo_work_order_units_guard), set_updated_at (app.set_updated_at).

A repo work order (D71): requests of one pool carried out by its PICs. Made and closed only by M5's functions (D3, R-REP-27).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
pool_id uuid not null
status repo_work_order_status not null 'active'::repo_work_order_status
assigned_by uuid not null
assigned_at timestamp with time zone not null now()
closed_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
repo_work_orders_closed_after_assigned CHECK (((closed_at IS NULL) OR (closed_at >= assigned_at)))
repo_work_orders_closed_at CHECK (((status = 'closed'::repo_work_order_status) = (closed_at IS NOT NULL)))
repo_work_orders_assigned_by_fkey FOREIGN KEY (assigned_by) REFERENCES profiles(id)
repo_work_orders_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
repo_work_orders_pool_id_fkey FOREIGN KEY (pool_id) REFERENCES pools(id)
repo_work_orders_pkey PRIMARY KEY (id)
Index Definition
repo_work_orders_assigned_by_fk_idx CREATE INDEX repo_work_orders_assigned_by_fk_idx ON public.repo_work_orders USING btree (assigned_by)
repo_work_orders_organization_id_fk_idx CREATE INDEX repo_work_orders_organization_id_fk_idx ON public.repo_work_orders USING btree (organization_id)
repo_work_orders_pool_status CREATE INDEX repo_work_orders_pool_status ON public.repo_work_orders USING btree (pool_id, status)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
role_id uuid not null
permission_code text not null
created_at timestamp with time zone not null now()
Constraint Definition
role_permissions_permission_code_fkey FOREIGN KEY (permission_code) REFERENCES permissions(code) ON UPDATE CASCADE
role_permissions_role_id_fkey FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE
role_permissions_pkey PRIMARY KEY (role_id, permission_code)
Index Definition
role_permissions_permission_code_fk_idx CREATE INDEX role_permissions_permission_code_fk_idx ON public.role_permissions USING btree (permission_code)

Triggers: audit_row (app.audit_row), end_sessions (app.end_sessions_on_role_permission_change), guard_last_user_manager (app.guard_last_user_manager).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
code text not null
name text not null
description text
is_system boolean not null false
home_route text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
roles_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
roles_pkey PRIMARY KEY (id)
roles_code_unique UNIQUE (organization_id, code)

Triggers: audit_row (app.audit_row), guard_last_user_manager (app.guard_last_user_manager), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
session_id uuid not null
vehicle_id uuid not null
status_at_start vehicle_status not null
note text
recheck_outcome opname_recheck_outcome
recheck_note text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
stock_opname_expected_missing_note CHECK (((recheck_outcome IS DISTINCT FROM 'confirmed_missing'::opname_recheck_outcome) OR (NULLIF(TRIM(BOTH FROM recheck_note), ''::text) IS NOT NULL)))
stock_opname_expected_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
stock_opname_expected_session_fk FOREIGN KEY (session_id, organization_id) REFERENCES stock_opname_sessions(id, organization_id) ON DELETE CASCADE
stock_opname_expected_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
stock_opname_expected_pkey PRIMARY KEY (id)
stock_opname_expected_id_session_vehicle_unique UNIQUE (id, session_id, vehicle_id)
stock_opname_expected_once UNIQUE (session_id, vehicle_id)
Index Definition
stock_opname_expected_organization_id_fk_idx CREATE INDEX stock_opname_expected_organization_id_fk_idx ON public.stock_opname_expected USING btree (organization_id)
stock_opname_expected_vehicle_id_fk_idx CREATE INDEX stock_opname_expected_vehicle_id_fk_idx ON public.stock_opname_expected USING btree (vehicle_id)

Triggers: opname_recheck_finished (app.opname_recheck_finished), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
session_id uuid not null
code text not null
typed boolean not null false
vehicle_id uuid
expected_id uuid
is_recheck boolean not null false
scanned_by uuid not null
scanned_at timestamp with time zone not null now()
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
stock_opname_scans_code_check CHECK ((TRIM(BOTH FROM code) <> ''::text))
stock_opname_scans_expected_fk FOREIGN KEY (expected_id, session_id, vehicle_id) REFERENCES stock_opname_expected(id, session_id, vehicle_id)
stock_opname_scans_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
stock_opname_scans_scanned_by_fkey FOREIGN KEY (scanned_by) REFERENCES profiles(id)
stock_opname_scans_session_fk FOREIGN KEY (session_id, organization_id) REFERENCES stock_opname_sessions(id, organization_id) ON DELETE CASCADE
stock_opname_scans_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
stock_opname_scans_pkey PRIMARY KEY (id)
Index Definition
stock_opname_scans_expected_id_fk_idx CREATE INDEX stock_opname_scans_expected_id_fk_idx ON public.stock_opname_scans USING btree (expected_id)
stock_opname_scans_organization_id_fk_idx CREATE INDEX stock_opname_scans_organization_id_fk_idx ON public.stock_opname_scans USING btree (organization_id)
stock_opname_scans_scanned_by_fk_idx CREATE INDEX stock_opname_scans_scanned_by_fk_idx ON public.stock_opname_scans USING btree (scanned_by)
stock_opname_scans_session_idx CREATE INDEX stock_opname_scans_session_idx ON public.stock_opname_scans USING btree (session_id)
stock_opname_scans_vehicle_id_fk_idx CREATE INDEX stock_opname_scans_vehicle_id_fk_idx ON public.stock_opname_scans USING btree (vehicle_id)

Triggers: opname_scan_check (app.opname_scan_check), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
pool_id uuid not null
status opname_status not null 'open'::opname_status
assigned_to uuid
deadline timestamp with time zone
note text
started_by uuid
started_at timestamp with time zone not null now()
finished_at timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
stock_opname_sessions_finished_at CHECK (((status = 'open'::opname_status) = (finished_at IS NULL)))
stock_opname_sessions_assigned_to_fkey FOREIGN KEY (assigned_to) REFERENCES profiles(id)
stock_opname_sessions_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
stock_opname_sessions_pool_fk FOREIGN KEY (pool_id, organization_id) REFERENCES pools(id, organization_id)
stock_opname_sessions_started_by_fkey FOREIGN KEY (started_by) REFERENCES profiles(id)
stock_opname_sessions_pkey PRIMARY KEY (id)
stock_opname_sessions_id_org_unique UNIQUE (id, organization_id)
Index Definition
stock_opname_sessions_assigned_to_fk_idx CREATE INDEX stock_opname_sessions_assigned_to_fk_idx ON public.stock_opname_sessions USING btree (assigned_to)
stock_opname_sessions_one_open CREATE UNIQUE INDEX stock_opname_sessions_one_open ON public.stock_opname_sessions USING btree (pool_id) WHERE (status = 'open'::opname_status)
stock_opname_sessions_organization_id_fk_idx CREATE INDEX stock_opname_sessions_organization_id_fk_idx ON public.stock_opname_sessions USING btree (organization_id)
stock_opname_sessions_started_by_fk_idx CREATE INDEX stock_opname_sessions_started_by_fk_idx ON public.stock_opname_sessions USING btree (started_by)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
plan plan_tier not null 'trial'::plan_tier
status subscription_status not null 'trialing'::subscription_status
current_period_end timestamp with time zone
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
subscriptions_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
subscriptions_pkey PRIMARY KEY (id)
subscriptions_organization_id_key UNIQUE (organization_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
plate_number text not null
note text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
temporary_plates_plate_normalized CHECK (((plate_number = upper(plate_number)) AND (plate_number !~ '\s'::text) AND (plate_number <> ''::text)))
temporary_plates_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
temporary_plates_pkey PRIMARY KEY (id)
temporary_plates_unique UNIQUE (organization_id, plate_number)

Triggers: refresh_temporary_plate (app.refresh_temporary_plate), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
driver_id uuid
vehicle_id uuid
v1_folder text not null
v1_label text
taken_at timestamp with time zone
content_type text not null
size_bytes bigint not null
storage_path storage_path
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
v1_files_one_owner CHECK ((num_nonnulls(driver_id, vehicle_id) = 1))
v1_files_owner_by_folder CHECK ((((v1_folder = ANY (ARRAY['bc'::text, 'driver'::text, 'payment'::text, 'rebate'::text])) AND (driver_id IS NOT NULL)) OR ((v1_folder = ANY (ARRAY['vehicle'::text, 'checkpoint'::text, 'asuransi'::text, 'etle'::text])) AND (vehicle_id IS NOT NULL))))
v1_files_size_bytes_check CHECK ((size_bytes >= 0))
v1_files_driver_fk FOREIGN KEY (driver_id, organization_id) REFERENCES drivers(id, organization_id)
v1_files_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
v1_files_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
v1_files_pkey PRIMARY KEY (id)
Index Definition
v1_files_driver_idx CREATE INDEX v1_files_driver_idx ON public.v1_files USING btree (driver_id) WHERE (driver_id IS NOT NULL)
v1_files_organization_id_fk_idx CREATE INDEX v1_files_organization_id_fk_idx ON public.v1_files USING btree (organization_id)
v1_files_vehicle_idx CREATE INDEX v1_files_vehicle_idx ON public.v1_files USING btree (vehicle_id) WHERE (vehicle_id IS NOT NULL)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
name text not null
country text
is_active boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
vehicle_brands_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
vehicle_brands_pkey PRIMARY KEY (id)
vehicle_brands_name_unique UNIQUE (organization_id, name)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
vehicle_id uuid not null
doc_type vehicle_doc_type not null
storage_path storage_path
expires_on date
tax_due_on date
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
vehicle_documents_path_own_folder CHECK (((storage_path IS NULL) OR ((storage_path)::text ~ (((('^'::text || (organization_id)::text) || '/vehicle_documents/'::text) || (id)::text) || '/[^/]+$'::text))))
vehicle_documents_tax_due_stnk_only CHECK (((tax_due_on IS NULL) OR (doc_type = 'stnk'::vehicle_doc_type)))
vehicle_documents_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
vehicle_documents_vehicle_id_fkey FOREIGN KEY (vehicle_id) REFERENCES vehicles(id) ON DELETE CASCADE
vehicle_documents_pkey PRIMARY KEY (id)
Index Definition
vehicle_documents_organization_id_fk_idx CREATE INDEX vehicle_documents_organization_id_fk_idx ON public.vehicle_documents USING btree (organization_id)
vehicle_documents_vehicle_id_fk_idx CREATE INDEX vehicle_documents_vehicle_id_fk_idx ON public.vehicle_documents USING btree (vehicle_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
brand_id uuid not null
pricing_group_id uuid
name text not null
vehicle_class vehicle_class not null 'car'::vehicle_class
body_type text
powertrain powertrain not null 'ice'::powertrain
tyre_size text
transmission transmission
default_service_type service_type
is_active boolean not null true
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
vehicle_models_brand_id_fkey FOREIGN KEY (brand_id) REFERENCES vehicle_brands(id)
vehicle_models_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
vehicle_models_pricing_group_id_fkey FOREIGN KEY (pricing_group_id) REFERENCES pricing_groups(id)
vehicle_models_pkey PRIMARY KEY (id)
vehicle_models_name_unique UNIQUE (organization_id, brand_id, name)
Index Definition
vehicle_models_brand_id_fk_idx CREATE INDEX vehicle_models_brand_id_fk_idx ON public.vehicle_models USING btree (brand_id)
vehicle_models_pricing_group_id_fk_idx CREATE INDEX vehicle_models_pricing_group_id_fk_idx ON public.vehicle_models USING btree (pricing_group_id)

Triggers: audit_row (app.audit_row), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
vehicle_id uuid not null
side vehicle_photo_side not null
storage_path storage_path
stored_at timestamp with time zone
created_by uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
vehicle_photos_path_own_folder CHECK (((storage_path IS NULL) OR ((storage_path)::text ~ (((('^'::text || (organization_id)::text) || '/vehicle_photos/'::text) || (id)::text) || '/[^/]+$'::text))))
vehicle_photos_created_by_fkey FOREIGN KEY (created_by) REFERENCES profiles(id)
vehicle_photos_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
vehicle_photos_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id) ON DELETE CASCADE
vehicle_photos_pkey PRIMARY KEY (id)
Index Definition
vehicle_photos_created_by_fk_idx CREATE INDEX vehicle_photos_created_by_fk_idx ON public.vehicle_photos USING btree (created_by)
vehicle_photos_organization_id_fk_idx CREATE INDEX vehicle_photos_organization_id_fk_idx ON public.vehicle_photos USING btree (organization_id)
vehicle_photos_vehicle_side_idx CREATE INDEX vehicle_photos_vehicle_side_idx ON public.vehicle_photos USING btree (vehicle_id, side)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
vehicle_id uuid not null
plate_number text not null
valid_from timestamp with time zone
valid_to timestamp with time zone not null now()
changed_by uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
vehicle_plate_history_changed_by_fkey FOREIGN KEY (changed_by) REFERENCES profiles(id)
vehicle_plate_history_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
vehicle_plate_history_vehicle_id_fkey FOREIGN KEY (vehicle_id) REFERENCES vehicles(id) ON DELETE CASCADE
vehicle_plate_history_pkey PRIMARY KEY (id)
Index Definition
vehicle_plate_history_changed_by_fk_idx CREATE INDEX vehicle_plate_history_changed_by_fk_idx ON public.vehicle_plate_history USING btree (changed_by)
vehicle_plate_history_plate_idx CREATE INDEX vehicle_plate_history_plate_idx ON public.vehicle_plate_history USING btree (organization_id, plate_number)
vehicle_plate_history_vehicle_id_fk_idx CREATE INDEX vehicle_plate_history_vehicle_id_fk_idx ON public.vehicle_plate_history USING btree (vehicle_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
vehicle_id uuid not null
from_status vehicle_status
to_status vehicle_status not null
rental_id uuid
changed_by uuid
note text
legacy_by text
legacy_driver text
legacy_driver_id text
legacy_from_status text
legacy_to_status text
changed_at timestamp with time zone not null now()
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
vehicle_status_history_changed_by_fkey FOREIGN KEY (changed_by) REFERENCES profiles(id)
vehicle_status_history_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
vehicle_status_history_rental_fk FOREIGN KEY (rental_id) REFERENCES rentals(id)
vehicle_status_history_vehicle_id_fkey FOREIGN KEY (vehicle_id) REFERENCES vehicles(id) ON DELETE CASCADE
vehicle_status_history_pkey PRIMARY KEY (id)
Index Definition
vehicle_status_history_changed_by_fk_idx CREATE INDEX vehicle_status_history_changed_by_fk_idx ON public.vehicle_status_history USING btree (changed_by)
vehicle_status_history_organization_id_fk_idx CREATE INDEX vehicle_status_history_organization_id_fk_idx ON public.vehicle_status_history USING btree (organization_id)
vehicle_status_history_rental_id_fk_idx CREATE INDEX vehicle_status_history_rental_id_fk_idx ON public.vehicle_status_history USING btree (rental_id)
vehicle_status_history_vehicle_idx CREATE INDEX vehicle_status_history_vehicle_idx ON public.vehicle_status_history USING btree (vehicle_id, changed_at DESC)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
home_pool_id uuid not null
rental_company_id uuid not null
model_id uuid not null
unit_code text not null
plate_number text not null Upper case, no spaces (B1234ABC). Changed only through public.change_plate() (R-VEH-85). Former plates live in vehicle_plate_history.
year smallint
color text
company_daily_cost bigint not null 0
odometer_km integer not null 0
plate_is_temporary boolean not null false Whether the plate is on the organization's temporary plates list. Set by the database, never by the app (R-VEH-02).
status vehicle_status not null 'not_ready'::vehicle_status Changed only through app.set_vehicle_status() (P9). inactive retires a car (D39).
supply_status supply_status not null 'active'::supply_status
vin text
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
vehicles_company_daily_cost_check CHECK ((company_daily_cost >= 0))
vehicles_odometer_km_check CHECK ((odometer_km >= 0))
vehicles_plate_normalized CHECK (((plate_number = upper(plate_number)) AND (plate_number !~ '\s'::text) AND (plate_number <> ''::text)))
vehicles_year_check CHECK (((year >= 1990) AND (year <= 2100)))
vehicles_home_pool_id_fkey FOREIGN KEY (home_pool_id) REFERENCES pools(id)
vehicles_model_id_fkey FOREIGN KEY (model_id) REFERENCES vehicle_models(id)
vehicles_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
vehicles_rental_company_fk FOREIGN KEY (rental_company_id, organization_id) REFERENCES rental_companies(id, organization_id)
vehicles_pkey PRIMARY KEY (id)
vehicles_id_org_unique UNIQUE (id, organization_id)
vehicles_unit_code_unique UNIQUE (organization_id, unit_code)
vehicles_vin_unique UNIQUE (organization_id, vin)
Index Definition
vehicles_home_pool_id_fk_idx CREATE INDEX vehicles_home_pool_id_fk_idx ON public.vehicles USING btree (home_pool_id)
vehicles_model_id_fk_idx CREATE INDEX vehicles_model_id_fk_idx ON public.vehicles USING btree (model_id)
vehicles_plate_unique CREATE UNIQUE INDEX vehicles_plate_unique ON public.vehicles USING btree (organization_id, plate_number) WHERE ((status <> 'inactive'::vehicle_status) AND (NOT plate_is_temporary))
vehicles_rental_company_id_fk_idx CREATE INDEX vehicles_rental_company_id_fk_idx ON public.vehicles USING btree (rental_company_id)

Triggers: audit_row (app.audit_row), guard_plate (app.guard_status_column), guard_status (app.guard_status_column), keep_old_plate (app.keep_old_plate), mark_temporary_plate (app.mark_temporary_plate), set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
work_order_id uuid not null
action wo_action not null
actor_id uuid
note text
legacy_by text
at timestamp with time zone not null now()
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
work_order_events_actor_id_fkey FOREIGN KEY (actor_id) REFERENCES profiles(id)
work_order_events_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
work_order_events_work_order_fk FOREIGN KEY (work_order_id, organization_id) REFERENCES work_orders(id, organization_id) ON DELETE CASCADE
work_order_events_pkey PRIMARY KEY (id)
Index Definition
work_order_events_actor_id_fk_idx CREATE INDEX work_order_events_actor_id_fk_idx ON public.work_order_events USING btree (actor_id)
work_order_events_organization_id_fk_idx CREATE INDEX work_order_events_organization_id_fk_idx ON public.work_order_events USING btree (organization_id)
work_order_events_work_order_id_fk_idx CREATE INDEX work_order_events_work_order_id_fk_idx ON public.work_order_events USING btree (work_order_id)

Triggers: set_updated_at (app.set_updated_at).

Column Type Null Default Note
id uuid not null gen_random_uuid()
organization_id uuid not null
pool_id uuid not null
vehicle_id uuid not null
inspection_id uuid
reason return_reason
legacy_reason text
route wo_route
status wo_status not null 'waiting'::wo_status
pic_id uuid
opened_at timestamp with time zone not null now()
ready_at timestamp with time zone
ready_by uuid
created_at timestamp with time zone not null now()
updated_at timestamp with time zone not null now()
Constraint Definition
work_orders_ready_at CHECK (((status <> 'ready'::wo_status) OR (ready_at IS NOT NULL)))
work_orders_reason_or_legacy CHECK (((reason IS NOT NULL) OR (legacy_reason IS NOT NULL)))
work_orders_inspection_fk FOREIGN KEY (inspection_id, organization_id) REFERENCES inspections(id, organization_id)
work_orders_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organizations(id)
work_orders_pic_id_fkey FOREIGN KEY (pic_id) REFERENCES profiles(id)
work_orders_pool_fk FOREIGN KEY (pool_id, organization_id) REFERENCES pools(id, organization_id)
work_orders_ready_by_fkey FOREIGN KEY (ready_by) REFERENCES profiles(id)
work_orders_vehicle_fk FOREIGN KEY (vehicle_id, organization_id) REFERENCES vehicles(id, organization_id)
work_orders_pkey PRIMARY KEY (id)
work_orders_id_org_unique UNIQUE (id, organization_id)
work_orders_id_vehicle_org_unique UNIQUE (id, vehicle_id, organization_id)
Index Definition
work_orders_inspection_id_fk_idx CREATE INDEX work_orders_inspection_id_fk_idx ON public.work_orders USING btree (inspection_id)
work_orders_one_open_per_vehicle CREATE UNIQUE INDEX work_orders_one_open_per_vehicle ON public.work_orders USING btree (vehicle_id) WHERE (status <> 'ready'::wo_status)
work_orders_organization_id_fk_idx CREATE INDEX work_orders_organization_id_fk_idx ON public.work_orders USING btree (organization_id)
work_orders_pic_id_fk_idx CREATE INDEX work_orders_pic_id_fk_idx ON public.work_orders USING btree (pic_id)
work_orders_pool_id_fk_idx CREATE INDEX work_orders_pool_id_fk_idx ON public.work_orders USING btree (pool_id)
work_orders_ready_by_fk_idx CREATE INDEX work_orders_ready_by_fk_idx ON public.work_orders USING btree (ready_by)

Triggers: audit_row (app.audit_row), default_pool (app.default_pool_from_vehicle), set_updated_at (app.set_updated_at).