backend/migrations · gitlab/main f232114 · 2026-09-13 03:19 GMT+8

iPig 資料表關係全圖

從 migration 檔機械解析產生,不是手畫的:14 支 migration(跳過 003_seed.sql)、175 張表、365 條 FK。上半頁是檢查清單——資料庫沒有替你守住的關聯;下半頁是依領域分開的 ER 圖與每張表的欄位明細。

資料表
175
另有 14 張分區子表
FK 約束
365
91 條 CASCADE
漏建 FK
6
另 6 項待確認
文字編號關聯
4
含動物↔計畫分派
多型關聯
14
1 項型別不符
規格 ERD 未畫
114
共 175 張

檢查清單

依嚴重程度排列。「要修」是資料庫目前擋不住錯誤資料的地方;「要看」需要你判斷是否刻意;「參考」是品質與文件層面的缺口。

要修

看起來是關聯,但資料庫沒有 FK 約束

12

欄位名稱像外鍵(_id_by),值也確實指向別張表,卻沒有 FOREIGN KEY。資料庫不會擋孤兒資料。其中 6 項判定為單純漏建,其餘各有成因。

欄位型別判定應指向說明
ai_query_logs.api_key_iduuid NN缺 FKai_api_keysPG16 允許分區母表建 FK 指向一般表。目前查詢紀錄可以指向已不存在的 API key。
amendment_status_history.changed_byuuid NN缺 FKusersNOT NULL 的行為人欄位。同一族的 amendment_versions.submitted_by 有 FK,它沒有。
ip_blocklist.alert_iduuid缺 FKsecurity_alerts封鎖紀錄指向觸發它的警報,資料庫不檢查。
observation_vet_reads.observation_iduuid NN缺 FKanimal_observations「獸醫已讀」可以指向不存在的觀察紀錄。同一張表的 vet_user_id 有 FK。
risk_register.related_nc_iduuid缺 FKqa_non_conformances風險登錄連到不符合事項,資料庫不檢查。
surgery_vet_reads.surgery_iduuid NN缺 FKanimal_surgeries同上,對應手術紀錄。
security_alerts.activity_log_iduuid結構上建不了user_activity_logsuser_activity_logs 的主鍵是 (id, partition_date),單欄 FK 建不起來。要約束就得連 partition_date 一起存。
user_activity_logs.session_iduuid可能是刻意的user_sessions稽核紀錄必須在 session 清掉之後仍保留,不綁 FK 很可能是刻意的——但沒有註解寫明。
audit_chain_known_breaks.recorded_bytext存文字不存 idusers存的是文字。要追到帳號應為 uuid FK;若刻意要在帳號刪除後仍可讀,建議在 migration 註解寫明。
equipment_calibrations.performed_byvarchar存文字不存 idusers人名自由文字。外部校正廠商執行時合理;內部人員執行時就追不到帳號。
equipment_maintenance_records.performed_byvarchar存文字不存 idusers同上,維修紀錄。
animals.animal_iduuid用途不明animals 表裡有一欄叫 animal_id 的 uuid,沒有 FK,也看不出指向哪裡。可能是舊系統遷移留下的,值得查是否還有人寫入。
要修

用文字編號關聯,而不是 id

4

另一張表有 UNIQUE 的文字欄位,這裡存了同名欄位卻沒有 FK。對方改號或刪除時,這邊不會被擋,也不會跟著變。最重要的是第一列:動物和計畫之間的分派關係,整個系統都是用文字 JOIN 的。

欄位型別判定對應到說明
animals.iacuc_novarchar文字鍵,沒有 FKprotocols.iacuc_no「這頭豬屬於哪個計畫」實際上靠這一欄。後端的權限檢查(services/access.rs)、病歷報表、安樂死流程都用 animals.iacuc_no = protocols.iacuc_no 做 JOIN。計畫改 IACUC 編號或打錯一個字,動物就默默脫離計畫,權限跟著失效。animals 另有 reserved_protocol_id FK,但那是「預留」,不是「分派」。
documents.iacuc_novarchar文字鍵,沒有 FKprotocols.iacuc_noERP 單據用文字編號掛到計畫;費用歸屬計畫時靠它,斷鏈風險同上。
role_training_requirements.role_codevarchar文字鍵,沒有 FKroles.codenotification_routing.role_code 有 FK 指向 roles(code),這張沒有。角色改碼或刪除時,訓練要求會指向不存在的角色。
animal_sudden_deaths.iacuc_novarchar可能是刻意的protocols.iacuc_no猝死當下的計畫編號。如果是刻意保存當時的快照就合理;如果拿來查計畫,斷鏈風險和 animals.iacuc_no 一樣。
stock_ledger.doc_novarchar設計上不綁documents.doc_no同一張表已有 doc_id FK,doc_no 是冗餘的單號快照。
expiry_monthly_snapshots.skuvarchar設計上不綁products.sku月快照保存當時的 SKU,同一張表另有 product_id FK。
要看

migration 011 留下的備份表

3

011 為了能回退,建了 mig011_conversion_backupmig011_inserted_conversionmig011_pack_unit_backup,但沒有任何 migration 把它們 DROP。011 的註解(L90–91)原文:「這三張表在正式環境預期是空的(實查換算表目前 0 列)。確認本 migration 不再需要回退後可自行 DROP。」——這是一個手動步驟,沒寫進 TODO 就會一直留在 schema 裡。

要修

多型關聯(type + id 兩欄)

14

一個 id 欄配一個「類型」欄,指向哪張表由類型決定。PostgreSQL 無法替這種關聯建 FK,完整性全靠應用層。其中 record_annotations.record_id 是 integer,但全系統只有 sku_subcategories 用整數主鍵,其餘都是 uuid——它指不到任何一筆 uuid 紀錄。

id 欄位類型欄id 型別
animal_record_attachments.record_idrecord_typeuuid
attachments.entity_identity_typevarchar
audit_logs.entity_identity_typeuuid
care_medication_records.record_idrecord_typeuuid
change_reasons.entity_identity_typetext
electronic_signatures.entity_identity_typevarchar
journal_entries.source_entity_idsource_entity_typeuuid
notifications.related_entity_idrelated_entity_typeuuid
pdf_artifacts.resource_idresource_typetext
protocol_activities.target_entity_idtarget_entity_typeuuid
qa_inspections.related_entity_idrelated_entity_typeuuid
record_annotations.record_idrecord_typeinteger 型別不符
record_versions.record_idrecord_typeuuid
user_activity_logs.entity_identity_typeuuid
要看

刪掉一筆會連帶刪掉什麼

91 條 CASCADE

沿 ON DELETE CASCADE 往下展開的完整範圍(下標是第幾層)。綠底的表有 migration 012 的鎖定觸發器,is_locked = true 時會擋 DELETE;其他的沒有。「後端硬刪」是 backend/srcDELETE FROM <表> 的出現處數。注意:只要還有任何 NO ACTION 的 FK 指著那筆資料,刪除會整個失敗,CASCADE 就不會發生。

刪除波及表數後端硬刪會被一起刪的表
users230annual_leave_entitlementsattendance_recordscomp_time_balancesleave_requestsmessage_thread_participantsnotification_settingsnotificationsovertime_recordspassword_reset_tokenspi_account_invitesrefresh_tokenssignature_bridge_sessionstraining_recordsuser_activity_aggregatesuser_aup_profilesuser_mcp_keysuser_preferencesuser_protocolsuser_rolesuser_sessionscalendar_event_sync2leave_approvals2overtime_approvals2
protocols161 處amendmentspi_account_invitesprotocol_activitiesprotocol_ai_reviewsprotocol_attachmentsprotocol_notice_acknowledgementsprotocol_versionsreview_assignmentsreview_round_historyuser_protocolsvet_review_assignmentsprotocol_pi_delegatesamendment_review_assignments2amendment_status_history2amendment_versions2review_comments2
animals120animal_blood_testsanimal_field_correction_requestsanimal_observationsanimal_pathology_reportsanimal_sacrificesanimal_surgeriesanimal_vaccinationsanimal_weightseuthanasia_ordersvet_patrol_entry_animalsanimal_blood_test_items2euthanasia_appeals2
products21 處product_uom_conversionsstorage_location_inventory
documents11 處document_lines
equipment71 處equipment_annual_plansequipment_calibrationsequipment_disposalsequipment_idle_requestsequipment_maintenance_recordsequipment_status_logsequipment_suppliers
amendments30amendment_review_assignmentsamendment_status_historyamendment_versions
euthanasia_orders10euthanasia_appeals
參考

外鍵欄位沒有索引

168

FK 欄位不在任何索引的開頭。影響兩件事:依關聯查詢時要掃表,刪除或更新被參照的列時要逐表掃描檢查。其中 132 條指向 users(多為 created_by 這類行為人欄位,使用者幾乎不會被刪,影響小),下表只列其餘 36 條。

欄位指向
amendments.created_delegation_idprotocol_pi_delegates
amendments.submitted_delegation_idprotocol_pi_delegates
animals.source_idanimal_sources
ap_payments.journal_entry_idjournal_entries
application_notices.attachment_idattachments
ar_receipts.journal_entry_idjournal_entries
blood_test_panel_items.template_idblood_test_templates
calendar_sync_conflicts.calendar_event_sync_idcalendar_event_sync
calendar_sync_conflicts.leave_request_idleave_requests
calendar_sync_conflicts.new_approval_request_idleave_requests
chart_of_accounts.parent_idchart_of_accounts
electronic_signatures.delegation_idprotocol_pi_delegates
environment_monitoring_points.zone_idzones
equipment_disposals.applicant_signature_idelectronic_signatures
equipment_disposals.approver_signature_idelectronic_signatures
equipment_idle_requests.applicant_signature_idelectronic_signatures
equipment_idle_requests.approver_signature_idelectronic_signatures
equipment_maintenance_records.reviewer_signature_idelectronic_signatures
euthanasia_appeals.delegation_idprotocol_pi_delegates
expiry_monthly_snapshots.product_idproducts
expiry_monthly_snapshots.warehouse_idwarehouses
line_shelf_allocations.product_idproducts
notification_routing.role_coderoles
pdf_artifacts.attachment_idattachments
product_uom_conversions.product_id, base_uomproducts
protocol_notice_acknowledgements.notice_attachment_idattachments
protocol_notice_acknowledgements.signature_idelectronic_signatures
protocols.close_pi_signature_idelectronic_signatures
protocols.close_sd_signature_idelectronic_signatures
qa_non_conformances.related_inspection_idqa_inspections
qa_schedule_items.related_inspection_idqa_inspections
record_annotations.signature_idelectronic_signatures
report_history.scheduled_report_idscheduled_reports
role_permissions.permission_idpermissions
study_final_reports.signature_idelectronic_signatures
personnel_affiliations.department_iddepartments
參考

沒有任何 FK 進出的表

14

和其他表之間一條約束都沒有。設定表、序號表本來就該獨立;存了關聯值卻是孤島的,就是漏掉的地方。

橘框:本頁其他檢查已發現它其實有關聯。

參考

後端程式碼幾乎沒用到的表

14

backend/src(418 個檔)裡表名出現 ≤ 2 次。沒有任何表是 0 次,所以沒有死表;出現 1 次通常只是資料匯出清單,代表功能可能還沒接上。

出現次數所在領域
affiliation_types1身分・權限・組織
export_jobs1平台・通知・稽核軌跡
import_jobs1平台・通知・稽核軌跡
mig011_conversion_backup1ERP・庫存
mig011_inserted_conversion1ERP・庫存
mig011_pack_unit_backup1ERP・庫存
personnel_affiliations1身分・權限・組織
protocol_attachments1AUP 計畫審查
review_round_history1AUP 計畫審查
user_aup_profiles1身分・權限・組織
document_acknowledgments2QA・GLP 合規
observation_vet_reads2動物與獸醫紀錄
surgery_vet_reads2動物與獸醫紀錄
user_activity_aggregates2平台・通知・稽核軌跡
參考

規格文件的 ERD 沒畫到的表

114 / 175

docs/spec/architecture/database_erd.md 裡 mermaid 圖出現過的實體共 66 個,下列資料表一次都沒出現。

參考

名字像外鍵、複核後不算遺漏

8

腳本用欄位名稱抓出來、逐一看過定義之後排除的項目,列出來避免下次重查。

欄位型別判定說明
animals.lab_animal_idvarchar外部系統 ID外部實驗動物編號(varchar)。
calendar_event_sync.google_event_idvarchar外部系統 IDGoogle Calendar 事件 ID。
event_outbox.source_entity_iduuid設計上不綁outbox 事件來源,指向哪張表由事件類型決定,本質上是多型。
google_calendar_config.calendar_idvarchar外部系統 IDGoogle Calendar ID。
google_calendar_config.event_color_idvarchar外部系統 IDGoogle Calendar 顏色代碼。
partners.tax_idvarchar外部系統 ID統一編號。
refresh_tokens.family_iduuid設計上不綁refresh token 輪替用的家族群組碼,不指向任何表。
mig011_conversion_backup.product_iduuid設計上不綁migration 011 的回退備份表,刻意不綁。

領域總覽

10 個領域

箭頭方向=「引用」,數字是跨領域的 FK 條數。每個領域都大量引用 users(全系統 190 條),為了看得出結構,指向「身分・權限・組織」的箭頭一律省略。領域是依表名前綴分的,不是資料庫裡的 schema。

flowchart LR
  identity["身分・權限・組織<br/>21 張"]
  aup["AUP 計畫審查<br/>20 張"]
  animal["動物與獸醫紀錄<br/>36 張"]
  facility["設施與環境<br/>6 張"]
  erp["ERP・庫存<br/>20 張"]
  accounting["會計<br/>5 張"]
  hr["人事・出勤・行事曆<br/>15 張"]
  equipment["設備與校正<br/>9 張"]
  qa["QA・GLP 合規<br/>22 張"]
  platform["平台・通知・稽核軌跡<br/>21 張"]
  aup -->|6| qa
  animal -->|5| aup
  equipment -->|5| qa
  equipment -->|3| erp
  accounting -->|2| erp
  aup -->|2| platform
  animal -->|2| erp
  animal -->|1| facility
  erp -->|1| aup
  qa -->|1| aup
  platform -->|1| qa
  identity -->|1| aup

身分・權限・組織

