Generated by npm run db:docs:generate — DO NOT EDIT BY HAND. Change the schema via a migration, then regenerate.
Core: fm_ · Tables: 29 · Source generated: 2026-06-10T02:55:32.169Z
Entity relationships
Tables
fm_asset_depreciation
Depreciation records are immutable for audit purposes. Corrections require new reversal entries. No UPDATE or DELETE policies exist by design.
RLS: ✅ enabled (4 policies)
Foreign keys:
asset_id→fm_assets(id)calculated_by→pf_profiles(id)fiscal_year_id→fa_fiscal_years(id)organization_id→pf_organizations(id)
fm_asset_dep_insert(INSERT)fm_asset_dep_select(SELECT)fm_asset_depreciation_insert(INSERT)fm_asset_depreciation_select(SELECT)
fm_asset_locations
RLS: ✅ enabled (2 policies)
Foreign keys:
asset_id→fm_assets(id)moved_by→pf_profiles(id)organization_id→pf_organizations(id)previous_site_id→pf_sites(id)site_id→pf_sites(id)
fm_asset_loc_insert(INSERT)fm_asset_loc_select(SELECT)
fm_asset_maintenance_history
RLS: ✅ enabled (2 policies)
Foreign keys:
asset_id→fm_assets(id)organization_id→pf_organizations(id)recorded_by→pf_profiles(id)work_order_id→fm_work_orders(id)
fm_asset_maint_insert(INSERT)fm_asset_maint_select(SELECT)
fm_assets
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)organization_id→pf_organizations(id)service_contract_vendor_id→fm_vendors(id)site_id→pf_sites(id)updated_by→pf_profiles(id)
fm_assets_delete(DELETE)fm_assets_insert(INSERT)fm_assets_select(SELECT)fm_assets_update(UPDATE)
fm_fleet_drivers
FM-13: Fleet driver/operator records
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→users(id)organization_id→pf_organizations(id)updated_by→users(id)user_id→pf_profiles(id)
fm_fleet_drivers_delete(DELETE)fm_fleet_drivers_insert(INSERT)fm_fleet_drivers_select(SELECT)fm_fleet_drivers_update(UPDATE)
fm_fleet_fuel_logs
FM-13: Fuel purchase records
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→users(id)driver_id→fm_fleet_drivers(id)organization_id→pf_organizations(id)updated_by→users(id)vehicle_id→fm_fleet_vehicles(id)
fm_fleet_fuel_logs_delete(DELETE)fm_fleet_fuel_logs_insert(INSERT)fm_fleet_fuel_logs_select(SELECT)fm_fleet_fuel_logs_update(UPDATE)
fm_fleet_maintenance_schedules
FM-13: Preventive maintenance schedules for fleet vehicles
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→users(id)organization_id→pf_organizations(id)updated_by→users(id)vehicle_id→fm_fleet_vehicles(id)
fm_fleet_maintenance_schedules_delete(DELETE)fm_fleet_maintenance_schedules_insert(INSERT)fm_fleet_maintenance_schedules_select(SELECT)fm_fleet_maintenance_schedules_update(UPDATE)
fm_fleet_mileage_logs
FM-13: Historical odometer readings
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→users(id)organization_id→pf_organizations(id)trip_id→fm_fleet_trips(id)vehicle_id→fm_fleet_vehicles(id)
fm_fleet_mileage_logs_delete(DELETE)fm_fleet_mileage_logs_insert(INSERT)fm_fleet_mileage_logs_select(SELECT)fm_fleet_mileage_logs_update(UPDATE)
fm_fleet_reservations
FM-13 Phase 2: Vehicle reservation records for shared/pool fleet vehicles
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→users(id)driver_id→fm_fleet_drivers(id)organization_id→pf_organizations(id)updated_by→users(id)vehicle_id→fm_fleet_vehicles(id)
fm_fleet_reservations_delete(DELETE)fm_fleet_reservations_insert(INSERT)fm_fleet_reservations_select(SELECT)fm_fleet_reservations_update(UPDATE)
fm_fleet_trips
FM-13: Fleet trip records for mileage tracking
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→users(id)driver_id→fm_fleet_drivers(id)organization_id→pf_organizations(id)updated_by→users(id)vehicle_id→fm_fleet_vehicles(id)
fm_fleet_trips_delete(DELETE)fm_fleet_trips_insert(INSERT)fm_fleet_trips_select(SELECT)fm_fleet_trips_update(UPDATE)
fm_fleet_vehicles
FM-13: Fleet vehicle master records
RLS: ✅ enabled (4 policies)
Foreign keys:
assigned_driver_id→fm_fleet_drivers(id)created_by→users(id)organization_id→pf_organizations(id)site_id→pf_sites(id)updated_by→users(id)
fm_fleet_vehicles_delete(DELETE)fm_fleet_vehicles_insert(INSERT)fm_fleet_vehicles_select(SELECT)fm_fleet_vehicles_update(UPDATE)
fm_inventory_item_locations
Junction table tracking quantity of each item at each location
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)inventory_item_id→fm_inventory_items(id)location_id→fm_inventory_locations(id)organization_id→pf_organizations(id)updated_by→pf_profiles(id)
fm_inventory_item_locations_delete(DELETE)fm_inventory_item_locations_insert(INSERT)fm_inventory_item_locations_select(SELECT)fm_inventory_item_locations_update(UPDATE)
fm_inventory_items
Master inventory item records with quantity, cost, and reorder management
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)default_location_id→fm_inventory_locations(id)organization_id→pf_organizations(id)site_id→pf_sites(id)updated_by→pf_profiles(id)
fm_inventory_items_delete(DELETE)fm_inventory_items_insert(INSERT)fm_inventory_items_select(SELECT)fm_inventory_items_update(UPDATE)
fm_inventory_locations
Storage locations for inventory items (warehouses, sites, vehicles)
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)organization_id→pf_organizations(id)site_id→pf_sites(id)updated_by→pf_profiles(id)
fm_inventory_locations_delete(DELETE)fm_inventory_locations_insert(INSERT)fm_inventory_locations_select(SELECT)fm_inventory_locations_update(UPDATE)
fm_inventory_transactions
Append-only transaction history for all inventory movements - DO NOT UPDATE OR DELETE
RLS: ✅ enabled (2 policies)
Foreign keys:
created_by→pf_profiles(id)inventory_item_id→fm_inventory_items(id)location_id→fm_inventory_locations(id)organization_id→pf_organizations(id)transfer_from_location_id→fm_inventory_locations(id)transfer_to_location_id→fm_inventory_locations(id)updated_by→users(id)work_order_id→fm_work_orders(id)
fm_inventory_transactions_insert(INSERT)fm_inventory_transactions_select(SELECT)
fm_module_settings
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)organization_id→pf_organizations(id)updated_by→pf_profiles(id)
fm_module_settings_delete(DELETE)fm_module_settings_insert(INSERT)fm_module_settings_select(SELECT)fm_module_settings_update(UPDATE)
fm_pm_completions
RLS: ✅ enabled (2 policies)
Foreign keys:
completed_by→pf_profiles(id)organization_id→pf_organizations(id)pm_schedule_id→fm_pm_schedules(id)work_order_id→fm_work_orders(id)
fm_pm_completions_insert(INSERT)fm_pm_completions_select(SELECT)
fm_pm_schedules
RLS: ✅ enabled (4 policies)
Foreign keys:
asset_id→fm_assets(id)created_by→pf_profiles(id)last_completed_work_order_id→fm_work_orders(id)organization_id→pf_organizations(id)pm_template_id→fm_pm_templates(id)site_id→pf_sites(id)updated_by→pf_profiles(id)
fm_pm_schedules_delete(DELETE)fm_pm_schedules_insert(INSERT)fm_pm_schedules_select(SELECT)fm_pm_schedules_update(UPDATE)
fm_pm_template_checklist_items
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)organization_id→pf_organizations(id)pm_template_id→fm_pm_templates(id)updated_by→pf_profiles(id)
fm_pm_checklist_delete(DELETE)fm_pm_checklist_insert(INSERT)fm_pm_checklist_select(SELECT)fm_pm_checklist_update(UPDATE)
fm_pm_template_materials
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)inventory_item_id→fm_inventory_items(id)organization_id→pf_organizations(id)pm_template_id→fm_pm_templates(id)updated_by→users(id)
fm_pm_materials_delete(DELETE)fm_pm_materials_insert(INSERT)fm_pm_materials_select(SELECT)fm_pm_materials_update(UPDATE)
fm_pm_templates
Preventive maintenance template definitions
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)default_assigned_to_vendor_id→fm_vendors(id)organization_id→pf_organizations(id)updated_by→pf_profiles(id)
fm_pm_templates_delete(DELETE)fm_pm_templates_insert(INSERT)fm_pm_templates_select(SELECT)fm_pm_templates_update(UPDATE)
fm_vendor_certifications
FM-03: Vendor certifications with expiration tracking
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)document_id→pf_documents(id)organization_id→pf_organizations(id)updated_by→pf_profiles(id)vendor_id→fm_vendors(id)
fm_vendor_certs_delete(DELETE)fm_vendor_certs_insert(INSERT)fm_vendor_certs_select(SELECT)fm_vendor_certs_update(UPDATE)
fm_vendor_sites
FM-03: Junction table linking vendors to sites they service
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)organization_id→pf_organizations(id)site_id→pf_sites(id)updated_by→users(id)vendor_id→fm_vendors(id)
fm_vendor_sites_delete(DELETE)fm_vendor_sites_insert(INSERT)fm_vendor_sites_select(SELECT)fm_vendor_sites_update(UPDATE)
fm_vendor_work_orders
FM-03: Vendor assignments to work orders
RLS: ✅ enabled (4 policies)
Foreign keys:
assigned_by→pf_profiles(id)invoice_document_id→pf_documents(id)organization_id→pf_organizations(id)quote_document_id→pf_documents(id)updated_by→pf_profiles(id)vendor_id→fm_vendors(id)work_order_id→fm_work_orders(id)
fm_vendor_wo_delete(DELETE)fm_vendor_wo_insert(INSERT)fm_vendor_wo_select(SELECT)fm_vendor_wo_update(UPDATE)
fm_vendors
FM-03: Vendor master records for facilities management
RLS: ✅ enabled (4 policies)
Foreign keys:
approved_by→pf_profiles(id)created_by→pf_profiles(id)organization_id→pf_organizations(id)updated_by→pf_profiles(id)
fm_vendors_delete(DELETE)fm_vendors_insert(INSERT)fm_vendors_select(SELECT)fm_vendors_update(UPDATE)
fm_work_order_attachments
FM-01: Photos, documents, and files attached to work orders
RLS: ✅ enabled (3 policies)
Foreign keys:
organization_id→pf_organizations(id)uploaded_by→pf_profiles(id)work_order_id→fm_work_orders(id)
fm_work_order_attachments_delete(DELETE)fm_work_order_attachments_insert(INSERT)fm_work_order_attachments_select(SELECT)
fm_work_order_history
FM-01: Audit trail of all changes to work orders
RLS: ✅ enabled (2 policies)
Foreign keys:
organization_id→pf_organizations(id)performed_by→pf_profiles(id)work_order_id→fm_work_orders(id)
fm_work_order_history_insert(INSERT)fm_work_order_history_select(SELECT)
fm_work_order_materials
FM-01: Materials and inventory items used on work orders (integrates with FM-02)
RLS: ✅ enabled (4 policies)
Foreign keys:
created_by→pf_profiles(id)organization_id→pf_organizations(id)updated_by→users(id)used_by→pf_profiles(id)work_order_id→fm_work_orders(id)
fm_work_order_materials_delete(DELETE)fm_work_order_materials_insert(INSERT)fm_work_order_materials_select(SELECT)fm_work_order_materials_update(UPDATE)
fm_work_orders
FM-01: Work orders for facilities maintenance requests and tasks
RLS: ✅ enabled (4 policies)
Foreign keys:
assigned_by→pf_profiles(id)closed_by→pf_profiles(id)completed_by→pf_profiles(id)created_by→pf_profiles(id)organization_id→pf_organizations(id)requester_id→pf_profiles(id)site_id→pf_sites(id)updated_by→pf_profiles(id)
fm_work_orders_delete(DELETE)fm_work_orders_insert(INSERT)fm_work_orders_select(SELECT)fm_work_orders_update(UPDATE)