21 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(1 條)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  affiliation_types {
    uuid id PK
    varchar code UK
  }
  ai_api_keys {
    uuid id PK
    varchar key_hash UK
    uuid created_by FK
  }
  departments {
    uuid id PK
    varchar code UK
    uuid parent_id FK
    uuid manager_id FK
  }
  invitation_roles {
    uuid invitation_id PK, FK
    uuid role_id PK, FK
  }
  invitations {
    uuid id PK
    varchar invitation_token UK
    uuid invited_by FK
    uuid created_user_id FK
  }
  ip_blocklist {
    uuid id PK
    uuid alert_id "無 FK"
    uuid blocked_by FK
    uuid unblocked_by FK
  }
  jwt_blacklist {
    varchar jti PK
  }
  login_events {
    uuid id PK
    uuid user_id FK
  }
  password_reset_tokens {
    uuid id PK
    uuid user_id FK
  }
  permissions {
    uuid id PK
    varchar code UK
  }
  personnel_affiliations {
    uuid id PK
    uuid user_id FK
    uuid affiliation_type_id FK
    uuid department_id FK
  }
  pi_account_invites {
    uuid id PK
    uuid protocol_id FK
    uuid pi_user_id FK
    uuid provisioned_by FK
    uuid approved_by FK
  }
  refresh_tokens {
    uuid id PK
    uuid user_id FK
  }
  role_permissions {
    uuid role_id PK, FK
    uuid permission_id PK, FK
  }
  roles {
    uuid id PK
    varchar code UK
  }
  user_aup_profiles {
    uuid user_id PK, FK
  }
  user_mcp_keys {
    uuid id PK
    uuid user_id FK
    text key_hash UK
  }
  user_preferences {
    uuid id PK
    uuid user_id FK
  }
  user_roles {
    uuid user_id PK, FK
    uuid role_id PK, FK
    uuid assigned_by FK
  }
  user_sessions {
    uuid id PK
    uuid user_id FK
    uuid refresh_token_id FK
  }
  users {
    uuid id PK
    varchar email UK
    uuid department_id FK
  }
  users ||--o{ ai_api_keys : "created_by"
  users |o--o{ departments : "manager_id"
  departments |o--o{ departments : "parent_id"
  invitations ||--o{ invitation_roles : "invitation_id · CASCADE"
  roles ||--o{ invitation_roles : "role_id"
  users |o--o{ invitations : "created_user_id"
  users ||--o{ invitations : "invited_by"
  users |o--o{ ip_blocklist : "blocked_by"
  users |o--o{ ip_blocklist : "unblocked_by"
  users |o--o{ login_events : "user_id"
  users ||--o{ password_reset_tokens : "user_id · CASCADE"
  users ||--o{ personnel_affiliations : "user_id"
  affiliation_types ||--o{ personnel_affiliations : "affiliation_type_id"
  departments |o--o{ personnel_affiliations : "department_id"
  users |o--o{ pi_account_invites : "approved_by"
  users ||--o{ pi_account_invites : "pi_user_id · CASCADE"
  protocols ||--o{ pi_account_invites : "protocol_id · CASCADE"
  users ||--o{ pi_account_invites : "provisioned_by"
  users ||--o{ refresh_tokens : "user_id · CASCADE"
  permissions ||--o{ role_permissions : "permission_id · CASCADE"
  roles ||--o{ role_permissions : "role_id · CASCADE"
  users ||--o| user_aup_profiles : "user_id · CASCADE"
  users ||--o{ user_mcp_keys : "user_id · CASCADE"
  users ||--o{ user_preferences : "user_id · CASCADE"
  users |o--o{ user_roles : "assigned_by"
  roles ||--o{ user_roles : "role_id · CASCADE"
  users ||--o{ user_roles : "user_id · CASCADE"
  refresh_tokens |o--o{ user_sessions : "refresh_token_id"
  users ||--o{ user_sessions : "user_id · CASCADE"
  departments |o--o{ users : "department_id"
  security_alerts |o..o{ ip_blocklist : "alert_id(無 FK)"
affiliation_types13 欄 · FK 出 0 / 入 1004_personnel_affiliations.sql:19
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
is_internalbooleanNOT NULL
default_eligible_annual_leavebooleanNOT NULL
default_eligible_leavebooleanNOT NULL
default_eligible_overtimebooleanNOT NULL
default_assignable_to_protocolbooleanNOT NULL
default_requires_leave_proxybooleanNOT NULL
sort_orderintegerNOT NULL
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 1 次 · 被這些表引用:personnel_affiliations

ai_api_keys13 欄 · FK 出 1 / 入 0002_schema.sql:1536
欄位型別NULL指向
iduuidNOT NULLPK
namevarcharNOT NULL
key_hashvarcharNOT NULLUK
key_prefixvarcharNOT NULL
created_byuuidNOT NULLFKusers
scopesjsonbNOT NULL
is_activebooleanNOT NULL
expires_attimestamptz
last_used_attimestamptz
usage_countbigintNOT NULL
rate_limit_per_minuteintegerNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 10 次 · 沒有表引用它

departments10 欄 · FK 出 2 / 入 3002_schema.sql:2837
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
parent_iduuidFKdepartments
manager_iduuidFKusers
is_activebooleanNOT NULL
configjsonb
sort_orderintegerNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 38 次 · 被這些表引用:departmentspersonnel_affiliationsusers

invitation_roles2 欄 · FK 出 2 / 入 0002_schema.sql:3645
欄位型別NULL指向
invitation_iduuidNOT NULLPKFKinvitations CASCADE
role_iduuidNOT NULLPKFKroles RESTRICT

backend/src 出現 8 次 · 沒有表引用它

invitations15 欄 · FK 出 2 / 入 1002_schema.sql:3655
欄位型別NULL指向
iduuidNOT NULLPK
emailvarcharNOT NULL
organizationvarchar
invitation_tokenvarcharNOT NULLUK
invited_byuuidNOT NULLFKusers
statusvarcharNOT NULL
expires_attimestamptzNOT NULL
accepted_attimestamptz
created_user_iduuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
display_namevarchar
phonevarchar
positionvarchar
is_internalbooleanNOT NULL

backend/src 出現 36 次 · 被這些表引用:invitation_roles

ip_blocklist14 欄 · FK 出 2 / 入 0002_schema.sql:3686
欄位型別NULL指向
iduuidNOT NULLPK
ip_addressinetNOT NULL
reasontextNOT NULL
sourcetextNOT NULL
alert_iduuid無 FK
blocked_attimestamptzNOT NULL
blocked_untiltimestamptz
blocked_byuuidFKusers
hit_countbigintNOT NULL
last_hit_attimestamptz
unblocked_attimestamptz
unblocked_byuuidFKusers
unblocked_reasontext
metadatajsonb

backend/src 出現 23 次 · 沒有表引用它

jwt_blacklist3 欄 · FK 出 0 / 入 0002_schema.sql:3753
欄位型別NULL指向
jtivarcharNOT NULLPK
expires_attimestamptzNOT NULL
revoked_attimestamptzNOT NULL

backend/src 出現 25 次 · 沒有表引用它

login_events19 欄 · FK 出 1 / 入 1002_schema.sql:3851
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidFKusers
emailvarcharNOT NULL
event_typevarcharNOT NULL
ip_addressinet
user_agenttext
device_typevarchar
browservarchar
osvarchar
geo_countryvarchar
geo_cityvarchar
geo_timezonevarchar
is_unusual_timeboolean
is_unusual_locationboolean
is_new_deviceboolean
is_mass_loginboolean
device_fingerprintvarchar
failure_reasonvarchar
created_attimestamptzNOT NULL

backend/src 出現 39 次 · 被這些表引用:security_alerts

password_reset_tokens6 欄 · FK 出 1 / 入 0002_schema.sql:4210
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
token_hashvarcharNOT NULL
expires_attimestamptzNOT NULL
used_attimestamptz
created_attimestamptzNOT NULL

backend/src 出現 8 次 · 沒有表引用它

permissions6 欄 · FK 出 0 / 入 1002_schema.sql:4306
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
modulevarchar
descriptiontext
created_attimestamptzNOT NULL

backend/src 出現 138 次 · 被這些表引用:role_permissions

personnel_affiliations14 欄 · FK 出 3 / 入 0004_personnel_affiliations.sql:43
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers
affiliation_type_iduuidNOT NULLFKaffiliation_types
effective_fromdateNOT NULL
effective_todate
eligible_annual_leavebooleanNOT NULL
eligible_leavebooleanNOT NULL
eligible_overtimebooleanNOT NULL
assignable_to_protocolbooleanNOT NULL
requires_leave_proxybooleanNOT NULL
department_iduuidFKdepartments
notetext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 1 次 · 沒有表引用它

pi_account_invites11 欄 · FK 出 4 / 入 0002_schema.sql:4320
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKprotocols CASCADE
pi_user_iduuidNOT NULLFKusers CASCADE
emailvarcharNOT NULL
statusvarcharNOT NULL
provisioned_byuuidNOT NULLFKusers
provisioned_attimestamptzNOT NULL
approved_byuuidFKusers
sent_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 10 次 · 沒有表引用它

refresh_tokens12 欄 · FK 出 1 / 入 1002_schema.sql:4831
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
token_hashvarcharNOT NULL
expires_attimestamptzNOT NULL
created_attimestamptzNOT NULL
revoked_attimestamptz
family_iduuidNOT NULL
revoked_reasontext
last_used_attimestamptzNOT NULL
rotated_attimestamptz
last_iptext
last_user_agenttext

backend/src 出現 16 次 · 被這些表引用:user_sessions

role_permissions2 欄 · FK 出 2 / 入 0002_schema.sql:4988
欄位型別NULL指向
role_iduuidNOT NULLPKFKroles CASCADE
permission_iduuidNOT NULLPKFKpermissions CASCADE

backend/src 出現 39 次 · 沒有表引用它

roles9 欄 · FK 出 0 / 入 4002_schema.sql:5013
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
descriptiontext
is_internalbooleanNOT NULL
is_systembooleanNOT NULL
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 238 次 · 被這些表引用:invitation_rolesnotification_routingrole_permissionsuser_roles

user_aup_profiles7 欄 · FK 出 1 / 入 0002_schema.sql:5975
欄位型別NULL指向
user_iduuidNOT NULLPKFKusers CASCADE
training_recordsjsonb
research_experiencetext
animal_experiencetext
certificationsjsonb
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 1 次 · 沒有表引用它

user_mcp_keys10 欄 · FK 出 1 / 入 0002_schema.sql:5990
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
key_hashtextNOT NULLUK
key_prefixvarcharNOT NULL
nametextNOT NULL
last_used_attimestamptz
created_attimestamptzNOT NULL
revoked_attimestamptz
scopestext[]NOT NULL
expires_attimestamptz

backend/src 出現 10 次 · 沒有表引用它

user_preferences6 欄 · FK 出 1 / 入 0002_schema.sql:6043
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
preference_keyvarcharNOT NULL
preference_valuejsonbNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 17 次 · 沒有表引用它

user_roles4 欄 · FK 出 3 / 入 0002_schema.sql:6070
欄位型別NULL指向
user_iduuidNOT NULLPKFKusers CASCADE
role_iduuidNOT NULLPKFKroles CASCADE
assigned_attimestamptz
assigned_byuuidFKusers

backend/src 出現 67 次 · 沒有表引用它

user_sessions13 欄 · FK 出 2 / 入 0002_schema.sql:6082
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
started_attimestamptzNOT NULL
ended_attimestamptz
last_activity_attimestamptzNOT NULL
refresh_token_iduuidFKrefresh_tokens SET NULL
ip_addressinet
user_agenttext
device_fingerprintvarchar
page_view_countinteger
action_countinteger
is_activeboolean
ended_reasonvarchar

backend/src 出現 20 次 · 沒有表引用它

users32 欄 · FK 出 1 / 入 190002_schema.sql:6103
欄位型別NULL指向
iduuidNOT NULLPK
emailvarcharNOT NULLUK
password_hashvarcharNOT NULL
display_namevarcharNOT NULL
phonevarchar
phone_extvarchar
organizationvarchar
is_internalbooleanNOT NULL
is_activebooleanNOT NULL
must_change_passwordbooleanNOT NULL
last_login_attimestamptz
login_attemptsintegerNOT NULL
locked_untiltimestamptz
theme_preferencevarcharNOT NULL
language_preferencevarcharNOT NULL
entry_datedate
positionvarchar
aup_rolesvarchar[]
years_experienceintegerNOT NULL
trainingsjsonbNOT NULL
deleted_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
totp_enabledbooleanNOT NULL
totp_secret_encryptedtext
totp_backup_codestext[]
versionintegerNOT NULL
expires_attimestamptz
last_totp_stepbigint
tokens_valid_aftertimestamptz
work_shiftvarcharNOT NULL
department_iduuidFKdepartments SET NULL

backend/src 出現 431 次 · 被這些表引用:ai_api_keysamendment_review_assignmentsamendment_versionsamendmentsanimal_blood_test_itemsanimal_blood_testsanimal_field_correction_requestsanimal_import_batchesanimal_observationsanimal_pathology_reportsanimal_sacrificesanimal_sudden_deathsanimal_surgeriesanimal_transfersanimal_vaccinationsanimal_vet_advice_recordsanimal_vet_advicesanimal_weightsanimalsannual_leave_entitlementsap_paymentsapplication_noticesar_receiptsattachmentsattendance_recordsaudit_logscalendar_sync_conflictscalendar_sync_historycare_medication_recordschange_reasonschange_requestscomp_time_balancescompetency_assessmentscontrolled_documentsdepartmentsdocument_acknowledgmentsdocument_revisionsdocumentselectronic_signaturesenvironment_readingsequipment_disposalsequipment_idle_requestsequipment_maintenance_recordsequipment_status_logseuthanasia_appealseuthanasia_byproduct_sampleseuthanasia_ordersevent_outboxexpiry_notification_configexport_jobsformulation_recordsimport_jobsinvitationsip_blocklistjournal_entriesleave_approvalsleave_requestsline_shelf_allocationslogin_eventsmanagement_reviewsmessage_attachmentsmessage_thread_participantsmessage_threadsmessagesnotification_settingsnotificationsobservation_vet_readsovertime_approvalsovertime_recordspassword_reset_tokenspdf_artifactspersonnel_affiliationspi_account_invitesplanned_experimentsproductsprotocol_activitiesprotocol_ai_reviewsprotocol_attachmentsprotocol_notice_acknowledgementsprotocol_pi_delegatesprotocol_template_versionsprotocol_versionsprotocolsqa_audit_schedulesqa_capaqa_inspectionsqa_non_conformancesqa_schedule_itemsqa_sop_acknowledgmentsqa_sop_documentsrecord_annotationsrecord_versionsreference_standardsrefresh_tokensreport_historyreview_assignmentsreview_commentsreview_round_historyrisk_registerscheduled_reportssecurity_alertssignature_bridge_sessionsstudy_final_reportssurgery_vet_readssystem_settingstraining_recordstransfer_vet_evaluationstreatment_drug_optionsuser_activity_aggregatesuser_activity_logsuser_aup_profilesuser_mcp_keysuser_preferencesuser_protocolsuser_rolesuser_sessionsvet_patrol_entry_photosvet_patrol_photosvet_patrol_reportsvet_review_assignments

AUP 計畫審查

20 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(1 條)。為了可讀,省略指向 users 的 33 條 FK(明細表裡有)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  amendment_review_assignments {
    uuid id PK
    uuid amendment_id FK
    uuid reviewer_id FK
    uuid assigned_by FK
  }
  amendment_status_history {
    uuid id PK
    uuid amendment_id FK
    uuid changed_by "無 FK"
  }
  amendment_versions {
    uuid id PK
    uuid amendment_id FK
    uuid submitted_by FK
  }
  amendments {
    uuid id PK
    uuid protocol_id FK
    uuid submitted_by FK
    uuid classified_by FK
    uuid created_by FK
    uuid approved_signature_id FK
    uuid rejected_signature_id FK
    uuid created_delegation_id FK
    uuid submitted_delegation_id FK
  }
  application_notices {
    uuid id PK
    text version_label UK
    uuid attachment_id FK
    uuid created_by FK
  }
  planned_experiments {
    uuid id PK
    uuid protocol_id FK
    uuid created_by FK
  }
  protocol_activities {
    uuid id PK
    uuid protocol_id FK
    uuid actor_id FK
  }
  protocol_ai_reviews {
    uuid id PK
    uuid protocol_id FK
    uuid protocol_version_id FK
    uuid triggered_by FK
  }
  protocol_attachments {
    uuid id PK
    uuid protocol_version_id FK
    uuid protocol_id FK
    uuid uploaded_by FK
  }
  protocol_notice_acknowledgements {
    uuid id PK
    uuid protocol_id FK, UK
    uuid notice_id FK
    uuid signer_id FK
    uuid signature_id FK
    uuid notice_attachment_id FK
  }
  protocol_pi_delegates {
    uuid id PK
    uuid protocol_id FK
    uuid delegate_user_id FK
    uuid authorized_by FK
    uuid revoked_by FK
  }
  protocol_template_versions {
    uuid id PK
    text version_label UK
    uuid created_by FK
  }
  protocol_versions {
    uuid id PK
    uuid protocol_id FK
    uuid submitted_by FK
  }
  protocols {
    uuid id PK
    varchar protocol_no UK
    varchar iacuc_no UK
    uuid pi_user_id FK
    uuid created_by FK
    uuid study_director_user_id FK
    UUID close_pi_signature_id FK
    UUID close_sd_signature_id FK
  }
  review_assignments {
    uuid id PK
    uuid protocol_id FK
    uuid reviewer_id FK
    uuid assigned_by FK
  }
  review_comments {
    uuid id PK
    uuid protocol_version_id FK
    uuid protocol_id FK
    uuid reviewer_id FK
    uuid resolved_by FK
    uuid parent_comment_id FK
    uuid replied_by FK
    uuid drafted_by FK
  }
  review_round_history {
    uuid id PK
    uuid protocol_id FK
    uuid actor_id FK
  }
  study_final_reports {
    uuid id PK
    varchar report_number UK
    uuid protocol_id FK
    uuid signed_by FK
    uuid signature_id FK
    uuid qau_signed_by FK
  }
  user_protocols {
    uuid user_id PK, FK
    uuid protocol_id PK, FK
    uuid granted_by FK
  }
  vet_review_assignments {
    uuid id PK
    uuid protocol_id FK, UK
    uuid vet_id FK
    uuid assigned_by FK
  }
  amendments ||--o{ amendment_review_assignments : "amendment_id · CASCADE"
  amendments ||--o{ amendment_status_history : "amendment_id · CASCADE"
  amendments ||--o{ amendment_versions : "amendment_id · CASCADE"
  electronic_signatures |o--o{ amendments : "approved_signature_id"
  protocols ||--o{ amendments : "protocol_id · CASCADE"
  electronic_signatures |o--o{ amendments : "rejected_signature_id"
  protocol_pi_delegates |o--o{ amendments : "created_delegation_id"
  protocol_pi_delegates |o--o{ amendments : "submitted_delegation_id"
  attachments |o--o{ application_notices : "attachment_id"
  protocols |o--o{ planned_experiments : "protocol_id"
  protocols ||--o{ protocol_activities : "protocol_id · CASCADE"
  protocols ||--o{ protocol_ai_reviews : "protocol_id · CASCADE"
  protocol_versions |o--o{ protocol_ai_reviews : "protocol_version_id"
  protocols |o--o{ protocol_attachments : "protocol_id · CASCADE"
  protocol_versions |o--o{ protocol_attachments : "protocol_version_id · CASCADE"
  attachments |o--o{ protocol_notice_acknowledgements : "notice_attachment_id"
  application_notices ||--o{ protocol_notice_acknowledgements : "notice_id"
  protocols ||--o| protocol_notice_acknowledgements : "protocol_id · CASCADE"
  electronic_signatures |o--o{ protocol_notice_acknowledgements : "signature_id"
  protocols ||--o{ protocol_pi_delegates : "protocol_id · CASCADE"
  protocols ||--o{ protocol_versions : "protocol_id · CASCADE"
  electronic_signatures |o--o{ protocols : "close_pi_signature_id"
  electronic_signatures |o--o{ protocols : "close_sd_signature_id"
  protocols ||--o{ review_assignments : "protocol_id · CASCADE"
  review_comments |o--o{ review_comments : "parent_comment_id · CASCADE"
  protocols |o--o{ review_comments : "protocol_id"
  protocol_versions |o--o{ review_comments : "protocol_version_id · CASCADE"
  protocols ||--o{ review_round_history : "protocol_id · CASCADE"
  protocols ||--o{ study_final_reports : "protocol_id"
  electronic_signatures |o--o{ study_final_reports : "signature_id"
  protocols ||--o{ user_protocols : "protocol_id · CASCADE"
  protocols ||--o| vet_review_assignments : "protocol_id · CASCADE"
  users |o..o{ amendment_status_history : "changed_by(無 FK)"
amendment_review_assignments9 欄 · FK 出 3 / 入 0002_schema.sql:1610
欄位型別NULL指向
iduuidNOT NULLPK
amendment_iduuidNOT NULLFKamendments CASCADE
reviewer_iduuidFKusers
assigned_byuuidNOT NULLFKusers
assigned_attimestamptzNOT NULL
decisionvarchar
decided_attimestamptz
commenttext
reviewer_nametext

backend/src 出現 13 次 · 沒有表引用它

amendment_status_history7 欄 · FK 出 1 / 入 0002_schema.sql:1635
欄位型別NULL指向
iduuidNOT NULLPK
amendment_iduuidNOT NULLFKamendments CASCADE
from_statusamendment_status
to_statusamendment_statusNOT NULL
changed_byuuidNOT NULL無 FK
remarktext
created_attimestamptzNOT NULL

backend/src 出現 5 次 · 沒有表引用它

amendment_versions6 欄 · FK 出 2 / 入 0002_schema.sql:1650
欄位型別NULL指向
iduuidNOT NULLPK
amendment_iduuidNOT NULLFKamendments CASCADE
version_nointegerNOT NULL
content_snapshotjsonbNOT NULL
submitted_attimestamptzNOT NULL
submitted_byuuidNOT NULLFKusers

backend/src 出現 6 次 · 沒有表引用它

amendments25 欄 · FK 出 8 / 入 3002_schema.sql:1664
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKprotocols CASCADE
amendment_novarcharNOT NULL
revision_numberintegerNOT NULL
amendment_typeamendment_typeNOT NULL
statusamendment_statusNOT NULL
titlevarcharNOT NULL
descriptiontext
change_itemsvarchar[]
changes_contentjsonb
submitted_byuuidFKusers
submitted_attimestamptz
classified_byuuidFKusers
classified_attimestamptz
classification_remarktext
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
approved_signature_iduuidFKelectronic_signatures RESTRICT
rejected_signature_iduuidFKelectronic_signatures RESTRICT
effective_fromtimestamptz
versionintegerNOT NULL
is_historicalbooleanNOT NULL
created_delegation_iduuidFKprotocol_pi_delegates
submitted_delegation_iduuidFKprotocol_pi_delegates

backend/src 出現 90 次 · 被這些表引用:amendment_review_assignmentsamendment_status_historyamendment_versions

application_notices9 欄 · FK 出 2 / 入 1002_schema.sql:2256
欄位型別NULL指向
iduuidNOT NULLPK
version_labeltextNOT NULLUK
titletextNOT NULL
contenttextNOT NULL
attachment_iduuidFKattachments
effective_fromdateNOT NULL
is_activebooleanNOT NULL
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL

backend/src 出現 13 次 · 被這些表引用:protocol_notice_acknowledgements

planned_experiments8 欄 · FK 出 2 / 入 1002_schema.sql:4339
欄位型別NULL指向
iduuidNOT NULLPK
unittextNOT NULL
descriptiontext
demand_countintegerNOT NULL
protocol_iduuidFKprotocols SET NULL
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 7 次 · 被這些表引用:animals

protocol_activities14 欄 · FK 出 2 / 入 0002_schema.sql:4441
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKprotocols CASCADE
activity_typeprotocol_activity_typeNOT NULL
actor_iduuidNOT NULLFKusers
actor_namevarchar
actor_emailvarchar
from_valuetext
to_valuetext
target_entity_typevarchar
target_entity_iduuid
target_entity_namevarchar
remarktext
extra_datajsonb
created_attimestamptzNOT NULL

backend/src 出現 23 次 · 沒有表引用它

protocol_ai_reviews15 欄 · FK 出 3 / 入 0002_schema.sql:4463
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKprotocols CASCADE
protocol_version_iduuidFKprotocol_versions
review_typevarcharNOT NULL
rule_resultjsonb
ai_resultjsonb
ai_modelvarchar
ai_input_tokensinteger
ai_output_tokensinteger
total_errorsintegerNOT NULL
total_warningsintegerNOT NULL
scoreinteger
triggered_byuuidFKusers
duration_msinteger
created_attimestamptzNOT NULL

backend/src 出現 10 次 · 沒有表引用它

protocol_attachments9 欄 · FK 出 3 / 入 0002_schema.sql:4487
欄位型別NULL指向
iduuidNOT NULLPK
protocol_version_iduuidFKprotocol_versions CASCADE
protocol_iduuidFKprotocols CASCADE
file_namevarcharNOT NULL
file_pathvarcharNOT NULL
file_sizeintegerNOT NULL
mime_typevarcharNOT NULL
uploaded_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL

backend/src 出現 1 次 · 沒有表引用它

protocol_notice_acknowledgements7 欄 · FK 出 5 / 入 0002_schema.sql:4504
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKUKprotocols CASCADE
notice_iduuidNOT NULLFKapplication_notices
signer_iduuidNOT NULLFKusers
signature_iduuidFKelectronic_signatures
notice_attachment_iduuidFKattachments
acknowledged_attimestamptzNOT NULL

backend/src 出現 6 次 · 沒有表引用它

protocol_pi_delegates10 欄 · FK 出 4 / 入 4010_protocol_pi_delegates.sql:18
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKprotocols CASCADE
delegate_user_iduuidNOT NULLFKusers
authorized_byuuidNOT NULLFKusers
authorized_attimestamptzNOT NULL
expires_attimestamptz
reasontext
revoked_byuuidFKusers
revoked_attimestamptz
revoked_reasontext

backend/src 出現 39 次 · 被這些表引用:amendmentselectronic_signatureseuthanasia_appeals

protocol_template_versions8 欄 · FK 出 1 / 入 0002_schema.sql:4519
欄位型別NULL指向
iduuidNOT NULLPK
version_labeltextNOT NULLUK
effective_datedate
is_currentbooleanNOT NULL
notestext
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 14 次 · 沒有表引用它

protocol_versions6 欄 · FK 出 2 / 入 3002_schema.sql:4535
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKprotocols CASCADE
version_nointegerNOT NULL
content_snapshotjsonbNOT NULL
submitted_attimestamptzNOT NULL
submitted_byuuidNOT NULLFKusers

backend/src 出現 19 次 · 被這些表引用:protocol_ai_reviewsprotocol_attachmentsreview_comments

protocols25 欄 · FK 出 5 / 入 19002_schema.sql:4549
欄位型別NULL指向
iduuidNOT NULLPK
protocol_novarcharNOT NULLUK
iacuc_novarcharUK
titlevarcharNOT NULL
statusprotocol_statusNOT NULL
pi_user_iduuidNOT NULLFKusers
working_contentjsonb
start_datedate
end_datedate
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
submitted_atdate
approved_atdate
application_notext
import_pendingbooleanNOT NULL
original_version_labeltext
study_director_user_iduuidFKusers
imported_attimestamptz
source_form_versiontext
is_glpbooleanNOT NULL
close_pi_signature_idUUIDFKelectronic_signatures
close_sd_signature_idUUIDFKelectronic_signatures
pi_is_externalbooleanNOT NULL

backend/src 出現 309 次 · 被這些表引用:amendmentsanimalsdocumentseuthanasia_byproduct_samplesformulation_recordspi_account_invitesplanned_experimentsprotocol_activitiesprotocol_ai_reviewsprotocol_attachmentsprotocol_notice_acknowledgementsprotocol_pi_delegatesprotocol_versionsreview_assignmentsreview_commentsreview_round_historystudy_final_reportsuser_protocolsvet_review_assignments

review_assignments10 欄 · FK 出 3 / 入 0002_schema.sql:4889
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKprotocols CASCADE
reviewer_iduuidNOT NULLFKusers
assigned_byuuidNOT NULLFKusers
assigned_attimestamptzNOT NULL
completed_attimestamptz
is_primary_reviewerbooleanNOT NULL
review_stagevarchar
decisionvarchar
decided_attimestamptz

backend/src 出現 19 次 · 沒有表引用它

review_comments19 欄 · FK 出 7 / 入 1002_schema.sql:4907
欄位型別NULL指向
iduuidNOT NULLPK
protocol_version_iduuidFKprotocol_versions CASCADE
protocol_iduuidFKprotocols
reviewer_iduuidFKusers
contenttextNOT NULL
is_resolvedbooleanNOT NULL
resolved_byuuidFKusers
resolved_attimestamptz
review_stagevarchar
parent_comment_iduuidFKreview_comments CASCADE
replied_byuuidFKusers
draft_contenttext
drafted_byuuidFKusers
draft_updated_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
reviewer_nametext
section_novarchar
comment_typevarcharNOT NULL

backend/src 出現 41 次 · 被這些表引用:review_comments

review_round_history8 欄 · FK 出 2 / 入 0002_schema.sql:4943
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKprotocols CASCADE
review_stagevarcharNOT NULL
round_numberintegerNOT NULL
actionvarcharNOT NULL
actor_iduuidNOT NULLFKusers
remarktext
created_attimestamptzNOT NULL

backend/src 出現 1 次 · 沒有表引用它

study_final_reports18 欄 · FK 出 4 / 入 0002_schema.sql:5306
欄位型別NULL指向
iduuidNOT NULLPK
report_numbervarcharNOT NULLUK
protocol_iduuidNOT NULLFKprotocols
titlevarcharNOT NULL
statusvarcharNOT NULL
summarytext
methodstext
resultstext
conclusionstext
deviationstext
signed_byuuidFKusers
signed_attimestamptz
signature_iduuidFKelectronic_signatures
qau_statementtext
qau_signed_byuuidFKusers
qau_signed_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 12 次 · 沒有表引用它

user_protocols5 欄 · FK 出 3 / 入 0002_schema.sql:6057
欄位型別NULL指向
user_iduuidNOT NULLPKFKusers CASCADE
protocol_iduuidNOT NULLPKFKprotocols CASCADE
role_in_protocolprotocol_roleNOT NULL
granted_attimestamptzNOT NULL
granted_byuuidFKusers

backend/src 出現 54 次 · 沒有表引用它

vet_review_assignments10 欄 · FK 出 3 / 入 0002_schema.sql:6438
欄位型別NULL指向
iduuidNOT NULLPK
protocol_iduuidNOT NULLFKUKprotocols CASCADE
vet_iduuidFKusers
assigned_byuuidFKusers
assigned_attimestamptzNOT NULL
completed_attimestamptz
decisionvarchar
decision_remarktext
review_formjsonb
vet_nametext

backend/src 出現 24 次 · 沒有表引用它

動物與獸醫紀錄

36 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(4 條)。為了可讀,省略指向 users 的 53 條 FK(明細表裡有)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  animal_blood_test_items {
    uuid id PK
    uuid blood_test_id FK
    uuid template_id FK
    uuid superseded_by_id FK
    uuid corrected_by FK
  }
  animal_blood_tests {
    uuid id PK
    uuid animal_id FK
    uuid deleted_by FK
    uuid created_by FK
    uuid locked_by FK
  }
  animal_field_correction_requests {
    uuid id PK
    uuid animal_id FK
    uuid requested_by FK
    uuid reviewed_by FK
  }
  animal_import_batches {
    uuid id PK
    uuid created_by FK
  }
  animal_observations {
    uuid id PK
    uuid animal_id FK
    uuid deleted_by FK
    uuid reviewed_by FK
    uuid created_by FK
    uuid locked_by FK
  }
  animal_pathology_reports {
    uuid id PK
    uuid animal_id FK, UK
    uuid created_by FK
  }
  animal_record_attachments {
    uuid id PK
  }
  animal_sacrifices {
    uuid id PK
    uuid animal_id FK, UK
    uuid locked_by FK
    uuid created_by FK
  }
  animal_sources {
    uuid id PK
    varchar code UK
  }
  animal_sudden_deaths {
    uuid id PK
    uuid animal_id FK, UK
    uuid discovered_by FK
    varchar iacuc_no "無 FK"
  }
  animal_surgeries {
    uuid id PK
    uuid animal_id FK
    uuid deleted_by FK
    uuid created_by FK
    uuid locked_by FK
  }
  animal_transfers {
    uuid id PK
    uuid animal_id FK
    uuid initiated_by FK
    uuid rejected_by FK
  }
  animal_vaccinations {
    uuid id PK
    uuid animal_id FK
    uuid deleted_by FK
    uuid created_by FK
  }
  animal_vet_advice_records {
    uuid id PK
    uuid animal_id FK
    uuid created_by FK
    uuid updated_by FK
    uuid source_vet_patrol_entry_id FK
  }
  animal_vet_advices {
    uuid id PK
    uuid animal_id FK, UK
    uuid created_by FK
    uuid updated_by FK
  }
  animal_weights {
    uuid id PK
    uuid animal_id FK
    uuid deleted_by FK
    uuid created_by FK
  }
  animals {
    uuid id PK
    uuid source_id FK
    varchar iacuc_no "無 FK"
    uuid deleted_by FK
    uuid animal_id "無 FK"
    uuid experiment_assigned_by FK
    uuid created_by FK
    uuid pen_id FK
    uuid species_id FK
    uuid reserved_protocol_id FK
    uuid reserved_planned_experiment_id FK
  }
  blood_test_panel_items {
    uuid panel_id PK, FK
    uuid template_id PK, FK
  }
  blood_test_panels {
    uuid id PK
    varchar key UK
  }
  blood_test_presets {
    uuid id PK
  }
  blood_test_templates {
    uuid id PK
    varchar code UK
  }
  care_medication_records {
    uuid id PK
    uuid deleted_by FK
    uuid locked_by FK
  }
  euthanasia_appeals {
    uuid id PK
    uuid order_id FK
    uuid pi_user_id FK
    uuid chair_user_id FK
    uuid delegation_id FK
  }
  euthanasia_byproduct_samples {
    uuid id PK
    uuid euthanasia_id FK
    uuid animal_id FK
    uuid source_protocol_id FK
    uuid requester_user_id FK
    uuid collector_id FK
    uuid created_by FK
  }
  euthanasia_orders {
    uuid id PK
    uuid animal_id FK
    uuid vet_user_id FK
    uuid pi_user_id FK
    uuid executed_by FK
  }
  formulation_records {
    uuid id PK
    uuid product_id FK
    uuid protocol_id FK
    uuid prepared_by FK
    uuid verified_by FK
  }
  observation_vet_reads {
    uuid observation_id PK "無 FK"
    uuid vet_user_id PK, FK
  }
  species {
    uuid id PK
    varchar code UK
    uuid parent_id FK
  }
  surgery_vet_reads {
    uuid surgery_id PK "無 FK"
    uuid vet_user_id PK, FK
  }
  transfer_vet_evaluations {
    uuid id PK
    uuid transfer_id FK, UK
    uuid vet_id FK
  }
  treatment_drug_options {
    uuid id PK
    uuid erp_product_id FK
    uuid created_by FK
  }
  vet_patrol_entries {
    uuid id PK
    uuid report_id FK
    uuid animal_id FK
  }
  vet_patrol_entry_animals {
    uuid entry_id PK, FK
    uuid animal_id PK, FK
  }
  vet_patrol_entry_photos {
    uuid id PK
    uuid entry_id FK
    uuid created_by FK
  }
  vet_patrol_photos {
    uuid id PK
    uuid report_id FK
    uuid created_by FK
  }
  vet_patrol_reports {
    uuid id PK
    uuid created_by FK
    uuid updated_by FK
    uuid follow_up_user_id FK
    uuid acknowledged_by_id FK
  }
  animal_blood_tests ||--o{ animal_blood_test_items : "blood_test_id · CASCADE"
  animal_blood_test_items |o--o{ animal_blood_test_items : "superseded_by_id"
  blood_test_templates |o--o{ animal_blood_test_items : "template_id"
  animals ||--o{ animal_blood_tests : "animal_id · CASCADE"
  animals ||--o{ animal_field_correction_requests : "animal_id · CASCADE"
  animals ||--o{ animal_observations : "animal_id · CASCADE"
  animals ||--o| animal_pathology_reports : "animal_id · CASCADE"
  animals ||--o| animal_sacrifices : "animal_id · CASCADE"
  animals ||--o| animal_sudden_deaths : "animal_id"
  animals ||--o{ animal_surgeries : "animal_id · CASCADE"
  animals ||--o{ animal_transfers : "animal_id"
  animals ||--o{ animal_vaccinations : "animal_id · CASCADE"
  animals ||--o{ animal_vet_advice_records : "animal_id"
  vet_patrol_entries |o--o{ animal_vet_advice_records : "source_vet_patrol_entry_id · CASCADE"
  animals ||--o| animal_vet_advices : "animal_id"
  animals ||--o{ animal_weights : "animal_id · CASCADE"
  pens |o--o{ animals : "pen_id"
  planned_experiments |o--o{ animals : "reserved_planned_experiment_id"
  protocols |o--o{ animals : "reserved_protocol_id"
  animal_sources |o--o{ animals : "source_id"
  species |o--o{ animals : "species_id"
  blood_test_panels ||--o{ blood_test_panel_items : "panel_id · CASCADE"
  blood_test_templates ||--o{ blood_test_panel_items : "template_id · CASCADE"
  euthanasia_orders ||--o{ euthanasia_appeals : "order_id · CASCADE"
  protocol_pi_delegates |o--o{ euthanasia_appeals : "delegation_id"
  animals ||--o{ euthanasia_byproduct_samples : "animal_id"
  euthanasia_orders |o--o{ euthanasia_byproduct_samples : "euthanasia_id"
  protocols ||--o{ euthanasia_byproduct_samples : "source_protocol_id"
  animals ||--o{ euthanasia_orders : "animal_id · CASCADE"
  products ||--o{ formulation_records : "product_id"
  protocols |o--o{ formulation_records : "protocol_id"
  species |o--o{ species : "parent_id"
  animal_transfers ||--o| transfer_vet_evaluations : "transfer_id"
  products |o--o{ treatment_drug_options : "erp_product_id"
  animals |o--o{ vet_patrol_entries : "animal_id"
  vet_patrol_reports ||--o{ vet_patrol_entries : "report_id · CASCADE"
  animals ||--o{ vet_patrol_entry_animals : "animal_id · CASCADE"
  vet_patrol_entries ||--o{ vet_patrol_entry_animals : "entry_id · CASCADE"
  vet_patrol_entries ||--o{ vet_patrol_entry_photos : "entry_id · CASCADE"
  vet_patrol_reports ||--o{ vet_patrol_photos : "report_id · CASCADE"
  animal_observations |o..o{ observation_vet_reads : "observation_id(無 FK)"
  animal_surgeries |o..o{ surgery_vet_reads : "surgery_id(無 FK)"
  protocols |o..o{ animal_sudden_deaths : "iacuc_no → iacuc_no(文字)"
  protocols |o..o{ animals : "iacuc_no → iacuc_no(文字)"
animal_blood_test_items15 欄 · FK 出 4 / 入 1002_schema.sql:1723
欄位型別NULL指向
iduuidNOT NULLPK
blood_test_iduuidNOT NULLFKanimal_blood_tests CASCADE
template_iduuidFKblood_test_templates
item_namevarcharNOT NULL
result_valuevarchar
result_unitvarchar
reference_rangevarchar
is_abnormalbooleanNOT NULL
remarktext
sort_orderintegerNOT NULL
created_attimestamptzNOT NULL
superseded_by_iduuidFKanimal_blood_test_items
superseded_attimestamptz
corrected_byuuidFKusers
correction_reasontext

backend/src 出現 15 次 · 被這些表引用:animal_blood_test_items

animal_blood_tests17 欄 · FK 出 4 / 入 1002_schema.sql:1775
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKanimals CASCADE
test_datedateNOT NULL
lab_namevarchar
statusvarcharNOT NULL
remarktext
vet_readbooleanNOT NULL
vet_read_attimestamptz
deleted_attimestamptz
deleted_byuuidFKusers
delete_reasontext
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
is_lockedbooleanNOT NULL
locked_attimestamptz
locked_byuuidFKusers

backend/src 出現 21 次 · 被這些表引用:animal_blood_test_items

animal_field_correction_requests12 欄 · FK 出 3 / 入 0002_schema.sql:1815
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKanimals CASCADE
field_namevarcharNOT NULL
old_valuetext
new_valuetextNOT NULL
reasontextNOT NULL
statusvarcharNOT NULL
requested_byuuidNOT NULLFKusers
reviewed_byuuidFKusers
reviewed_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 7 次 · 沒有表引用它

animal_import_batches11 欄 · FK 出 1 / 入 0002_schema.sql:1858
欄位型別NULL指向
iduuidNOT NULLPK
import_typeimport_typeNOT NULL
file_namevarcharNOT NULL
total_rowsintegerNOT NULL
success_countintegerNOT NULL
error_countintegerNOT NULL
statusimport_statusNOT NULL
error_detailsjsonb
created_byuuidFKusers
created_attimestamptzNOT NULL
completed_attimestamptz

backend/src 出現 5 次 · 沒有表引用它

animal_observations29 欄 · FK 出 5 / 入 0002_schema.sql:1877
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKanimals CASCADE
event_datedateNOT NULL
record_typerecord_typeNOT NULL
equipment_usedjsonb
anesthesia_starttimestamptz
anesthesia_endtimestamptz
contenttextNOT NULL
no_medication_neededbooleanNOT NULL
stop_medicationbooleanNOT NULL
treatmentsjsonb
remarktext
vet_readbooleanNOT NULL
vet_read_attimestamptz
deleted_attimestamptz
deletion_reasontext
deleted_byuuidFKusers
is_emergencyboolean
emergency_statusvarchar
emergency_reasontext
reviewed_byuuidFKusers
reviewed_attimestamptz
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
is_lockedbooleanNOT NULL
locked_attimestamptz
locked_byuuidFKusers

backend/src 出現 36 次 · 沒有表引用它

animal_pathology_reports5 欄 · FK 出 2 / 入 0002_schema.sql:1921
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKUKanimals CASCADE
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 3 次 · 沒有表引用它

animal_record_attachments9 欄 · FK 出 0 / 入 0002_schema.sql:1934
欄位型別NULL指向
iduuidNOT NULLPK
record_typeanimal_record_typeNOT NULL
record_iduuidNOT NULL
file_typeanimal_file_typeNOT NULL
file_namevarcharNOT NULL
file_pathvarcharNOT NULL
file_sizeintegerNOT NULL
mime_typevarcharNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 3 次 · 沒有表引用它

animal_sacrifices17 欄 · FK 出 3 / 入 0002_schema.sql:1951
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKUKanimals CASCADE
sacrifice_datedate
zoletil_dosevarchar
method_electrocutionbooleanNOT NULL
method_bloodlettingbooleanNOT NULL
method_othertext
samplingtext
sampling_othertext
blood_volume_mlnumeric
confirmed_sacrificebooleanNOT NULL
is_lockedbooleanNOT NULL
locked_attimestamptz
locked_byuuidFKusers
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 17 次 · 沒有表引用它

animal_sources11 欄 · FK 出 0 / 入 1002_schema.sql:1976
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
addresstext
contactvarchar
phonevarchar
phone_extvarchar
is_activebooleanNOT NULL
sort_orderintegerNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 16 次 · 被這些表引用:animals

animal_sudden_deaths10 欄 · FK 出 2 / 入 0002_schema.sql:1995
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKUKanimals
discovered_attimestamptzNOT NULL
discovered_byuuidNOT NULLFKusers
probable_causetext
iacuc_novarchar無 FK
locationvarchar
remarktext
requires_pathologyboolean
created_attimestamptzNOT NULL

backend/src 出現 4 次 · 沒有表引用它

animal_surgeries28 欄 · FK 出 4 / 入 0002_schema.sql:2013
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKanimals CASCADE
is_first_experimentbooleanNOT NULL
surgery_datedateNOT NULL
surgery_sitevarcharNOT NULL
induction_anesthesiajsonb
pre_surgery_medicationjsonb
positioningvarchar
anesthesia_maintenancejsonb
anesthesia_observationtext
vital_signsjsonb
reflex_recoverytext
respiration_rateinteger
post_surgery_medicationjsonb
remarktext
no_medication_neededbooleanNOT NULL
vet_readbooleanNOT NULL
vet_read_attimestamptz
deleted_attimestamptz
deletion_reasontext
deleted_byuuidFKusers
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
is_lockedbooleanNOT NULL
locked_attimestamptz
locked_byuuidFKusers

backend/src 出現 31 次 · 沒有表引用它

animal_transfers14 欄 · FK 出 3 / 入 1002_schema.sql:2056
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKanimals
from_iacuc_novarcharNOT NULL
to_iacuc_novarchar
statusanimal_transfer_statusNOT NULL
initiated_byuuidNOT NULLFKusers
reasontextNOT NULL
remarktext
rejected_byuuidFKusers
rejected_reasontext
completed_attimestamptz
transfer_typevarcharNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 31 次 · 被這些表引用:transfer_vet_evaluations

animal_vaccinations10 欄 · FK 出 3 / 入 0002_schema.sql:2085
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKanimals CASCADE
administered_datedateNOT NULL
vaccinevarchar
deworming_dosevarchar
deleted_attimestamptz
deletion_reasontext
deleted_byuuidFKusers
created_byuuidFKusers
created_attimestamptzNOT NULL

backend/src 出現 11 次 · 沒有表引用它

animal_vet_advice_records12 欄 · FK 出 4 / 入 0002_schema.sql:2103
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKanimals
advice_datedateNOT NULL
observationtextNOT NULL
suggested_treatmenttextNOT NULL
created_byuuidFKusers
updated_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
deleted_attimestamptz
follow_uptextNOT NULL
source_vet_patrol_entry_iduuidFKvet_patrol_entries CASCADE

backend/src 出現 12 次 · 沒有表引用它

animal_vet_advices7 欄 · FK 出 3 / 入 0002_schema.sql:2123
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKUKanimals
sectionsjsonbNOT NULL
created_byuuidFKusers
updated_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 7 次 · 沒有表引用它

animal_weights9 欄 · FK 出 3 / 入 0002_schema.sql:2138
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKanimals CASCADE
measure_datedateNOT NULL
weightnumericNOT NULL
deleted_attimestamptz
deletion_reasontext
deleted_byuuidFKusers
created_byuuidFKusers
created_attimestamptzNOT NULL

backend/src 出現 23 次 · 沒有表引用它

animals38 欄 · FK 出 8 / 入 16002_schema.sql:2155
欄位型別NULL指向
iduuidNOT NULLPK
ear_tagvarcharNOT NULL
statusanimal_statusNOT NULL
breedanimal_breedNOT NULL
source_iduuidFKanimal_sources
genderanimal_genderNOT NULL
birth_datedate
entry_datedateNOT NULL
entry_weightnumeric
pen_locationvarchar
pre_experiment_codevarchar
iacuc_novarchar無 FK
experiment_datedate
remarktext
deleted_attimestamptz
deleted_byuuidFKusers
animal_novarchar
deletion_reasontext
animal_iduuid無 FK
breed_othervarchar
experiment_assigned_byuuidFKusers
lab_animal_idvarchar
glp_study_novarchar
randomization_groupvarchar
dosing_groupvarchar
quarantine_end_datedate
vet_weight_viewed_attimestamptz
vet_vaccine_viewed_attimestamptz
vet_sacrifice_viewed_attimestamptz
vet_last_viewed_attimestamptz
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
pen_iduuidFKpens
species_iduuidFKspecies
reserved_protocol_iduuidFKprotocols SET NULL
reserved_planned_experiment_iduuidFKplanned_experiments SET NULL

backend/src 出現 341 次 · 被這些表引用:animal_blood_testsanimal_field_correction_requestsanimal_observationsanimal_pathology_reportsanimal_sacrificesanimal_sudden_deathsanimal_surgeriesanimal_transfersanimal_vaccinationsanimal_vet_advice_recordsanimal_vet_advicesanimal_weightseuthanasia_byproduct_sampleseuthanasia_ordersvet_patrol_entriesvet_patrol_entry_animals

blood_test_panel_items3 欄 · FK 出 2 / 入 0002_schema.sql:2391
欄位型別NULL指向
panel_iduuidNOT NULLPKFKblood_test_panels CASCADE
template_iduuidNOT NULLPKFKblood_test_templates CASCADE
sort_orderintegerNOT NULL

backend/src 出現 13 次 · 沒有表引用它

blood_test_panels8 欄 · FK 出 0 / 入 1002_schema.sql:2402
欄位型別NULL指向
iduuidNOT NULLPK
keyvarcharNOT NULLUK
namevarcharNOT NULL
iconvarchar
sort_orderintegerNOT NULL
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 10 次 · 被這些表引用:blood_test_panel_items

blood_test_presets8 欄 · FK 出 0 / 入 0002_schema.sql:2418
欄位型別NULL指向
iduuidNOT NULLPK
namevarcharNOT NULL
iconvarchar
panel_keystext[]NOT NULL
sort_orderintegerNOT NULL
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 8 次 · 沒有表引用它

blood_test_templates10 欄 · FK 出 0 / 入 2002_schema.sql:2434
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
default_unitvarchar
reference_rangevarchar
default_pricenumeric
sort_orderintegerNOT NULL
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 15 次 · 被這些表引用:animal_blood_test_itemsblood_test_panel_items

care_medication_records24 欄 · FK 出 2 / 入 0002_schema.sql:2541
欄位型別NULL指向
iduuidNOT NULLPK
record_typevet_record_typeNOT NULL
record_iduuidNOT NULL
record_modecare_record_modeNOT NULL
post_op_daysinteger
time_periodvarchar
vet_readbooleanNOT NULL
deleted_attimestamptz
deletion_reasontext
deleted_byuuidFKusers
created_attimestamptzNOT NULL
incisionsmallint
attitude_behaviorsmallint
appetitesmallint
fecessmallint
urinesmallint
pain_scoresmallint
injection_ketorolacbooleanNOT NULL
injection_meloxicambooleanNOT NULL
oral_meloxicambooleanNOT NULL
post_medicationsjsonb
is_lockedbooleanNOT NULL
locked_attimestamptz
locked_byuuidFKusers

backend/src 出現 15 次 · 沒有表引用它

euthanasia_appeals12 欄 · FK 出 4 / 入 0002_schema.sql:3236
欄位型別NULL指向
iduuidNOT NULLPK
order_iduuidNOT NULLFKeuthanasia_orders CASCADE
pi_user_iduuidNOT NULLFKusers
reasontextNOT NULL
attachment_pathvarchar
chair_user_iduuidFKusers
chair_decisionvarchar
chair_decided_attimestamptz
chair_deadline_attimestamptz
created_attimestamptzNOT NULL
versionintegerNOT NULL
delegation_iduuidFKprotocol_pi_delegates

backend/src 出現 9 次 · 沒有表引用它

euthanasia_byproduct_samples18 欄 · FK 出 6 / 入 0002_schema.sql:3262
欄位型別NULL指向
iduuidNOT NULLPK
euthanasia_iduuidFKeuthanasia_orders RESTRICT
animal_iduuidNOT NULLFKanimals RESTRICT
source_protocol_iduuidNOT NULLFKprotocols RESTRICT
sampled_attimestamptzNOT NULL
sample_contenttextNOT NULL
requester_user_iduuidFKusers RESTRICT
collector_iduuidNOT NULLFKusers RESTRICT
notestext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
created_byuuidNOT NULLFKusers RESTRICT
deleted_attimestamptz
requester_org_nametext
requester_contact_nametext
special_equipment_usedtext
work_started_attimestamptz
work_ended_attimestamptz

backend/src 出現 11 次 · 沒有表引用它

euthanasia_orders13 欄 · FK 出 4 / 入 2002_schema.sql:3346
欄位型別NULL指向
iduuidNOT NULLPK
animal_iduuidNOT NULLFKanimals CASCADE
vet_user_iduuidNOT NULLFKusers
pi_user_iduuidNOT NULLFKusers
statuseuthanasia_order_statusNOT NULL
reasontextNOT NULL
deadline_attimestamptzNOT NULL
pi_responded_attimestamptz
executed_attimestamptz
executed_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

backend/src 出現 29 次 · 被這些表引用:euthanasia_appealseuthanasia_byproduct_samples

formulation_records13 欄 · FK 出 4 / 入 0002_schema.sql:3555
欄位型別NULL指向
iduuidNOT NULLPK
product_iduuidNOT NULLFKproducts
protocol_iduuidFKprotocols
formulation_datedateNOT NULL
batch_numbervarchar
concentrationvarchar
volumevarchar
prepared_byuuidNOT NULLFKusers
verified_byuuidFKusers
verified_attimestamptz
expiry_datedate
notestext
created_attimestamptzNOT NULL

backend/src 出現 3 次 · 沒有表引用它

observation_vet_reads3 欄 · FK 出 1 / 入 0002_schema.sql:4070
欄位型別NULL指向
observation_iduuidNOT NULLPK無 FK
vet_user_iduuidNOT NULLPKFKusers
read_attimestamptzNOT NULL

backend/src 出現 2 次 · 沒有表引用它

species11 欄 · FK 出 1 / 入 2002_schema.sql:5223
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
name_envarchar
iconvarchar
is_activebooleanNOT NULL
configjsonb
sort_orderintegerNOT NULL
parent_iduuidFKspecies
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 102 次 · 被這些表引用:animalsspecies

surgery_vet_reads3 欄 · FK 出 1 / 入 0002_schema.sql:5332
欄位型別NULL指向
surgery_iduuidNOT NULLPK無 FK
vet_user_iduuidNOT NULLPKFKusers
read_attimestamptzNOT NULL

backend/src 出現 2 次 · 沒有表引用它

transfer_vet_evaluations7 欄 · FK 出 2 / 入 0002_schema.sql:5372
欄位型別NULL指向
iduuidNOT NULLPK
transfer_iduuidNOT NULLFKUKanimal_transfers
vet_iduuidNOT NULLFKusers
health_statustextNOT NULL
is_fit_for_transferbooleanNOT NULL
conditionstext
evaluated_attimestamptzNOT NULL

backend/src 出現 3 次 · 沒有表引用它

treatment_drug_options13 欄 · FK 出 2 / 入 0002_schema.sql:5387
欄位型別NULL指向
iduuidNOT NULLPK
namevarcharNOT NULL
display_namevarchar
default_dosage_unitvarchar
available_unitstext[]
default_dosage_valuevarchar
erp_product_iduuidFKproducts
categoryvarchar
sort_orderintegerNOT NULL
is_activebooleanNOT NULL
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 17 次 · 沒有表引用它

vet_patrol_entries9 欄 · FK 出 2 / 入 3002_schema.sql:6350
欄位型別NULL指向
iduuidNOT NULLPK
report_iduuidNOT NULLFKvet_patrol_reports CASCADE
categoryvarcharNOT NULL
animal_iduuidFKanimals
observationtextNOT NULL
suggestiontextNOT NULL
follow_uptextNOT NULL
sort_orderintegerNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 26 次 · 被這些表引用:animal_vet_advice_recordsvet_patrol_entry_animalsvet_patrol_entry_photos

vet_patrol_entry_animals2 欄 · FK 出 2 / 入 0002_schema.sql:6367
欄位型別NULL指向
entry_iduuidNOT NULLPKFKvet_patrol_entries CASCADE
animal_iduuidNOT NULLPKFKanimals CASCADE

backend/src 出現 6 次 · 沒有表引用它

vet_patrol_entry_photos10 欄 · FK 出 2 / 入 0002_schema.sql:6377
欄位型別NULL指向
iduuidNOT NULLPK
entry_iduuidNOT NULLFKvet_patrol_entries CASCADE
file_namevarcharNOT NULL
file_pathtextNOT NULL
file_sizebigintNOT NULL
mime_typevarcharNOT NULL
captiontextNOT NULL
sort_orderintegerNOT NULL
created_byuuidFKusers
created_attimestamptzNOT NULL

backend/src 出現 15 次 · 沒有表引用它

vet_patrol_photos10 欄 · FK 出 2 / 入 0002_schema.sql:6395
欄位型別NULL指向
iduuidNOT NULLPK
report_iduuidNOT NULLFKvet_patrol_reports CASCADE
file_namevarcharNOT NULL
file_pathtextNOT NULL
file_sizebigintNOT NULL
mime_typevarcharNOT NULL
captiontextNOT NULL
sort_orderintegerNOT NULL
created_byuuidFKusers
created_attimestamptzNOT NULL

backend/src 出現 11 次 · 沒有表引用它

vet_patrol_reports16 欄 · FK 出 4 / 入 2002_schema.sql:6413
欄位型別NULL指向
iduuidNOT NULLPK
patrol_datedateNOT NULL
week_startdate
week_enddate
statusvarcharNOT NULL
created_byuuidFKusers
updated_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
deleted_attimestamptz
accompanying_personneltext
submitted_attimestamptz
follow_up_user_iduuidFKusers
follow_up_submitted_attimestamptz
acknowledged_attimestamptz
acknowledged_by_iduuidFKusers

backend/src 出現 69 次 · 被這些表引用:vet_patrol_entriesvet_patrol_photos

設施與環境

6 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(0 條)。為了可讀,省略指向 users 的 1 條 FK(明細表裡有)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  buildings {
    uuid id PK
    uuid facility_id FK
  }
  environment_monitoring_points {
    uuid id PK
    uuid building_id FK
    uuid zone_id FK
  }
  environment_readings {
    uuid id PK
    uuid monitoring_point_id FK
    uuid recorded_by FK
  }
  facilities {
    uuid id PK
  }
  pens {
    uuid id PK
    uuid zone_id FK
  }
  zones {
    uuid id PK
    uuid building_id FK
  }
  facilities ||--o{ buildings : "facility_id"
  buildings |o--o{ environment_monitoring_points : "building_id"
  zones |o--o{ environment_monitoring_points : "zone_id"
  environment_monitoring_points ||--o{ environment_readings : "monitoring_point_id · CASCADE"
  zones ||--o{ pens : "zone_id"
  buildings ||--o{ zones : "building_id"
buildings10 欄 · FK 出 1 / 入 2002_schema.sql:2452
欄位型別NULL指向
iduuidNOT NULLPK
facility_iduuidNOT NULLFKfacilities
codevarcharNOT NULL
namevarcharNOT NULL
descriptiontext
is_activebooleanNOT NULL
configjsonb
sort_orderintegerNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 32 次 · 被這些表引用:environment_monitoring_pointszones

environment_monitoring_points10 欄 · FK 出 2 / 入 1002_schema.sql:3009
欄位型別NULL指向
iduuidNOT NULLPK
namevarcharNOT NULL
location_typevarcharNOT NULL
building_iduuidFKbuildings
zone_iduuidFKzones
parametersjsonbNOT NULL
monitoring_intervalvarchar
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 8 次 · 被這些表引用:environment_readings

environment_readings10 欄 · FK 出 2 / 入 0002_schema.sql:3027
欄位型別NULL指向
iduuidNOT NULLPK
monitoring_point_iduuidNOT NULLFKenvironment_monitoring_points CASCADE
reading_timetimestamptzNOT NULL
readingsjsonbNOT NULL
is_out_of_rangebooleanNOT NULL
out_of_range_paramsjsonb
recorded_byuuidFKusers
sourcevarcharNOT NULL
notestext
created_attimestamptzNOT NULL

backend/src 出現 3 次 · 沒有表引用它

facilities10 欄 · FK 出 0 / 入 1002_schema.sql:3537
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULL
namevarcharNOT NULL
addresstext
phonevarchar
contact_personvarchar
is_activebooleanNOT NULL
configjsonb
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 82 次 · 被這些表引用:buildings

pens12 欄 · FK 出 1 / 入 1002_schema.sql:4286
欄位型別NULL指向
iduuidNOT NULLPK
zone_iduuidNOT NULLFKzones
codevarcharNOT NULL
namevarchar
capacityintegerNOT NULL
current_countintegerNOT NULL
statusvarcharNOT NULL
row_indexinteger
col_indexinteger
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 56 次 · 被這些表引用:animals

zones10 欄 · FK 出 1 / 入 2002_schema.sql:6457
欄位型別NULL指向
iduuidNOT NULLPK
building_iduuidNOT NULLFKbuildings
codevarcharNOT NULL
namevarchar
colorvarchar
is_activebooleanNOT NULL
layout_configjsonb
sort_orderintegerNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 29 次 · 被這些表引用:environment_monitoring_pointspens

ERP・庫存

20 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(1 條)。為了可讀,省略指向 users 的 6 條 FK(明細表裡有)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  document_lines {
    uuid id PK
    uuid document_id FK
    uuid product_id FK
    uuid storage_location_id FK
    uuid storage_location_from_id FK
    uuid storage_location_to_id FK
    uuid warehouse_id FK
  }
  documents {
    uuid id PK
    varchar doc_no UK
    uuid warehouse_id FK
    uuid warehouse_from_id FK
    uuid warehouse_to_id FK
    uuid partner_id FK
    uuid source_doc_id FK
    varchar iacuc_no "無 FK"
    uuid manager_approved_by FK
    uuid created_by FK
    uuid approved_by FK
    uuid protocol_id FK
    uuid reverses_doc_id FK
  }
  expiry_monthly_snapshots {
    uuid id PK
    uuid product_id FK
    uuid warehouse_id FK
  }
  expiry_notification_config {
    uuid id PK
    uuid updated_by FK
  }
  inventory_snapshots {
    uuid warehouse_id PK, FK
    uuid product_id PK, FK
  }
  line_shelf_allocations {
    uuid id PK
    uuid document_line_id FK
    uuid storage_location_id FK
    uuid product_id FK
    uuid created_by FK
  }
  mig011_conversion_backup {
    uuid id PK
  }
  mig011_inserted_conversion {
    uuid id PK
  }
  mig011_pack_unit_backup {
    uuid product_id PK
  }
  partners {
    uuid id PK
    varchar code UK
  }
  product_categories {
    uuid id PK
    varchar code UK
    uuid parent_id FK
  }
  product_uom_conversions {
    uuid id PK
    uuid product_id FK
    varchar base_uom FK
  }
  products {
    uuid id PK
    varchar sku UK
    uuid category_id FK
    uuid created_by FK
  }
  sku_categories {
    char code PK
  }
  sku_sequences {
    char category_code PK
    char subcategory_code PK
  }
  sku_subcategories {
    integer id PK
    char category_code FK
  }
  stock_ledger {
    uuid id PK
    uuid warehouse_id FK
    uuid product_id FK
    uuid doc_id FK
    uuid line_id FK
    uuid storage_location_id FK
  }
  storage_location_inventory {
    uuid id PK
    uuid storage_location_id FK
    uuid product_id FK
  }
  storage_locations {
    uuid id PK
    uuid warehouse_id FK
  }
  warehouses {
    uuid id PK
    varchar code UK
  }
  documents ||--o{ document_lines : "document_id · CASCADE"
  products ||--o{ document_lines : "product_id"
  storage_locations |o--o{ document_lines : "storage_location_from_id"
  storage_locations |o--o{ document_lines : "storage_location_id"
  storage_locations |o--o{ document_lines : "storage_location_to_id"
  warehouses |o--o{ document_lines : "warehouse_id"
  partners |o--o{ documents : "partner_id"
  protocols |o--o{ documents : "protocol_id"
  documents |o--o{ documents : "reverses_doc_id"
  documents |o--o{ documents : "source_doc_id"
  warehouses |o--o{ documents : "warehouse_from_id"
  warehouses |o--o{ documents : "warehouse_id"
  warehouses |o--o{ documents : "warehouse_to_id"
  products ||--o{ expiry_monthly_snapshots : "product_id"
  warehouses ||--o{ expiry_monthly_snapshots : "warehouse_id"
  products ||--o{ inventory_snapshots : "product_id"
  warehouses ||--o{ inventory_snapshots : "warehouse_id"
  document_lines |o--o{ line_shelf_allocations : "document_line_id"
  products ||--o{ line_shelf_allocations : "product_id"
  storage_locations ||--o{ line_shelf_allocations : "storage_location_id"
  product_categories |o--o{ product_categories : "parent_id"
  products ||--o{ product_uom_conversions : "product_id · CASCADE"
  products ||--o{ product_uom_conversions : "product_id, base_uom · CASCADE"
  product_categories |o--o{ products : "category_id"
  sku_categories ||--o{ sku_subcategories : "category_code · CASCADE"
  documents ||--o{ stock_ledger : "doc_id"
  document_lines |o--o{ stock_ledger : "line_id"
  products ||--o{ stock_ledger : "product_id"
  storage_locations |o--o{ stock_ledger : "storage_location_id"
  warehouses ||--o{ stock_ledger : "warehouse_id"
  products ||--o{ storage_location_inventory : "product_id · CASCADE"
  storage_locations ||--o{ storage_location_inventory : "storage_location_id · CASCADE"
  warehouses ||--o{ storage_locations : "warehouse_id · CASCADE"
  protocols |o..o{ documents : "iacuc_no → iacuc_no(文字)"
document_lines14 欄 · FK 出 6 / 入 2002_schema.sql:2868
欄位型別NULL指向
iduuidNOT NULLPK
document_iduuidNOT NULLFKdocuments CASCADE
line_nointegerNOT NULL
product_iduuidNOT NULLFKproducts
qtynumericNOT NULL
uomvarcharNOT NULL
unit_pricenumeric
batch_novarchar
expiry_datedate
remarktext
storage_location_iduuidFKstorage_locations
storage_location_from_iduuidFKstorage_locations
storage_location_to_iduuidFKstorage_locations
warehouse_iduuidFKwarehouses

backend/src 出現 46 次 · 被這些表引用:line_shelf_allocationsstock_ledger

documents28 欄 · FK 出 10 / 入 4002_schema.sql:2915
欄位型別NULL指向
iduuidNOT NULLPK
doc_typedoc_typeNOT NULL
doc_novarcharNOT NULLUK
statusdoc_statusNOT NULL
warehouse_iduuidFKwarehouses
warehouse_from_iduuidFKwarehouses
warehouse_to_iduuidFKwarehouses
partner_iduuidFKpartners
source_doc_iduuidFKdocuments
doc_datedateNOT NULL
receipt_statusvarchar
stocktake_scopejsonb
remarktext
iacuc_novarchar無 FK
requires_manager_approvalboolean
scrap_total_amountnumeric
manager_approval_statusvarchar
manager_approved_byuuidFKusers
manager_approved_attimestamptz
manager_reject_reasontext
created_byuuidNOT NULLFKusers
approved_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
approved_attimestamptz
protocol_iduuidFKprotocols SET NULL
reverses_doc_iduuidFKdocuments
system_generatedbooleanNOT NULL

backend/src 出現 129 次 · 被這些表引用:document_linesdocumentsstock_ledger

expiry_monthly_snapshots12 欄 · FK 出 2 / 入 0002_schema.sql:3432
欄位型別NULL指向
iduuidNOT NULLPK
snapshot_ymcharNOT NULL
product_iduuidNOT NULLFKproducts
skuvarcharNOT NULL
product_namevarcharNOT NULL
warehouse_iduuidNOT NULLFKwarehouses
batch_novarchar
expiry_datedateNOT NULL
days_pastsmallintNOT NULL
on_hand_qtynumericNOT NULL
base_uomvarcharNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 3 次 · 沒有表引用它

expiry_notification_config6 欄 · FK 出 1 / 入 0002_schema.sql:3473
欄位型別NULL指向
iduuidNOT NULLPK
warn_dayssmallintNOT NULL
cutoff_dayssmallintNOT NULL
monthly_threshold_dayssmallint
updated_attimestamptzNOT NULL
updated_byuuidFKusers

backend/src 出現 3 次 · 沒有表引用它

inventory_snapshots5 欄 · FK 出 2 / 入 0002_schema.sql:3631
欄位型別NULL指向
warehouse_iduuidNOT NULLPKFKwarehouses
product_iduuidNOT NULLPKFKproducts
on_hand_qty_basenumericNOT NULL
avg_costnumeric
updated_attimestamptzNOT NULL

backend/src 出現 7 次 · 沒有表引用它

line_shelf_allocations9 欄 · FK 出 4 / 入 0002_schema.sql:3833
欄位型別NULL指向
iduuidNOT NULLPK
document_line_iduuidFKdocument_lines SET NULL
storage_location_iduuidNOT NULLFKstorage_locations
product_iduuidNOT NULLFKproducts
batch_novarchar
expiry_datedate
qtynumericNOT NULL
created_byuuidFKusers
created_attimestamptzNOT NULL

backend/src 出現 6 次 · 沒有表引用它

mig011_conversion_backup4 欄 · FK 出 0 / 入 0011_uom_conversions_from_pack.sql:93
欄位型別NULL指向
iduuidNOT NULLPK
product_iduuidNOT NULL
uomvarcharNOT NULL
factor_to_basenumericNOT NULL

backend/src 出現 1 次 · 沒有表引用它

mig011_inserted_conversion1 欄 · FK 出 0 / 入 0011_uom_conversions_from_pack.sql:105
欄位型別NULL指向
iduuidNOT NULLPK

backend/src 出現 1 次 · 沒有表引用它

mig011_pack_unit_backup2 欄 · FK 出 0 / 入 0011_uom_conversions_from_pack.sql:100
欄位型別NULL指向
product_iduuidNOT NULLPK
pack_unitvarcharNOT NULL

backend/src 出現 1 次 · 沒有表引用它

partners15 欄 · FK 出 0 / 入 6002_schema.sql:4187
欄位型別NULL指向
iduuidNOT NULLPK
partner_typepartner_typeNOT NULL
codevarcharNOT NULLUK
namevarcharNOT NULL
supplier_categorysupplier_category
customer_categorycustomer_category
tax_idvarchar
phonevarchar
phone_extvarchar
emailvarchar
addresstext
payment_termsvarchar
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 60 次 · 被這些表引用:ap_paymentsar_receiptsdocumentsequipment_calibrationsequipment_maintenance_recordsequipment_suppliers

product_categories6 欄 · FK 出 1 / 入 2002_schema.sql:4356
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
parent_iduuidFKproduct_categories
is_activebooleanNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 8 次 · 被這些表引用:product_categoriesproducts

product_uom_conversions5 欄 · FK 出 2 / 入 0002_schema.sql:4370
欄位型別NULL指向
iduuidNOT NULLPK
product_iduuidNOT NULLFKproducts CASCADE
uomvarcharNOT NULL
factor_to_basenumericNOT NULL
base_uomvarcharNOT NULLFKproducts CASCADE

backend/src 出現 31 次 · 沒有表引用它

products36 欄 · FK 出 2 / 入 10002_schema.sql:4382
欄位型別NULL指向
iduuidNOT NULLPK
skuvarcharNOT NULLUK
namevarcharNOT NULL
spectext
category_iduuidFKproduct_categories
category_codechar
subcategory_codechar
base_uomvarcharNOT NULL
pack_unitvarchar
pack_qtyinteger
track_batchbooleanNOT NULL
track_expirybooleanNOT NULL
default_expiry_daysinteger
safety_stocknumeric
safety_stock_uomvarchar
reorder_pointnumeric
reorder_point_uomvarchar
image_urlvarchar
license_novarchar
storage_conditionvarchar
barcodevarchar
tagstext[]
statusvarcharNOT NULL
remarktext
is_activebooleanNOT NULL
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
glp_characterizationtext
stability_datajsonb
storage_conditionsvarchar
cas_numbervarchar
is_test_articlebooleanNOT NULL
is_control_articlebooleanNOT NULL
cost_pricenumeric
selling_pricenumeric

backend/src 出現 115 次 · 被這些表引用:document_linesexpiry_monthly_snapshotsformulation_recordsinventory_snapshotsline_shelf_allocationsproduct_uom_conversionsstock_ledgerstorage_location_inventorytreatment_drug_options

sku_categories5 欄 · FK 出 0 / 入 1002_schema.sql:5147
欄位型別NULL指向
codecharNOT NULLPK
namevarcharNOT NULL
sort_orderintegerNOT NULL
is_activebooleanNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 14 次 · 被這些表引用:sku_subcategories

sku_sequences3 欄 · FK 出 0 / 入 0002_schema.sql:5160
欄位型別NULL指向
category_codecharNOT NULLPK
subcategory_codecharNOT NULLPK
last_sequenceintegerNOT NULL

backend/src 出現 5 次 · 沒有表引用它

sku_subcategories7 欄 · FK 出 1 / 入 0002_schema.sql:5171
欄位型別NULL指向
idintegerNOT NULLPK
category_codecharNOT NULLFKsku_categories CASCADE
codecharNOT NULL
namevarcharNOT NULL
sort_orderintegerNOT NULL
is_activebooleanNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 14 次 · 沒有表引用它

stock_ledger15 欄 · FK 出 5 / 入 0002_schema.sql:5242
欄位型別NULL指向
iduuidNOT NULLPK
warehouse_iduuidNOT NULLFKwarehouses
product_iduuidNOT NULLFKproducts
trx_datetimestamptzNOT NULL
doc_typedoc_typeNOT NULL
doc_iduuidNOT NULLFKdocuments
doc_novarcharNOT NULL
line_iduuidFKdocument_lines
directionstock_directionNOT NULL
qty_basenumericNOT NULL
unit_costnumeric
batch_novarchar
expiry_datedate
created_attimestamptzNOT NULL
storage_location_iduuidFKstorage_locations

backend/src 出現 55 次 · 沒有表引用它

storage_location_inventory7 欄 · FK 出 2 / 入 0002_schema.sql:5265
欄位型別NULL指向
iduuidNOT NULLPK
storage_location_iduuidNOT NULLFKstorage_locations CASCADE
product_iduuidNOT NULLFKproducts CASCADE
on_hand_qtynumericNOT NULL
batch_novarchar
expiry_datedate
updated_attimestamptzNOT NULL

backend/src 出現 58 次 · 沒有表引用它

storage_locations17 欄 · FK 出 1 / 入 6002_schema.sql:5281
欄位型別NULL指向
iduuidNOT NULLPK
warehouse_iduuidNOT NULLFKwarehouses CASCADE
codevarcharNOT NULL
namevarchar
location_typevarcharNOT NULL
row_indexintegerNOT NULL
col_indexintegerNOT NULL
widthintegerNOT NULL
heightintegerNOT NULL
capacityinteger
current_countinteger
colorvarchar
zonevarchar
is_activebooleanNOT NULL
configjsonb
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 42 次 · 被這些表引用:document_linesline_shelf_allocationsstock_ledgerstorage_location_inventory

warehouses10 欄 · FK 出 0 / 入 8002_schema.sql:6188
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
addresstext
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
exclude_from_alertsbooleanNOT NULL
skip_routine_stocktakebooleanNOT NULL
is_default_issue_sourcebooleanNOT NULL

backend/src 出現 67 次 · 被這些表引用:document_linesdocumentsexpiry_monthly_snapshotsinventory_snapshotsstock_ledgerstorage_locations

會計

5 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(0 條)。為了可讀,省略指向 users 的 3 條 FK(明細表裡有)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  ap_payments {
    uuid id PK
    varchar payment_no UK
    uuid partner_id FK
    uuid journal_entry_id FK
    uuid created_by FK
  }
  ar_receipts {
    uuid id PK
    varchar receipt_no UK
    uuid partner_id FK
    uuid journal_entry_id FK
    uuid created_by FK
  }
  chart_of_accounts {
    uuid id PK
    varchar code UK
    uuid parent_id FK
  }
  journal_entries {
    uuid id PK
    varchar entry_no UK
    uuid created_by FK
  }
  journal_entry_lines {
    uuid id PK
    uuid journal_entry_id FK
    uuid account_id FK
  }
  journal_entries |o--o{ ap_payments : "journal_entry_id"
  partners ||--o{ ap_payments : "partner_id"
  journal_entries |o--o{ ar_receipts : "journal_entry_id"
  partners ||--o{ ar_receipts : "partner_id"
  chart_of_accounts |o--o{ chart_of_accounts : "parent_id"
  chart_of_accounts ||--o{ journal_entry_lines : "account_id"
  journal_entries ||--o{ journal_entry_lines : "journal_entry_id · CASCADE"
ap_payments9 欄 · FK 出 3 / 入 0002_schema.sql:2239
欄位型別NULL指向
iduuidNOT NULLPK
payment_novarcharNOT NULLUK
partner_iduuidNOT NULLFKpartners
payment_datedateNOT NULL
amountnumericNOT NULL
referencetext
journal_entry_iduuidFKjournal_entries
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL

backend/src 出現 3 次 · 沒有表引用它

ar_receipts9 欄 · FK 出 3 / 入 0002_schema.sql:2285
欄位型別NULL指向
iduuidNOT NULLPK
receipt_novarcharNOT NULLUK
partner_iduuidNOT NULLFKpartners
receipt_datedateNOT NULL
amountnumericNOT NULL
referencetext
journal_entry_iduuidFKjournal_entries
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL

backend/src 出現 3 次 · 沒有表引用它

chart_of_accounts8 欄 · FK 出 1 / 入 2002_schema.sql:2708
欄位型別NULL指向
iduuidNOT NULLPK
codevarcharNOT NULLUK
namevarcharNOT NULL
account_typeaccount_typeNOT NULL
parent_iduuidFKchart_of_accounts
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 12 次 · 被這些表引用:chart_of_accountsjournal_entry_lines

journal_entries8 欄 · FK 出 1 / 入 3002_schema.sql:3709
欄位型別NULL指向
iduuidNOT NULLPK
entry_novarcharNOT NULLUK
entry_datedateNOT NULL
descriptiontext
source_entity_typevarchar
source_entity_iduuid
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL

backend/src 出現 12 次 · 被這些表引用:ap_paymentsar_receiptsjournal_entry_lines

journal_entry_lines7 欄 · FK 出 2 / 入 0002_schema.sql:3725
欄位型別NULL指向
iduuidNOT NULLPK
journal_entry_iduuidNOT NULLFKjournal_entries CASCADE
line_nointegerNOT NULL
account_iduuidNOT NULLFKchart_of_accounts
debit_amountnumericNOT NULL
credit_amountnumericNOT NULL
descriptiontext

backend/src 出現 14 次 · 沒有表引用它

人事・出勤・行事曆

15 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(1 條)。為了可讀,省略指向 users 的 19 條 FK(明細表裡有)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  annual_leave_entitlements {
    uuid id PK
    uuid user_id FK
    uuid created_by FK
  }
  attendance_records {
    uuid id PK
    uuid user_id FK
    uuid corrected_by FK
  }
  calendar_event_sync {
    uuid id PK
    uuid leave_request_id FK
  }
  calendar_sync_conflicts {
    uuid id PK
    uuid calendar_event_sync_id FK
    uuid leave_request_id FK
    uuid resolved_by FK
    uuid new_approval_request_id FK
  }
  calendar_sync_history {
    uuid id PK
    uuid triggered_by FK
  }
  comp_time_balances {
    uuid id PK
    uuid user_id FK
    uuid overtime_record_id FK, UK
  }
  competency_assessments {
    uuid id PK
    uuid user_id FK
    uuid assessor_id FK
  }
  google_calendar_config {
    uuid id PK
  }
  leave_approvals {
    uuid id PK
    uuid leave_request_id FK
    uuid approver_id FK
  }
  leave_balance_usage {
    uuid id PK
    uuid leave_request_id FK
    uuid annual_leave_entitlement_id FK
    uuid comp_time_balance_id FK
  }
  leave_requests {
    uuid id PK
    uuid user_id FK
    uuid proxy_user_id FK
    uuid annual_leave_source_id FK
    uuid current_approver_id FK
  }
  overtime_approvals {
    uuid id PK
    uuid overtime_record_id FK
    uuid approver_id FK
  }
  overtime_records {
    uuid id PK
    uuid user_id FK
    uuid attendance_id FK
    uuid approved_by FK
    uuid rejected_by FK
    uuid voided_by FK
  }
  role_training_requirements {
    uuid id PK
    varchar role_code "無 FK"
  }
  training_records {
    uuid id PK
    uuid user_id FK
  }
  leave_requests ||--o{ calendar_event_sync : "leave_request_id · CASCADE"
  calendar_event_sync |o--o{ calendar_sync_conflicts : "calendar_event_sync_id"
  leave_requests |o--o{ calendar_sync_conflicts : "leave_request_id"
  leave_requests |o--o{ calendar_sync_conflicts : "new_approval_request_id"
  overtime_records ||--o| comp_time_balances : "overtime_record_id · CASCADE"
  leave_requests ||--o{ leave_approvals : "leave_request_id · CASCADE"
  annual_leave_entitlements |o--o{ leave_balance_usage : "annual_leave_entitlement_id"
  comp_time_balances |o--o{ leave_balance_usage : "comp_time_balance_id"
  leave_requests ||--o{ leave_balance_usage : "leave_request_id"
  annual_leave_entitlements |o--o{ leave_requests : "annual_leave_source_id"
  overtime_records ||--o{ overtime_approvals : "overtime_record_id · CASCADE"
  attendance_records |o--o{ overtime_records : "attendance_id"
  roles |o..o{ role_training_requirements : "role_code → code(文字)"
annual_leave_entitlements16 欄 · FK 出 2 / 入 2002_schema.sql:2202
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
entitlement_yearintegerNOT NULL
entitled_daysnumericNOT NULL
used_daysnumeric
expires_atdateNOT NULL
calculation_basisvarchar
seniority_yearsnumeric
is_expiredboolean
expired_daysnumeric
expiry_processed_attimestamptz
notestext
adjustment_daysnumeric
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 21 次 · 被這些表引用:leave_balance_usageleave_requests

attendance_records25 欄 · FK 出 2 / 入 1002_schema.sql:2320
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
work_datedateNOT NULL
clock_in_timetimestamptz
clock_out_timetimestamptz
regular_hoursnumeric
overtime_hoursnumeric
statusvarchar
clock_in_sourcevarchar
clock_in_ipinet
clock_out_sourcevarchar
clock_out_ipinet
clock_in_latitudefloat8
clock_in_longitudefloat8
clock_out_latitudefloat8
clock_out_longitudefloat8
remarktext
is_correctedboolean
corrected_byuuidFKusers
corrected_attimestamptz
correction_reasontext
original_clock_intimestamptz
original_clock_outtimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 19 次 · 被這些表引用:overtime_records

calendar_event_sync15 欄 · FK 出 1 / 入 1002_schema.sql:2470
欄位型別NULL指向
iduuidNOT NULLPK
leave_request_iduuidNOT NULLFKleave_requests CASCADE
google_event_idvarchar
google_event_etagvarchar
google_event_linktext
sync_versionintegerNOT NULL
local_updated_attimestamptzNOT NULL
google_updated_attimestamptz
last_synced_datajsonb
sync_statusvarcharNOT NULL
last_errortext
error_countintegerNOT NULL
last_error_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 12 次 · 被這些表引用:calendar_sync_conflicts

calendar_sync_conflicts15 欄 · FK 出 4 / 入 0002_schema.sql:2493
欄位型別NULL指向
iduuidNOT NULLPK
calendar_event_sync_iduuidFKcalendar_event_sync SET NULL
leave_request_iduuidFKleave_requests SET NULL
conflict_typevarcharNOT NULL
ipig_datajsonbNOT NULL
google_datajsonb
difference_summarytext
statusvarcharNOT NULL
resolved_byuuidFKusers
resolved_attimestamptz
resolution_notestext
requires_new_approvalbooleanNOT NULL
new_approval_request_iduuidFKleave_requests
detected_attimestamptzNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 6 次 · 沒有表引用它

calendar_sync_history17 欄 · FK 出 1 / 入 0002_schema.sql:2516
欄位型別NULL指向
iduuidNOT NULLPK
job_typevarcharNOT NULL
triggered_byuuidFKusers
started_attimestamptzNOT NULL
completed_attimestamptz
duration_msinteger
statusvarcharNOT NULL
events_createdintegerNOT NULL
events_updatedintegerNOT NULL
events_deletedintegerNOT NULL
events_checkedintegerNOT NULL
conflicts_detectedintegerNOT NULL
errors_countintegerNOT NULL
error_messagesjsonb
progress_percentageintegerNOT NULL
current_operationvarchar
created_attimestamptzNOT NULL

backend/src 出現 5 次 · 沒有表引用它

comp_time_balances13 欄 · FK 出 2 / 入 1002_schema.sql:2724
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
overtime_record_iduuidNOT NULLFKUKovertime_records CASCADE
original_hoursnumericNOT NULL
used_hoursnumeric
earned_datedateNOT NULL
expires_atdateNOT NULL
is_expiredboolean
expired_hoursnumeric
converted_to_payboolean
expiry_processed_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 12 次 · 被這些表引用:leave_balance_usage

competency_assessments13 欄 · FK 出 2 / 入 0002_schema.sql:2745
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers
assessment_typevarcharNOT NULL
skill_areavarcharNOT NULL
assessment_datedateNOT NULL
assessor_iduuidNOT NULLFKusers
resultvarcharNOT NULL
scorenumeric
methodvarchar
valid_untildate
notestext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 6 次 · 沒有表引用它

google_calendar_config25 欄 · FK 出 0 / 入 0002_schema.sql:3576
欄位型別NULL指向
iduuidNOT NULLPK
calendar_idvarcharNOT NULL
calendar_namevarchar
calendar_descriptiontext
auth_methodvarcharNOT NULL
auth_emailvarchar
is_configuredbooleanNOT NULL
sync_enabledbooleanNOT NULL
sync_schedule_morningtime_without_time_zone
sync_schedule_eveningtime_without_time_zone
sync_timezonevarchar
sync_approved_leavesbooleanNOT NULL
sync_overtimebooleanNOT NULL
event_title_templatevarchar
event_color_idvarchar
last_sync_attimestamptz
last_sync_statusvarchar
last_sync_errortext
last_sync_events_pushedinteger
last_sync_events_pulledinteger
last_sync_conflictsinteger
last_sync_duration_msinteger
next_sync_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 6 次 · 沒有表引用它

leave_approvals7 欄 · FK 出 2 / 入 0002_schema.sql:3764
欄位型別NULL指向
iduuidNOT NULLPK
leave_request_iduuidNOT NULLFKleave_requests CASCADE
approver_iduuidNOT NULLFKusers
approval_levelvarcharNOT NULL
actionvarcharNOT NULL
commentstext
created_attimestamptzNOT NULL

backend/src 出現 10 次 · 沒有表引用它

leave_balance_usage9 欄 · FK 出 3 / 入 0002_schema.sql:3780
欄位型別NULL指向
iduuidNOT NULLPK
leave_request_iduuidNOT NULLFKleave_requests
source_typevarcharNOT NULL
annual_leave_entitlement_iduuidFKannual_leave_entitlements
comp_time_balance_iduuidFKcomp_time_balances
days_usednumeric
hours_usednumeric
actionvarcharNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 11 次 · 沒有表引用它

leave_requests26 欄 · FK 出 4 / 入 5002_schema.sql:3799
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
proxy_user_iduuidFKusers
leave_typeleave_typeNOT NULL
start_datedateNOT NULL
end_datedateNOT NULL
start_timetime_without_time_zone
end_timetime_without_time_zone
total_daysnumericNOT NULL
total_hoursnumeric
reasontext
supporting_documentsjsonb
annual_leave_source_iduuidFKannual_leave_entitlements
is_urgentboolean
is_retroactiveboolean
statusleave_status
current_approver_iduuidFKusers
submitted_attimestamptz
approved_attimestamptz
rejected_attimestamptz
cancelled_attimestamptz
revoked_attimestamptz
cancellation_reasontext
revocation_reasontext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 50 次 · 被這些表引用:calendar_event_synccalendar_sync_conflictsleave_approvalsleave_balance_usage

overtime_approvals7 欄 · FK 出 2 / 入 0002_schema.sql:4081
欄位型別NULL指向
iduuidNOT NULLPK
overtime_record_iduuidNOT NULLFKovertime_records CASCADE
approver_iduuidNOT NULLFKusers
approval_levelvarcharNOT NULL
actionvarcharNOT NULL
commentstext
created_attimestamptzNOT NULL

backend/src 出現 5 次 · 沒有表引用它

overtime_records30 欄 · FK 出 5 / 入 2002_schema.sql:4097
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
attendance_iduuidFKattendance_records
overtime_datedateNOT NULL
start_timetimestamptzNOT NULL
end_timetimestamptzNOT NULL
hoursnumericNOT NULL
overtime_typevarcharNOT NULL
multipliernumeric
comp_time_hoursnumericNOT NULL
comp_time_expires_atdateNOT NULL
comp_time_used_hoursnumeric
statusvarchar
submitted_attimestamptz
approved_byuuidFKusers
approved_attimestamptz
rejected_byuuidFKusers
rejected_attimestamptz
rejection_reasontext
reasontextNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
calc_unitvarcharNOT NULL
tier1_hoursnumericNOT NULL
tier2_hoursnumericNOT NULL
weighted_hoursnumericNOT NULL
day_countnumericNOT NULL
voided_byuuidFKusers
voided_attimestamptz
void_reasontext

backend/src 出現 34 次 · 被這些表引用:comp_time_balancesovertime_approvals

role_training_requirements7 欄 · FK 出 0 / 入 0002_schema.sql:4998
欄位型別NULL指向
iduuidNOT NULLPK
role_codevarcharNOT NULL無 FK
training_topicvarcharNOT NULL
is_mandatorybooleanNOT NULL
recurrence_monthsinteger
created_attimestamptzNOT NULL
deleted_attimestamptz

backend/src 出現 6 次 · 沒有表引用它

training_records8 欄 · FK 出 1 / 入 0002_schema.sql:5356
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
course_namevarcharNOT NULL
completed_atdateNOT NULL
expires_atdate
notestext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 9 次 · 沒有表引用它

設備與校正

9 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(2 條)。為了可讀,省略指向 users 的 8 條 FK(明細表裡有)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  equipment {
    uuid id PK
  }
  equipment_annual_plans {
    uuid id PK
    uuid equipment_id FK
  }
  equipment_calibrations {
    uuid id PK
    uuid equipment_id FK
    uuid partner_id FK
    varchar performed_by "無 FK"
    uuid reference_standard_id FK
  }
  equipment_disposals {
    uuid id PK
    uuid equipment_id FK
    uuid applied_by FK
    uuid approved_by FK
    uuid applicant_signature_id FK
    uuid approver_signature_id FK
  }
  equipment_idle_requests {
    uuid id PK
    uuid equipment_id FK
    uuid applied_by FK
    uuid applicant_signature_id FK
    uuid approved_by FK
    uuid approver_signature_id FK
  }
  equipment_maintenance_records {
    uuid id PK
    uuid equipment_id FK
    uuid repair_partner_id FK
    varchar performed_by "無 FK"
    uuid created_by FK
    uuid reviewed_by FK
    uuid reviewer_signature_id FK
  }
  equipment_status_logs {
    uuid id PK
    uuid equipment_id FK
    uuid changed_by FK
  }
  equipment_suppliers {
    uuid id PK
    uuid equipment_id FK
    uuid partner_id FK
  }
  reference_standards {
    uuid id PK
    uuid created_by FK
  }
  equipment ||--o{ equipment_annual_plans : "equipment_id · CASCADE"
  equipment ||--o{ equipment_calibrations : "equipment_id · CASCADE"
  partners |o--o{ equipment_calibrations : "partner_id"
  reference_standards |o--o{ equipment_calibrations : "reference_standard_id"
  electronic_signatures |o--o{ equipment_disposals : "applicant_signature_id"
  electronic_signatures |o--o{ equipment_disposals : "approver_signature_id"
  equipment ||--o{ equipment_disposals : "equipment_id · CASCADE"
  electronic_signatures |o--o{ equipment_idle_requests : "applicant_signature_id"
  electronic_signatures |o--o{ equipment_idle_requests : "approver_signature_id"
  equipment ||--o{ equipment_idle_requests : "equipment_id · CASCADE"
  equipment ||--o{ equipment_maintenance_records : "equipment_id · CASCADE"
  partners |o--o{ equipment_maintenance_records : "repair_partner_id"
  electronic_signatures |o--o{ equipment_maintenance_records : "reviewer_signature_id"
  equipment ||--o{ equipment_status_logs : "equipment_id · CASCADE"
  equipment ||--o{ equipment_suppliers : "equipment_id · CASCADE"
  partners ||--o{ equipment_suppliers : "partner_id · CASCADE"
  users |o..o{ equipment_calibrations : "performed_by(無 FK)"
  users |o..o{ equipment_maintenance_records : "performed_by(無 FK)"
equipment16 欄 · FK 出 0 / 入 7002_schema.sql:3045
欄位型別NULL指向
iduuidNOT NULLPK
namevarcharNOT NULL
modelvarchar
serial_numbervarchar
locationvarchar
notestext
is_activebooleanNOT NULL
statusequipment_statusNOT NULL
calibration_typecalibration_type
calibration_cyclecalibration_cycle
inspection_cyclecalibration_cycle
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
purchase_datedate
warranty_expirydate
departmentvarchar

backend/src 出現 239 次 · 被這些表引用:equipment_annual_plansequipment_calibrationsequipment_disposalsequipment_idle_requestsequipment_maintenance_recordsequipment_status_logsequipment_suppliers

equipment_annual_plans20 欄 · FK 出 1 / 入 0002_schema.sql:3069
欄位型別NULL指向
iduuidNOT NULLPK
yearintegerNOT NULL
equipment_iduuidNOT NULLFKequipment CASCADE
calibration_typecalibration_typeNOT NULL
cyclecalibration_cycleNOT NULL
month_1booleanNOT NULL
month_2booleanNOT NULL
month_3booleanNOT NULL
month_4booleanNOT NULL
month_5booleanNOT NULL
month_6booleanNOT NULL
month_7booleanNOT NULL
month_8booleanNOT NULL
month_9booleanNOT NULL
month_10booleanNOT NULL
month_11booleanNOT NULL
month_12booleanNOT NULL
generated_attimestamptzNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 8 次 · 沒有表引用它

equipment_calibrations25 欄 · FK 出 3 / 入 0002_schema.sql:3097
欄位型別NULL指向
iduuidNOT NULLPK
equipment_iduuidNOT NULLFKequipment CASCADE
calibrated_atdateNOT NULL
next_due_atdate
resultvarchar
notestext
calibration_typecalibration_typeNOT NULL
partner_iduuidFKpartners
report_numbervarchar
inspectorvarchar
equipment_serial_numbervarchar
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
certificate_numbervarchar
performed_byvarchar無 FK
acceptance_criteriavarchar
measurement_uncertaintyvarchar
validation_phasevalidation_phase
protocol_numbervarchar
reference_standard_iduuidFKreference_standards
calibration_lab_namevarchar
calibration_lab_accreditationvarchar
traceability_statementtext
reading_beforevarchar
reading_aftervarchar

backend/src 出現 12 次 · 沒有表引用它

equipment_disposals16 欄 · FK 出 5 / 入 0002_schema.sql:3130
欄位型別NULL指向
iduuidNOT NULLPK
equipment_iduuidNOT NULLFKequipment CASCADE
statusdisposal_statusNOT NULL
disposal_datedate
reasontextNOT NULL
disposal_methodtext
applied_byuuidNOT NULLFKusers
applied_attimestamptzNOT NULL
approved_byuuidFKusers
approved_attimestamptz
rejection_reasontext
applicant_signature_iduuidFKelectronic_signatures
approver_signature_iduuidFKelectronic_signatures
notestext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 18 次 · 沒有表引用它

equipment_idle_requests15 欄 · FK 出 5 / 入 0002_schema.sql:3154
欄位型別NULL指向
iduuidNOT NULLPK
equipment_iduuidNOT NULLFKequipment CASCADE
request_typetextNOT NULL
reasontextNOT NULL
statusdisposal_statusNOT NULL
applied_byuuidNOT NULLFKusers
applied_attimestamptzNOT NULL
applicant_signature_iduuidFKelectronic_signatures
approved_byuuidFKusers
approved_attimestamptz
approver_signature_iduuidFKelectronic_signatures
rejection_reasontext
notestext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 11 次 · 沒有表引用它

equipment_maintenance_records19 欄 · FK 出 5 / 入 0002_schema.sql:3178
欄位型別NULL指向
iduuidNOT NULLPK
equipment_iduuidNOT NULLFKequipment CASCADE
maintenance_typemaintenance_typeNOT NULL
statusmaintenance_statusNOT NULL
reported_atdateNOT NULL
completed_atdate
problem_descriptiontext
repair_contenttext
repair_partner_iduuidFKpartners
maintenance_itemstext
performed_byvarchar無 FK
notestext
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
reviewed_byuuidFKusers
reviewed_attimestamptz
reviewer_signature_iduuidFKelectronic_signatures
review_notestext

backend/src 出現 18 次 · 沒有表引用它

equipment_status_logs7 欄 · FK 出 2 / 入 0002_schema.sql:3205
欄位型別NULL指向
iduuidNOT NULLPK
equipment_iduuidNOT NULLFKequipment CASCADE
old_statusequipment_statusNOT NULL
new_statusequipment_statusNOT NULL
changed_byuuidNOT NULLFKusers
reasontext
created_attimestamptzNOT NULL

backend/src 出現 8 次 · 沒有表引用它

equipment_suppliers8 欄 · FK 出 2 / 入 0002_schema.sql:3220
欄位型別NULL指向
iduuidNOT NULLPK
equipment_iduuidNOT NULLFKequipment CASCADE
partner_iduuidNOT NULLFKpartners CASCADE
contact_personvarchar
contact_phonevarchar
contact_emailvarchar
notestext
created_attimestamptzNOT NULL

backend/src 出現 5 次 · 沒有表引用它

reference_standards17 欄 · FK 出 1 / 入 1002_schema.sql:4806
欄位型別NULL指向
iduuidNOT NULLPK
namevarcharNOT NULL
serial_numbervarchar
standard_typevarcharNOT NULL
traceable_tovarchar
national_standard_numbervarchar
calibration_labvarchar
calibration_lab_accreditationvarchar
last_calibrated_atdate
next_due_atdate
certificate_numbervarchar
measurement_uncertaintyvarchar
statusvarcharNOT NULL
notestext
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 7 次 · 被這些表引用:equipment_calibrations

QA・GLP 合規

22 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(2 條)。為了可讀,省略指向 users 的 29 條 FK(明細表裡有)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  audit_chain_known_breaks {
    uuid log_id PK
    text recorded_by "無 FK"
  }
  audit_logs {
    uuid id PK
    uuid actor_user_id FK
  }
  change_reasons {
    uuid id PK
    uuid changed_by FK
  }
  change_requests {
    uuid id PK
    varchar change_number UK
    uuid requested_by FK
    uuid reviewed_by FK
    uuid approved_by FK
    uuid verified_by FK
  }
  controlled_documents {
    uuid id PK
    varchar doc_number UK
    uuid owner_id FK
    uuid approved_by FK
  }
  data_retention_policies {
    uuid id PK
    text table_name UK
  }
  document_acknowledgments {
    uuid id PK
    uuid document_id FK
    uuid user_id FK
  }
  document_revisions {
    uuid id PK
    uuid document_id FK
    uuid revised_by FK
    uuid reviewed_by FK
    uuid approved_by FK
  }
  electronic_signatures {
    uuid id PK
    uuid signer_id FK
    uuid invalidated_by FK
    uuid delegation_id FK
  }
  management_reviews {
    uuid id PK
    varchar review_number UK
    uuid chaired_by FK
  }
  qa_audit_schedules {
    uuid id PK
    uuid created_by FK
  }
  qa_capa {
    uuid id PK
    uuid nc_id FK
    uuid assignee_id FK
  }
  qa_inspection_items {
    uuid id PK
    uuid inspection_id FK
  }
  qa_inspections {
    uuid id PK
    varchar inspection_number UK
    uuid inspector_id FK
  }
  qa_non_conformances {
    uuid id PK
    varchar nc_number UK
    uuid related_inspection_id FK
    uuid assignee_id FK
    uuid created_by FK
  }
  qa_schedule_items {
    uuid id PK
    uuid schedule_id FK
    uuid responsible_person_id FK
    uuid related_inspection_id FK
  }
  qa_sop_acknowledgments {
    uuid id PK
    uuid sop_id FK
    uuid user_id FK
  }
  qa_sop_documents {
    uuid id PK
    varchar document_number UK
    uuid created_by FK
    uuid reviewed_by FK
    uuid approved_by FK
  }
  record_annotations {
    uuid id PK
    uuid created_by FK
    uuid signature_id FK
  }
  record_versions {
    uuid id PK
    uuid changed_by FK
  }
  risk_register {
    uuid id PK
    varchar risk_number UK
    uuid owner_id FK
    uuid related_nc_id "無 FK"
  }
  signature_bridge_sessions {
    uuid id PK
    uuid user_id FK
  }
  controlled_documents ||--o{ document_acknowledgments : "document_id · CASCADE"
  controlled_documents ||--o{ document_revisions : "document_id · CASCADE"
  protocol_pi_delegates |o--o{ electronic_signatures : "delegation_id"
  qa_non_conformances ||--o{ qa_capa : "nc_id · CASCADE"
  qa_inspections ||--o{ qa_inspection_items : "inspection_id · CASCADE"
  qa_inspections |o--o{ qa_non_conformances : "related_inspection_id"
  qa_inspections |o--o{ qa_schedule_items : "related_inspection_id"
  qa_audit_schedules ||--o{ qa_schedule_items : "schedule_id · CASCADE"
  qa_sop_documents ||--o{ qa_sop_acknowledgments : "sop_id · CASCADE"
  electronic_signatures |o--o{ record_annotations : "signature_id"
  users |o..o{ audit_chain_known_breaks : "recorded_by(無 FK)"
  qa_non_conformances |o..o{ risk_register : "related_nc_id(無 FK)"
audit_chain_known_breaks4 欄 · FK 出 0 / 入 0002_schema.sql:2354
欄位型別NULL指向
log_iduuidNOT NULLPK
reasontextNOT NULL
recorded_attimestamptzNOT NULL
recorded_bytext無 FK

backend/src 出現 6 次 · 沒有表引用它

audit_logs10 欄 · FK 出 1 / 入 0002_schema.sql:2373
欄位型別NULL指向
iduuidNOT NULLPK
actor_user_iduuidNOT NULLFKusers
actionvarcharNOT NULL
entity_typevarcharNOT NULL
entity_iduuidNOT NULL
before_datajsonb
after_datajsonb
ip_addressvarchar
user_agenttext
created_attimestamptzNOT NULL

backend/src 出現 10 次 · 沒有表引用它

change_reasons10 欄 · FK 出 1 / 入 0002_schema.sql:2664
欄位型別NULL指向
iduuidNOT NULLPK
entity_typevarcharNOT NULL
entity_idtextNOT NULL
change_typevarcharNOT NULL
reasontextNOT NULL
old_valuesjsonb
new_valuesjsonb
changed_fieldstext[]
changed_byuuidFKusers
changed_attimestamptzNOT NULL

backend/src 出現 19 次 · 沒有表引用它

change_requests18 欄 · FK 出 4 / 入 0002_schema.sql:2682
欄位型別NULL指向
iduuidNOT NULLPK
change_numbervarcharNOT NULLUK
titlevarcharNOT NULL
change_typevarcharNOT NULL
descriptiontextNOT NULL
justificationtext
impact_assessmenttext
statusvarcharNOT NULL
requested_byuuidNOT NULLFKusers
reviewed_byuuidFKusers
reviewed_attimestamptz
approved_byuuidFKusers
approved_attimestamptz
implemented_attimestamptz
verified_byuuidFKusers
verified_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 11 次 · 沒有表引用它

controlled_documents17 欄 · FK 出 2 / 入 2002_schema.sql:2767
欄位型別NULL指向
iduuidNOT NULLPK
doc_numbervarcharNOT NULLUK
titlevarcharNOT NULL
doc_typevarcharNOT NULL
categoryvarchar
current_versionintegerNOT NULL
statusvarcharNOT NULL
effective_datedate
review_due_datedate
owner_iduuidFKusers
approved_byuuidFKusers
approved_attimestamptz
obsoleted_attimestamptz
retention_yearsinteger
file_pathtext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 14 次 · 被這些表引用:document_acknowledgmentsdocument_revisions

data_retention_policies7 欄 · FK 出 0 / 入 0002_schema.sql:2792
欄位型別NULL指向
iduuidNOT NULLPK
table_nametextNOT NULLUK
retention_yearsinteger
delete_strategytextNOT NULL
descriptiontext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 5 次 · 沒有表引用它

document_acknowledgments5 欄 · FK 出 2 / 入 0002_schema.sql:2855
欄位型別NULL指向
iduuidNOT NULLPK
document_iduuidNOT NULLFKcontrolled_documents CASCADE
user_iduuidNOT NULLFKusers
acknowledged_attimestamptzNOT NULL
version_acknowledgedintegerNOT NULL

backend/src 出現 2 次 · 沒有表引用它

document_revisions10 欄 · FK 出 4 / 入 0002_schema.sql:2897
欄位型別NULL指向
iduuidNOT NULLPK
document_iduuidNOT NULLFKcontrolled_documents CASCADE
versionintegerNOT NULL
change_summarytextNOT NULL
revised_byuuidFKusers
reviewed_byuuidFKusers
approved_byuuidFKusers
approved_attimestamptz
file_pathtext
created_attimestamptzNOT NULL

backend/src 出現 3 次 · 沒有表引用它

electronic_signatures20 欄 · FK 出 3 / 入 13002_schema.sql:2966
欄位型別NULL指向
iduuidNOT NULLPK
entity_typevarcharNOT NULL
entity_idvarcharNOT NULL
signer_iduuidNOT NULLFKusers
signature_typevarcharNOT NULL
content_hashvarcharNOT NULL
signature_datavarcharNOT NULL
ip_addressvarchar
user_agenttext
signed_attimestamptzNOT NULL
is_validbooleanNOT NULL
invalidated_reasontext
invalidated_attimestamptz
invalidated_byuuidFKusers
handwriting_svgtext
stroke_datajsonb
signature_methodvarchar
hmac_versionsmallintNOT NULL
meaningsignature_meaningNOT NULL
delegation_iduuidFKprotocol_pi_delegates

backend/src 出現 37 次 · 被這些表引用:amendmentsequipment_disposalsequipment_idle_requestsequipment_maintenance_recordspdf_artifactsprotocol_notice_acknowledgementsprotocolsrecord_annotationsstudy_final_reports

management_reviews14 欄 · FK 出 1 / 入 0002_schema.sql:3878
欄位型別NULL指向
iduuidNOT NULLPK
review_numbervarcharNOT NULLUK
titlevarcharNOT NULL
review_datedateNOT NULL
statusvarcharNOT NULL
agendatext
attendeesjsonb
minutestext
decisionsjsonb
action_itemsjsonb
chaired_byuuidFKusers
approved_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 8 次 · 沒有表引用它

qa_audit_schedules9 欄 · FK 出 1 / 入 1002_schema.sql:4620
欄位型別NULL指向
iduuidNOT NULLPK
yearintegerNOT NULL
titlevarcharNOT NULL
schedule_typeqa_schedule_typeNOT NULL
descriptiontext
statusqa_schedule_statusNOT NULL
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 6 次 · 被這些表引用:qa_schedule_items

qa_capa10 欄 · FK 出 2 / 入 0002_schema.sql:4637
欄位型別NULL指向
iduuidNOT NULLPK
nc_iduuidNOT NULLFKqa_non_conformances CASCADE
action_typecapa_action_typeNOT NULL
descriptiontextNOT NULL
assignee_iduuidFKusers
due_datedate
completed_attimestamptz
statuscapa_statusNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 4 次 · 沒有表引用它

qa_inspection_items7 欄 · FK 出 1 / 入 0002_schema.sql:4655
欄位型別NULL指向
iduuidNOT NULLPK
inspection_iduuidNOT NULLFKqa_inspections CASCADE
item_orderintegerNOT NULL
descriptiontextNOT NULL
resultqa_item_resultNOT NULL
remarkstext
created_attimestamptzNOT NULL

backend/src 出現 4 次 · 沒有表引用它

qa_inspections13 欄 · FK 出 1 / 入 3002_schema.sql:4670
欄位型別NULL指向
iduuidNOT NULLPK
inspection_numbervarcharNOT NULLUK
titlevarcharNOT NULL
inspection_typeqa_inspection_typeNOT NULL
inspection_datedateNOT NULL
inspector_iduuidNOT NULLFKusers
related_entity_typevarchar
related_entity_iduuid
statusqa_inspection_statusNOT NULL
findingstext
conclusiontext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 7 次 · 被這些表引用:qa_inspection_itemsqa_non_conformancesqa_schedule_items

qa_non_conformances16 欄 · FK 出 3 / 入 1002_schema.sql:4691
欄位型別NULL指向
iduuidNOT NULLPK
nc_numbervarcharNOT NULLUK
titlevarcharNOT NULL
descriptiontextNOT NULL
severitync_severityNOT NULL
sourcenc_sourceNOT NULL
related_inspection_iduuidFKqa_inspections
assignee_iduuidFKusers
due_datedate
statusnc_statusNOT NULL
root_causetext
closure_notestext
closed_attimestamptz
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 8 次 · 被這些表引用:qa_capa

qa_schedule_items12 欄 · FK 出 3 / 入 0002_schema.sql:4715
欄位型別NULL指向
iduuidNOT NULLPK
schedule_iduuidNOT NULLFKqa_audit_schedules CASCADE
inspection_typeqa_inspection_typeNOT NULL
titlevarcharNOT NULL
planned_datedateNOT NULL
actual_datedate
responsible_person_iduuidFKusers
related_inspection_iduuidFKqa_inspections
statusqa_schedule_item_statusNOT NULL
notestext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 5 次 · 沒有表引用它

qa_sop_acknowledgments4 欄 · FK 出 2 / 入 0002_schema.sql:4735
欄位型別NULL指向
iduuidNOT NULLPK
sop_iduuidNOT NULLFKqa_sop_documents CASCADE
user_iduuidNOT NULLFKusers
acknowledged_attimestamptzNOT NULL

backend/src 出現 6 次 · 沒有表引用它

qa_sop_documents19 欄 · FK 出 3 / 入 1002_schema.sql:4747
欄位型別NULL指向
iduuidNOT NULLPK
document_numbervarcharNOT NULLUK
titlevarcharNOT NULL
versionvarcharNOT NULL
categoryvarchar
file_pathvarchar
effective_datedate
review_datedate
statussop_statusNOT NULL
descriptiontext
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
reviewed_byuuidFKusers
reviewed_attimestamptz
approved_byuuidFKusers
approved_attimestamptz
review_due_datedate
revision_historyjsonb

backend/src 出現 13 次 · 被這些表引用:qa_sop_acknowledgments

record_annotations8 欄 · FK 出 2 / 入 0002_schema.sql:4774
欄位型別NULL指向
iduuidNOT NULLPK
record_typevarcharNOT NULL
record_idintegerNOT NULL
annotation_typevarcharNOT NULL
contenttextNOT NULL
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
signature_iduuidFKelectronic_signatures

backend/src 出現 3 次 · 沒有表引用它

record_versions8 欄 · FK 出 1 / 入 0002_schema.sql:4790
欄位型別NULL指向
iduuidNOT NULLPK
record_typeversion_record_typeNOT NULL
record_iduuidNOT NULL
version_nointegerNOT NULL
snapshotjsonbNOT NULL
diff_summarytext
changed_byuuidFKusers
changed_attimestamptzNOT NULL

backend/src 出現 5 次 · 沒有表引用它

risk_register18 欄 · FK 出 1 / 入 0002_schema.sql:4959
欄位型別NULL指向
iduuidNOT NULLPK
risk_numbervarcharNOT NULLUK
titlevarcharNOT NULL
descriptiontext
categoryvarchar
sourcevarchar
severityintegerNOT NULL
likelihoodintegerNOT NULL
detectabilityinteger
risk_scoreinteger
statusvarcharNOT NULL
mitigation_plantext
residual_risk_scoreinteger
owner_iduuidFKusers
review_datedate
related_nc_iduuid無 FK
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 8 次 · 沒有表引用它

signature_bridge_sessions10 欄 · FK 出 1 / 入 0002_schema.sql:5107
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
mobile_token_hashvarcharNOT NULL
purposevarcharNOT NULL
payloadtext
statusvarcharNOT NULL
expires_attimestamptzNOT NULL
created_attimestamptzNOT NULL
submitted_attimestamptz
consumed_attimestamptz

backend/src 出現 9 次 · 沒有表引用它

平台・通知・稽核軌跡

21 張表

實線=有 FK 約束;虛線=沒有約束但確實是關聯(3 條)。為了可讀,省略指向 users 的 19 條 FK(明細表裡有)。屬性只列 PK/FK/UK 與被標記的欄位。

erDiagram
  ai_query_logs {
    uuid id PK
    uuid api_key_id "無 FK"
    timestamptz created_at PK
  }
  attachments {
    uuid id PK
    uuid uploaded_by FK
  }
  event_outbox {
    uuid id PK
    uuid enqueued_by FK
  }
  export_jobs {
    uuid id PK
    uuid created_by FK
  }
  import_jobs {
    uuid id PK
    uuid created_by FK
  }
  message_attachments {
    uuid id PK
    uuid message_id FK
    uuid uploaded_by FK
  }
  message_thread_participants {
    uuid thread_id PK, FK
    uuid user_id PK, FK
  }
  message_threads {
    uuid id PK
    uuid created_by FK
  }
  messages {
    uuid id PK
    uuid thread_id FK
    uuid sender_id FK
  }
  notification_routing {
    uuid id PK
    varchar role_code FK
  }
  notification_settings {
    uuid user_id PK, FK
  }
  notifications {
    uuid id PK
    uuid user_id FK
  }
  pdf_artifacts {
    uuid id PK
    uuid generated_by FK
    uuid electronic_signature_id FK
    uuid attachment_id FK
  }
  report_history {
    uuid id PK
    uuid scheduled_report_id FK
    uuid generated_by FK
  }
  scheduled_reports {
    uuid id PK
    uuid created_by FK
  }
  security_alert_config {
    varchar key PK
  }
  security_alerts {
    uuid id PK
    uuid user_id FK
    uuid activity_log_id "無 FK"
    uuid login_event_id FK
    uuid resolved_by FK
  }
  security_notification_channels {
    uuid id PK
  }
  system_settings {
    varchar key PK
    uuid updated_by FK
  }
  user_activity_aggregates {
    uuid id PK
    uuid user_id FK
  }
  user_activity_logs {
    uuid id PK
    uuid actor_user_id FK
    uuid session_id "無 FK"
    date partition_date PK
    uuid impersonated_by_user_id FK
  }
  messages |o--o{ message_attachments : "message_id · CASCADE"
  message_threads ||--o{ message_thread_participants : "thread_id · CASCADE"
  message_threads ||--o{ messages : "thread_id · CASCADE"
  roles |o--o{ notification_routing : "role_code"
  attachments |o--o{ pdf_artifacts : "attachment_id"
  electronic_signatures |o--o{ pdf_artifacts : "electronic_signature_id"
  scheduled_reports |o--o{ report_history : "scheduled_report_id"
  login_events |o--o{ security_alerts : "login_event_id"
  ai_api_keys |o..o{ ai_query_logs : "api_key_id(無 FK)"
  user_activity_logs |o..o{ security_alerts : "activity_log_id(無 FK)"
  user_sessions |o..o{ user_activity_logs : "session_id(無 FK)"
ai_query_logs9 欄 · FK 出 0 / 入 0 · 分區 ×2002_schema.sql:1558
欄位型別NULL指向
iduuidNOT NULLPK
api_key_iduuidNOT NULL無 FK
endpointvarcharNOT NULL
methodvarcharNOT NULL
query_summaryjsonb
response_statussmallintNOT NULL
duration_msintegerNOT NULL
source_ipvarchar
created_attimestamptzNOT NULLPK

backend/src 出現 3 次 · 沒有表引用它

attachments10 欄 · FK 出 1 / 入 3002_schema.sql:2302
欄位型別NULL指向
iduuidNOT NULLPK
categoryvarcharNOT NULL
entity_idvarchar
entity_typevarchar
file_namevarcharNOT NULL
file_pathvarcharNOT NULL
file_sizeintegerNOT NULL
mime_typevarcharNOT NULL
uploaded_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL

backend/src 出現 59 次 · 被這些表引用:application_noticespdf_artifactsprotocol_notice_acknowledgements

event_outbox13 欄 · FK 出 1 / 入 0002_schema.sql:3374
欄位型別NULL指向
iduuidNOT NULLPK
channeltextNOT NULL
payloadjsonbNOT NULL
statustextNOT NULL
attempt_countintegerNOT NULL
next_attempt_attimestamptzNOT NULL
last_errortext
enqueued_byuuidFKusers
enqueued_attimestamptzNOT NULL
started_attimestamptz
done_attimestamptz
source_entitytext
source_entity_iduuid

backend/src 出現 11 次 · 沒有表引用它

export_jobs11 欄 · FK 出 1 / 入 0002_schema.sql:3518
欄位型別NULL指向
iduuidNOT NULLPK
export_typeexport_typeNOT NULL
export_formatexport_formatNOT NULL
statusimport_statusNOT NULL
file_namevarchar
file_pathvarchar
parametersjsonb
started_attimestamptz
completed_attimestamptz
created_byuuidFKusers
created_attimestamptzNOT NULL

backend/src 出現 1 次 · 沒有表引用它

import_jobs14 欄 · FK 出 1 / 入 0002_schema.sql:3609
欄位型別NULL指向
iduuidNOT NULLPK
import_typeimport_typeNOT NULL
statusimport_statusNOT NULL
file_namevarcharNOT NULL
file_pathvarcharNOT NULL
total_rowsinteger
processed_rowsinteger
success_rowsinteger
error_rowsinteger
error_detailsjsonb
started_attimestamptz
completed_attimestamptz
created_byuuidFKusers
created_attimestamptzNOT NULL

backend/src 出現 1 次 · 沒有表引用它

message_attachments9 欄 · FK 出 2 / 入 0002_schema.sql:3900
欄位型別NULL指向
iduuidNOT NULLPK
message_iduuidFKmessages CASCADE
uploaded_byuuidNOT NULLFKusers
file_namevarcharNOT NULL
file_pathtextNOT NULL
file_sizebigintNOT NULL
mime_typevarcharNOT NULL
sort_orderintegerNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 8 次 · 沒有表引用它

message_thread_participants5 欄 · FK 出 2 / 入 0002_schema.sql:3917
欄位型別NULL指向
thread_iduuidNOT NULLPKFKmessage_threads CASCADE
user_iduuidNOT NULLPKFKusers CASCADE
joined_attimestamptzNOT NULL
last_read_attimestamptz
left_attimestamptz

backend/src 出現 13 次 · 沒有表引用它

message_threads7 欄 · FK 出 1 / 入 2002_schema.sql:3930
欄位型別NULL指向
iduuidNOT NULLPK
typevarcharNOT NULL
subjectvarchar
created_byuuidNOT NULLFKusers
created_attimestamptzNOT NULL
last_message_attimestamptzNOT NULL
deleted_attimestamptz

backend/src 出現 6 次 · 被這些表引用:message_thread_participantsmessages

messages7 欄 · FK 出 2 / 入 1002_schema.sql:3946
欄位型別NULL指向
iduuidNOT NULLPK
thread_iduuidNOT NULLFKmessage_threads CASCADE
sender_iduuidNOT NULLFKusers
bodytextNOT NULL
created_attimestamptzNOT NULL
edited_attimestamptz
deleted_attimestamptz

backend/src 出現 35 次 · 被這些表引用:message_attachments

notification_routing13 欄 · FK 出 1 / 入 0002_schema.sql:3961
欄位型別NULL指向
iduuidNOT NULLPK
event_typevarcharNOT NULL
role_codevarcharFKroles
channelvarcharNOT NULL
is_activebooleanNOT NULL
descriptiontext
frequencyvarcharNOT NULL
hour_of_daysmallintNOT NULL
day_of_weeksmallint
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
target_kindvarcharNOT NULL
target_valuevarcharNOT NULL

backend/src 出現 50 次 · 沒有表引用它

notification_settings9 欄 · FK 出 1 / 入 0002_schema.sql:4022
欄位型別NULL指向
user_iduuidNOT NULLPKFKusers CASCADE
email_low_stockbooleanNOT NULL
email_expiry_warningbooleanNOT NULL
email_document_approvalbooleanNOT NULL
email_protocol_statusbooleanNOT NULL
email_monthly_reportbooleanNOT NULL
expiry_warning_daysintegerNOT NULL
low_stock_notify_immediatelybooleanNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 22 次 · 沒有表引用它

notifications13 欄 · FK 出 1 / 入 0002_schema.sql:4039
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidNOT NULLFKusers CASCADE
typenotification_typeNOT NULL
titlevarcharNOT NULL
contenttext
is_readbooleanNOT NULL
read_attimestamptz
related_entity_typevarchar
related_entity_iduuid
created_attimestamptzNOT NULL
prioritysmallintNOT NULL
kindtextNOT NULL
recipient_roletext

backend/src 出現 59 次 · 沒有表引用它

pdf_artifacts15 欄 · FK 出 3 / 入 0002_schema.sql:4224
欄位型別NULL指向
iduuidNOT NULLPK
resource_typetextNOT NULL
resource_idtextNOT NULL
pdf_blob_hashtextNOT NULL
pdf_size_bytesbigintNOT NULL
doc_typetextNOT NULL
generated_byuuidNOT NULLFKusers
generated_attimestamptzNOT NULL
request_ipinet
user_agenttext
electronic_signature_iduuidFKelectronic_signatures
hmac_chain_linktext
attachment_iduuidFKattachments
storage_strategytextNOT NULL
created_attimestamptzNOT NULL

backend/src 出現 6 次 · 沒有表引用它

report_history9 欄 · FK 出 2 / 入 0002_schema.sql:4872
欄位型別NULL指向
iduuidNOT NULLPK
scheduled_report_iduuidFKscheduled_reports SET NULL
report_typereport_typeNOT NULL
file_namevarcharNOT NULL
file_pathvarcharNOT NULL
file_sizeinteger
parametersjsonb
generated_attimestamptzNOT NULL
generated_byuuidFKusers

backend/src 出現 4 次 · 沒有表引用它

scheduled_reports14 欄 · FK 出 1 / 入 1002_schema.sql:5030
欄位型別NULL指向
iduuidNOT NULLPK
report_typereport_typeNOT NULL
schedule_typeschedule_typeNOT NULL
day_of_weekinteger
day_of_monthinteger
hour_of_dayintegerNOT NULL
parametersjsonb
recipientsuuid[]NOT NULL
is_activebooleanNOT NULL
last_run_attimestamptz
next_run_attimestamptz
created_byuuidFKusers
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 7 次 · 被這些表引用:report_history

security_alert_config4 欄 · FK 出 0 / 入 0002_schema.sql:5052
欄位型別NULL指向
keyvarcharNOT NULLPK
valuetextNOT NULL
descriptiontext
updated_attimestamptzNOT NULL

backend/src 出現 4 次 · 沒有表引用它

security_alerts16 欄 · FK 出 3 / 入 0002_schema.sql:5064
欄位型別NULL指向
iduuidNOT NULLPK
alert_typevarcharNOT NULL
severityvarcharNOT NULL
titlevarcharNOT NULL
descriptiontext
user_iduuidFKusers
activity_log_iduuid無 FK
login_event_iduuidFKlogin_events
context_datajsonb
statusvarchar
resolved_byuuidFKusers
resolved_attimestamptz
resolution_notestext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
last_notified_attimestamptz

backend/src 出現 39 次 · 沒有表引用它

security_notification_channels7 欄 · FK 出 0 / 入 0002_schema.sql:5090
欄位型別NULL指向
iduuidNOT NULLPK
channelvarcharNOT NULL
is_enabledbooleanNOT NULL
config_jsonjsonbNOT NULL
min_severityvarcharNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 4 次 · 沒有表引用它

system_settings5 欄 · FK 出 1 / 入 0002_schema.sql:5343
欄位型別NULL指向
keyvarcharNOT NULLPK
valuejsonbNOT NULL
descriptiontext
updated_attimestamptzNOT NULL
updated_byuuidFKusers

backend/src 出現 34 次 · 沒有表引用它

user_activity_aggregates16 欄 · FK 出 1 / 入 0002_schema.sql:5409
欄位型別NULL指向
iduuidNOT NULLPK
user_iduuidFKusers CASCADE
aggregate_datedateNOT NULL
login_countinteger
failed_login_countinteger
session_countinteger
total_session_minutesinteger
page_view_countinteger
action_countinteger
actions_by_categoryjsonb
pages_visitedjsonb
entities_modifiedjsonb
unique_ip_countinteger
unusual_activity_countinteger
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

backend/src 出現 2 次 · 沒有表引用它

user_activity_logs32 欄 · FK 出 2 / 入 0 · 分區 ×12002_schema.sql:5433
欄位型別NULL指向
iduuidNOT NULLPK
actor_user_iduuidFKusers
actor_emailvarchar
actor_display_namevarchar
actor_rolesjsonb
session_iduuid無 FK
session_started_attimestamptz
event_categoryvarcharNOT NULL
event_typevarcharNOT NULL
event_severityvarchar
entity_typevarchar
entity_iduuid
entity_display_namevarchar
before_datajsonb
after_datajsonb
changed_fieldstext[]
ip_addressinet
user_agenttext
request_pathvarchar
request_methodvarchar
response_statusinteger
geo_countryvarchar
geo_cityvarchar
is_suspiciousboolean
suspicious_reasontext
created_attimestamptzNOT NULL
partition_datedateNOT NULLPK
integrity_hashvarchar
previous_hashvarchar
impersonated_by_user_iduuidFKusers
hmac_versionsmallint
extra_inputtext

backend/src 出現 79 次 · 沒有表引用它

怎麼算的

  • 來源是 gitlab/mainbackend/migrations,依檔名順序套用 CREATE TABLEALTER TABLE … ADD COLUMN/ADD CONSTRAINTCREATE INDEX。FK 總數與 migration 檔中 FOREIGN KEYREFERENCES 字樣的出現數逐一對過。
  • 分區子表(14 張)併回母表;view(6 個)不畫。
  • 「缺 FK」是用欄位名稱(_id_by)找候選,再逐欄讀定義人工判定,所以只抓得到名字像外鍵的欄位。命名不規則的關聯(例如只叫 owner)抓不到。
  • 「文字鍵關聯」是找另一張表 UNIQUE 文字欄位的同名欄位,或 <單數表名>_<欄位> 形式。
  • 「後端出現次數」是 backend/src 全文比對表名,只證明有被提到,不證明有被正確使用。
  • 未涵蓋:資料庫實際狀態(本頁不連任何資料庫)、觸發器與 CHECK 約束的內容、應用層的完整性檢查。