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_id | uuid NN | 缺 FK | ai_api_keys | PG16 允許分區母表建 FK 指向一般表。目前查詢紀錄可以指向已不存在的 API key。 |
amendment_status_history.changed_by | uuid NN | 缺 FK | users | NOT NULL 的行為人欄位。同一族的 amendment_versions.submitted_by 有 FK,它沒有。 |
ip_blocklist.alert_id | uuid | 缺 FK | security_alerts | 封鎖紀錄指向觸發它的警報,資料庫不檢查。 |
observation_vet_reads.observation_id | uuid NN | 缺 FK | animal_observations | 「獸醫已讀」可以指向不存在的觀察紀錄。同一張表的 vet_user_id 有 FK。 |
risk_register.related_nc_id | uuid | 缺 FK | qa_non_conformances | 風險登錄連到不符合事項,資料庫不檢查。 |
surgery_vet_reads.surgery_id | uuid NN | 缺 FK | animal_surgeries | 同上,對應手術紀錄。 |
security_alerts.activity_log_id | uuid | 結構上建不了 | user_activity_logs | user_activity_logs 的主鍵是 (id, partition_date),單欄 FK 建不起來。要約束就得連 partition_date 一起存。 |
user_activity_logs.session_id | uuid | 可能是刻意的 | user_sessions | 稽核紀錄必須在 session 清掉之後仍保留,不綁 FK 很可能是刻意的——但沒有註解寫明。 |
audit_chain_known_breaks.recorded_by | text | 存文字不存 id | users | 存的是文字。要追到帳號應為 uuid FK;若刻意要在帳號刪除後仍可讀,建議在 migration 註解寫明。 |
equipment_calibrations.performed_by | varchar | 存文字不存 id | users | 人名自由文字。外部校正廠商執行時合理;內部人員執行時就追不到帳號。 |
equipment_maintenance_records.performed_by | varchar | 存文字不存 id | users | 同上,維修紀錄。 |
animals.animal_id | uuid | 用途不明 | — | animals 表裡有一欄叫 animal_id 的 uuid,沒有 FK,也看不出指向哪裡。可能是舊系統遷移留下的,值得查是否還有人寫入。 |
用文字編號關聯,而不是 id
4另一張表有 UNIQUE 的文字欄位,這裡存了同名欄位卻沒有 FK。對方改號或刪除時,這邊不會被擋,也不會跟著變。最重要的是第一列:動物和計畫之間的分派關係,整個系統都是用文字 JOIN 的。
| 欄位 | 型別 | 判定 | 對應到 | 說明 |
|---|---|---|---|---|
animals.iacuc_no | varchar | 文字鍵,沒有 FK | protocols.iacuc_no | 「這頭豬屬於哪個計畫」實際上靠這一欄。後端的權限檢查(services/access.rs)、病歷報表、安樂死流程都用 animals.iacuc_no = protocols.iacuc_no 做 JOIN。計畫改 IACUC 編號或打錯一個字,動物就默默脫離計畫,權限跟著失效。animals 另有 reserved_protocol_id FK,但那是「預留」,不是「分派」。 |
documents.iacuc_no | varchar | 文字鍵,沒有 FK | protocols.iacuc_no | ERP 單據用文字編號掛到計畫;費用歸屬計畫時靠它,斷鏈風險同上。 |
role_training_requirements.role_code | varchar | 文字鍵,沒有 FK | roles.code | notification_routing.role_code 有 FK 指向 roles(code),這張沒有。角色改碼或刪除時,訓練要求會指向不存在的角色。 |
animal_sudden_deaths.iacuc_no | varchar | 可能是刻意的 | protocols.iacuc_no | 猝死當下的計畫編號。如果是刻意保存當時的快照就合理;如果拿來查計畫,斷鏈風險和 animals.iacuc_no 一樣。 |
stock_ledger.doc_no | varchar | 設計上不綁 | documents.doc_no | 同一張表已有 doc_id FK,doc_no 是冗餘的單號快照。 |
expiry_monthly_snapshots.sku | varchar | 設計上不綁 | products.sku | 月快照保存當時的 SKU,同一張表另有 product_id FK。 |
migration 011 留下的備份表
3011 為了能回退,建了 mig011_conversion_backup、mig011_inserted_conversion、mig011_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_id | record_type | uuid |
attachments.entity_id | entity_type | varchar |
audit_logs.entity_id | entity_type | uuid |
care_medication_records.record_id | record_type | uuid |
change_reasons.entity_id | entity_type | text |
electronic_signatures.entity_id | entity_type | varchar |
journal_entries.source_entity_id | source_entity_type | uuid |
notifications.related_entity_id | related_entity_type | uuid |
pdf_artifacts.resource_id | resource_type | text |
protocol_activities.target_entity_id | target_entity_type | uuid |
qa_inspections.related_entity_id | related_entity_type | uuid |
record_annotations.record_id | record_type | integer 型別不符 |
record_versions.record_id | record_type | uuid |
user_activity_logs.entity_id | entity_type | uuid |
刪掉一筆會連帶刪掉什麼
91 條 CASCADE沿 ON DELETE CASCADE 往下展開的完整範圍(下標是第幾層)。綠底的表有 migration 012 的鎖定觸發器,is_locked = true 時會擋 DELETE;其他的沒有。「後端硬刪」是 backend/src 裡 DELETE FROM <表> 的出現處數。注意:只要還有任何 NO ACTION 的 FK 指著那筆資料,刪除會整個失敗,CASCADE 就不會發生。
| 刪除 | 波及表數 | 後端硬刪 | 會被一起刪的表 |
|---|---|---|---|
| users | 23 | 0 | annual_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 |
| protocols | 16 | 1 處 | amendmentspi_account_invitesprotocol_activitiesprotocol_ai_reviewsprotocol_attachmentsprotocol_notice_acknowledgementsprotocol_versionsreview_assignmentsreview_round_historyuser_protocolsvet_review_assignmentsprotocol_pi_delegatesamendment_review_assignments2amendment_status_history2amendment_versions2review_comments2 |
| animals | 12 | 0 | animal_blood_testsanimal_field_correction_requestsanimal_observationsanimal_pathology_reportsanimal_sacrificesanimal_surgeriesanimal_vaccinationsanimal_weightseuthanasia_ordersvet_patrol_entry_animalsanimal_blood_test_items2euthanasia_appeals2 |
| products | 2 | 1 處 | product_uom_conversionsstorage_location_inventory |
| documents | 1 | 1 處 | document_lines |
| equipment | 7 | 1 處 | equipment_annual_plansequipment_calibrationsequipment_disposalsequipment_idle_requestsequipment_maintenance_recordsequipment_status_logsequipment_suppliers |
| amendments | 3 | 0 | amendment_review_assignmentsamendment_status_historyamendment_versions |
| euthanasia_orders | 1 | 0 | euthanasia_appeals |
外鍵欄位沒有索引
168FK 欄位不在任何索引的開頭。影響兩件事:依關聯查詢時要掃表,刪除或更新被參照的列時要逐表掃描檢查。其中 132 條指向 users(多為 created_by 這類行為人欄位,使用者幾乎不會被刪,影響小),下表只列其餘 36 條。
沒有任何 FK 進出的表
14和其他表之間一條約束都沒有。設定表、序號表本來就該獨立;存了關聯值卻是孤島的,就是漏掉的地方。
橘框:本頁其他檢查已發現它其實有關聯。
後端程式碼幾乎沒用到的表
14backend/src(418 個檔)裡表名出現 ≤ 2 次。沒有任何表是 0 次,所以沒有死表;出現 1 次通常只是資料匯出清單,代表功能可能還沒接上。
| 表 | 出現次數 | 所在領域 |
|---|---|---|
| affiliation_types | 1 | 身分・權限・組織 |
| export_jobs | 1 | 平台・通知・稽核軌跡 |
| import_jobs | 1 | 平台・通知・稽核軌跡 |
| mig011_conversion_backup | 1 | ERP・庫存 |
| mig011_inserted_conversion | 1 | ERP・庫存 |
| mig011_pack_unit_backup | 1 | ERP・庫存 |
| personnel_affiliations | 1 | 身分・權限・組織 |
| protocol_attachments | 1 | AUP 計畫審查 |
| review_round_history | 1 | AUP 計畫審查 |
| user_aup_profiles | 1 | 身分・權限・組織 |
| document_acknowledgments | 2 | QA・GLP 合規 |
| observation_vet_reads | 2 | 動物與獸醫紀錄 |
| surgery_vet_reads | 2 | 動物與獸醫紀錄 |
| user_activity_aggregates | 2 | 平台・通知・稽核軌跡 |
規格文件的 ERD 沒畫到的表
114 / 175docs/spec/architecture/database_erd.md 裡 mermaid 圖出現過的實體共 66 個,下列資料表一次都沒出現。
身分・權限・組織 11
AUP 計畫審查 11
動物與獸醫紀錄 16
ERP・庫存 12
人事・出勤・行事曆 12
設備與校正 9
QA・GLP 合規 19
平台・通知・稽核軌跡 17
名字像外鍵、複核後不算遺漏
8腳本用欄位名稱抓出來、逐一看過定義之後排除的項目,列出來避免下次重查。
| 欄位 | 型別 | 判定 | 說明 |
|---|---|---|---|
animals.lab_animal_id | varchar | 外部系統 ID | 外部實驗動物編號(varchar)。 |
calendar_event_sync.google_event_id | varchar | 外部系統 ID | Google Calendar 事件 ID。 |
event_outbox.source_entity_id | uuid | 設計上不綁 | outbox 事件來源,指向哪張表由事件類型決定,本質上是多型。 |
google_calendar_config.calendar_id | varchar | 外部系統 ID | Google Calendar ID。 |
google_calendar_config.event_color_id | varchar | 外部系統 ID | Google Calendar 顏色代碼。 |
partners.tax_id | varchar | 外部系統 ID | 統一編號。 |
refresh_tokens.family_id | uuid | 設計上不綁 | refresh token 輪替用的家族群組碼,不指向任何表。 |
mig011_conversion_backup.product_id | uuid | 設計上不綁 | 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 | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
is_internal | boolean | NOT NULL | ||
default_eligible_annual_leave | boolean | NOT NULL | ||
default_eligible_leave | boolean | NOT NULL | ||
default_eligible_overtime | boolean | NOT NULL | ||
default_assignable_to_protocol | boolean | NOT NULL | ||
default_requires_leave_proxy | boolean | NOT NULL | ||
sort_order | integer | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 1 次 · 被這些表引用:personnel_affiliations
ai_api_keys13 欄 · FK 出 1 / 入 0002_schema.sql:1536
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
name | varchar | NOT NULL | ||
key_hash | varchar | NOT NULL | UK | |
key_prefix | varchar | NOT NULL | ||
created_by | uuid | NOT NULL | FK | users |
scopes | jsonb | NOT NULL | ||
is_active | boolean | NOT NULL | ||
expires_at | timestamptz | |||
last_used_at | timestamptz | |||
usage_count | bigint | NOT NULL | ||
rate_limit_per_minute | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 10 次 · 沒有表引用它
departments10 欄 · FK 出 2 / 入 3002_schema.sql:2837
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
parent_id | uuid | FK | departments | |
manager_id | uuid | FK | users | |
is_active | boolean | NOT NULL | ||
config | jsonb | |||
sort_order | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 38 次 · 被這些表引用:departments、personnel_affiliations、users
invitation_roles2 欄 · FK 出 2 / 入 0002_schema.sql:3645
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
invitation_id | uuid | NOT NULL | PKFK | invitations CASCADE |
role_id | uuid | NOT NULL | PKFK | roles RESTRICT |
backend/src 出現 8 次 · 沒有表引用它
invitations15 欄 · FK 出 2 / 入 1002_schema.sql:3655
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
email | varchar | NOT NULL | ||
organization | varchar | |||
invitation_token | varchar | NOT NULL | UK | |
invited_by | uuid | NOT NULL | FK | users |
status | varchar | NOT NULL | ||
expires_at | timestamptz | NOT NULL | ||
accepted_at | timestamptz | |||
created_user_id | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
display_name | varchar | |||
phone | varchar | |||
position | varchar | |||
is_internal | boolean | NOT NULL |
backend/src 出現 36 次 · 被這些表引用:invitation_roles
ip_blocklist14 欄 · FK 出 2 / 入 0002_schema.sql:3686
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
ip_address | inet | NOT NULL | ||
reason | text | NOT NULL | ||
source | text | NOT NULL | ||
alert_id | uuid | 無 FK | ||
blocked_at | timestamptz | NOT NULL | ||
blocked_until | timestamptz | |||
blocked_by | uuid | FK | users | |
hit_count | bigint | NOT NULL | ||
last_hit_at | timestamptz | |||
unblocked_at | timestamptz | |||
unblocked_by | uuid | FK | users | |
unblocked_reason | text | |||
metadata | jsonb |
backend/src 出現 23 次 · 沒有表引用它
jwt_blacklist3 欄 · FK 出 0 / 入 0002_schema.sql:3753
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
jti | varchar | NOT NULL | PK | |
expires_at | timestamptz | NOT NULL | ||
revoked_at | timestamptz | NOT NULL |
backend/src 出現 25 次 · 沒有表引用它
login_events19 欄 · FK 出 1 / 入 1002_schema.sql:3851
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | FK | users | |
email | varchar | NOT NULL | ||
event_type | varchar | NOT NULL | ||
ip_address | inet | |||
user_agent | text | |||
device_type | varchar | |||
browser | varchar | |||
os | varchar | |||
geo_country | varchar | |||
geo_city | varchar | |||
geo_timezone | varchar | |||
is_unusual_time | boolean | |||
is_unusual_location | boolean | |||
is_new_device | boolean | |||
is_mass_login | boolean | |||
device_fingerprint | varchar | |||
failure_reason | varchar | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 39 次 · 被這些表引用:security_alerts
password_reset_tokens6 欄 · FK 出 1 / 入 0002_schema.sql:4210
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
token_hash | varchar | NOT NULL | ||
expires_at | timestamptz | NOT NULL | ||
used_at | timestamptz | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 沒有表引用它
permissions6 欄 · FK 出 0 / 入 1002_schema.sql:4306
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
module | varchar | |||
description | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 138 次 · 被這些表引用:role_permissions
personnel_affiliations14 欄 · FK 出 3 / 入 0004_personnel_affiliations.sql:43
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users |
affiliation_type_id | uuid | NOT NULL | FK | affiliation_types |
effective_from | date | NOT NULL | ||
effective_to | date | |||
eligible_annual_leave | boolean | NOT NULL | ||
eligible_leave | boolean | NOT NULL | ||
eligible_overtime | boolean | NOT NULL | ||
assignable_to_protocol | boolean | NOT NULL | ||
requires_leave_proxy | boolean | NOT NULL | ||
department_id | uuid | FK | departments | |
note | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 1 次 · 沒有表引用它
pi_account_invites11 欄 · FK 出 4 / 入 0002_schema.sql:4320
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FK | protocols CASCADE |
pi_user_id | uuid | NOT NULL | FK | users CASCADE |
email | varchar | NOT NULL | ||
status | varchar | NOT NULL | ||
provisioned_by | uuid | NOT NULL | FK | users |
provisioned_at | timestamptz | NOT NULL | ||
approved_by | uuid | FK | users | |
sent_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 10 次 · 沒有表引用它
refresh_tokens12 欄 · FK 出 1 / 入 1002_schema.sql:4831
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
token_hash | varchar | NOT NULL | ||
expires_at | timestamptz | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
revoked_at | timestamptz | |||
family_id | uuid | NOT NULL | ||
revoked_reason | text | |||
last_used_at | timestamptz | NOT NULL | ||
rotated_at | timestamptz | |||
last_ip | text | |||
last_user_agent | text |
backend/src 出現 16 次 · 被這些表引用:user_sessions
role_permissions2 欄 · FK 出 2 / 入 0002_schema.sql:4988
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
role_id | uuid | NOT NULL | PKFK | roles CASCADE |
permission_id | uuid | NOT NULL | PKFK | permissions CASCADE |
backend/src 出現 39 次 · 沒有表引用它
roles9 欄 · FK 出 0 / 入 4002_schema.sql:5013
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
description | text | |||
is_internal | boolean | NOT NULL | ||
is_system | boolean | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 238 次 · 被這些表引用:invitation_roles、notification_routing、role_permissions、user_roles
user_aup_profiles7 欄 · FK 出 1 / 入 0002_schema.sql:5975
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
user_id | uuid | NOT NULL | PKFK | users CASCADE |
training_records | jsonb | |||
research_experience | text | |||
animal_experience | text | |||
certifications | jsonb | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 1 次 · 沒有表引用它
user_mcp_keys10 欄 · FK 出 1 / 入 0002_schema.sql:5990
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
key_hash | text | NOT NULL | UK | |
key_prefix | varchar | NOT NULL | ||
name | text | NOT NULL | ||
last_used_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
revoked_at | timestamptz | |||
scopes | text[] | NOT NULL | ||
expires_at | timestamptz |
backend/src 出現 10 次 · 沒有表引用它
user_preferences6 欄 · FK 出 1 / 入 0002_schema.sql:6043
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
preference_key | varchar | NOT NULL | ||
preference_value | jsonb | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 17 次 · 沒有表引用它
user_roles4 欄 · FK 出 3 / 入 0002_schema.sql:6070
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
user_id | uuid | NOT NULL | PKFK | users CASCADE |
role_id | uuid | NOT NULL | PKFK | roles CASCADE |
assigned_at | timestamptz | |||
assigned_by | uuid | FK | users |
backend/src 出現 67 次 · 沒有表引用它
user_sessions13 欄 · FK 出 2 / 入 0002_schema.sql:6082
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
started_at | timestamptz | NOT NULL | ||
ended_at | timestamptz | |||
last_activity_at | timestamptz | NOT NULL | ||
refresh_token_id | uuid | FK | refresh_tokens SET NULL | |
ip_address | inet | |||
user_agent | text | |||
device_fingerprint | varchar | |||
page_view_count | integer | |||
action_count | integer | |||
is_active | boolean | |||
ended_reason | varchar |
backend/src 出現 20 次 · 沒有表引用它
users32 欄 · FK 出 1 / 入 190002_schema.sql:6103
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
email | varchar | NOT NULL | UK | |
password_hash | varchar | NOT NULL | ||
display_name | varchar | NOT NULL | ||
phone | varchar | |||
phone_ext | varchar | |||
organization | varchar | |||
is_internal | boolean | NOT NULL | ||
is_active | boolean | NOT NULL | ||
must_change_password | boolean | NOT NULL | ||
last_login_at | timestamptz | |||
login_attempts | integer | NOT NULL | ||
locked_until | timestamptz | |||
theme_preference | varchar | NOT NULL | ||
language_preference | varchar | NOT NULL | ||
entry_date | date | |||
position | varchar | |||
aup_roles | varchar[] | |||
years_experience | integer | NOT NULL | ||
trainings | jsonb | NOT NULL | ||
deleted_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
totp_enabled | boolean | NOT NULL | ||
totp_secret_encrypted | text | |||
totp_backup_codes | text[] | |||
version | integer | NOT NULL | ||
expires_at | timestamptz | |||
last_totp_step | bigint | |||
tokens_valid_after | timestamptz | |||
work_shift | varchar | NOT NULL | ||
department_id | uuid | FK | departments SET NULL |
backend/src 出現 431 次 · 被這些表引用:ai_api_keys、amendment_review_assignments、amendment_versions、amendments、animal_blood_test_items、animal_blood_tests、animal_field_correction_requests、animal_import_batches、animal_observations、animal_pathology_reports、animal_sacrifices、animal_sudden_deaths、animal_surgeries、animal_transfers、animal_vaccinations、animal_vet_advice_records、animal_vet_advices、animal_weights、animals、annual_leave_entitlements、ap_payments、application_notices、ar_receipts、attachments、attendance_records、audit_logs、calendar_sync_conflicts、calendar_sync_history、care_medication_records、change_reasons、change_requests、comp_time_balances、competency_assessments、controlled_documents、departments、document_acknowledgments、document_revisions、documents、electronic_signatures、environment_readings、equipment_disposals、equipment_idle_requests、equipment_maintenance_records、equipment_status_logs、euthanasia_appeals、euthanasia_byproduct_samples、euthanasia_orders、event_outbox、expiry_notification_config、export_jobs、formulation_records、import_jobs、invitations、ip_blocklist、journal_entries、leave_approvals、leave_requests、line_shelf_allocations、login_events、management_reviews、message_attachments、message_thread_participants、message_threads、messages、notification_settings、notifications、observation_vet_reads、overtime_approvals、overtime_records、password_reset_tokens、pdf_artifacts、personnel_affiliations、pi_account_invites、planned_experiments、products、protocol_activities、protocol_ai_reviews、protocol_attachments、protocol_notice_acknowledgements、protocol_pi_delegates、protocol_template_versions、protocol_versions、protocols、qa_audit_schedules、qa_capa、qa_inspections、qa_non_conformances、qa_schedule_items、qa_sop_acknowledgments、qa_sop_documents、record_annotations、record_versions、reference_standards、refresh_tokens、report_history、review_assignments、review_comments、review_round_history、risk_register、scheduled_reports、security_alerts、signature_bridge_sessions、study_final_reports、surgery_vet_reads、system_settings、training_records、transfer_vet_evaluations、treatment_drug_options、user_activity_aggregates、user_activity_logs、user_aup_profiles、user_mcp_keys、user_preferences、user_protocols、user_roles、user_sessions、vet_patrol_entry_photos、vet_patrol_photos、vet_patrol_reports、vet_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 | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
amendment_id | uuid | NOT NULL | FK | amendments CASCADE |
reviewer_id | uuid | FK | users | |
assigned_by | uuid | NOT NULL | FK | users |
assigned_at | timestamptz | NOT NULL | ||
decision | varchar | |||
decided_at | timestamptz | |||
comment | text | |||
reviewer_name | text |
backend/src 出現 13 次 · 沒有表引用它
amendment_status_history7 欄 · FK 出 1 / 入 0002_schema.sql:1635
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
amendment_id | uuid | NOT NULL | FK | amendments CASCADE |
from_status | amendment_status | |||
to_status | amendment_status | NOT NULL | ||
changed_by | uuid | NOT NULL | 無 FK | |
remark | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 5 次 · 沒有表引用它
amendment_versions6 欄 · FK 出 2 / 入 0002_schema.sql:1650
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
amendment_id | uuid | NOT NULL | FK | amendments CASCADE |
version_no | integer | NOT NULL | ||
content_snapshot | jsonb | NOT NULL | ||
submitted_at | timestamptz | NOT NULL | ||
submitted_by | uuid | NOT NULL | FK | users |
backend/src 出現 6 次 · 沒有表引用它
amendments25 欄 · FK 出 8 / 入 3002_schema.sql:1664
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FK | protocols CASCADE |
amendment_no | varchar | NOT NULL | ||
revision_number | integer | NOT NULL | ||
amendment_type | amendment_type | NOT NULL | ||
status | amendment_status | NOT NULL | ||
title | varchar | NOT NULL | ||
description | text | |||
change_items | varchar[] | |||
changes_content | jsonb | |||
submitted_by | uuid | FK | users | |
submitted_at | timestamptz | |||
classified_by | uuid | FK | users | |
classified_at | timestamptz | |||
classification_remark | text | |||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
approved_signature_id | uuid | FK | electronic_signatures RESTRICT | |
rejected_signature_id | uuid | FK | electronic_signatures RESTRICT | |
effective_from | timestamptz | |||
version | integer | NOT NULL | ||
is_historical | boolean | NOT NULL | ||
created_delegation_id | uuid | FK | protocol_pi_delegates | |
submitted_delegation_id | uuid | FK | protocol_pi_delegates |
backend/src 出現 90 次 · 被這些表引用:amendment_review_assignments、amendment_status_history、amendment_versions
application_notices9 欄 · FK 出 2 / 入 1002_schema.sql:2256
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
version_label | text | NOT NULL | UK | |
title | text | NOT NULL | ||
content | text | NOT NULL | ||
attachment_id | uuid | FK | attachments | |
effective_from | date | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL |
backend/src 出現 13 次 · 被這些表引用:protocol_notice_acknowledgements
planned_experiments8 欄 · FK 出 2 / 入 1002_schema.sql:4339
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
unit | text | NOT NULL | ||
description | text | |||
demand_count | integer | NOT NULL | ||
protocol_id | uuid | FK | protocols SET NULL | |
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 7 次 · 被這些表引用:animals
protocol_activities14 欄 · FK 出 2 / 入 0002_schema.sql:4441
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FK | protocols CASCADE |
activity_type | protocol_activity_type | NOT NULL | ||
actor_id | uuid | NOT NULL | FK | users |
actor_name | varchar | |||
actor_email | varchar | |||
from_value | text | |||
to_value | text | |||
target_entity_type | varchar | |||
target_entity_id | uuid | |||
target_entity_name | varchar | |||
remark | text | |||
extra_data | jsonb | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 23 次 · 沒有表引用它
protocol_ai_reviews15 欄 · FK 出 3 / 入 0002_schema.sql:4463
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FK | protocols CASCADE |
protocol_version_id | uuid | FK | protocol_versions | |
review_type | varchar | NOT NULL | ||
rule_result | jsonb | |||
ai_result | jsonb | |||
ai_model | varchar | |||
ai_input_tokens | integer | |||
ai_output_tokens | integer | |||
total_errors | integer | NOT NULL | ||
total_warnings | integer | NOT NULL | ||
score | integer | |||
triggered_by | uuid | FK | users | |
duration_ms | integer | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 10 次 · 沒有表引用它
protocol_attachments9 欄 · FK 出 3 / 入 0002_schema.sql:4487
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_version_id | uuid | FK | protocol_versions CASCADE | |
protocol_id | uuid | FK | protocols CASCADE | |
file_name | varchar | NOT NULL | ||
file_path | varchar | NOT NULL | ||
file_size | integer | NOT NULL | ||
mime_type | varchar | NOT NULL | ||
uploaded_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL |
backend/src 出現 1 次 · 沒有表引用它
protocol_notice_acknowledgements7 欄 · FK 出 5 / 入 0002_schema.sql:4504
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FKUK | protocols CASCADE |
notice_id | uuid | NOT NULL | FK | application_notices |
signer_id | uuid | NOT NULL | FK | users |
signature_id | uuid | FK | electronic_signatures | |
notice_attachment_id | uuid | FK | attachments | |
acknowledged_at | timestamptz | NOT NULL |
backend/src 出現 6 次 · 沒有表引用它
protocol_pi_delegates10 欄 · FK 出 4 / 入 4010_protocol_pi_delegates.sql:18
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FK | protocols CASCADE |
delegate_user_id | uuid | NOT NULL | FK | users |
authorized_by | uuid | NOT NULL | FK | users |
authorized_at | timestamptz | NOT NULL | ||
expires_at | timestamptz | |||
reason | text | |||
revoked_by | uuid | FK | users | |
revoked_at | timestamptz | |||
revoked_reason | text |
backend/src 出現 39 次 · 被這些表引用:amendments、electronic_signatures、euthanasia_appeals
protocol_template_versions8 欄 · FK 出 1 / 入 0002_schema.sql:4519
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
version_label | text | NOT NULL | UK | |
effective_date | date | |||
is_current | boolean | NOT NULL | ||
notes | text | |||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 14 次 · 沒有表引用它
protocol_versions6 欄 · FK 出 2 / 入 3002_schema.sql:4535
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FK | protocols CASCADE |
version_no | integer | NOT NULL | ||
content_snapshot | jsonb | NOT NULL | ||
submitted_at | timestamptz | NOT NULL | ||
submitted_by | uuid | NOT NULL | FK | users |
backend/src 出現 19 次 · 被這些表引用:protocol_ai_reviews、protocol_attachments、review_comments
protocols25 欄 · FK 出 5 / 入 19002_schema.sql:4549
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_no | varchar | NOT NULL | UK | |
iacuc_no | varchar | UK | ||
title | varchar | NOT NULL | ||
status | protocol_status | NOT NULL | ||
pi_user_id | uuid | NOT NULL | FK | users |
working_content | jsonb | |||
start_date | date | |||
end_date | date | |||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
submitted_at | date | |||
approved_at | date | |||
application_no | text | |||
import_pending | boolean | NOT NULL | ||
original_version_label | text | |||
study_director_user_id | uuid | FK | users | |
imported_at | timestamptz | |||
source_form_version | text | |||
is_glp | boolean | NOT NULL | ||
close_pi_signature_id | UUID | FK | electronic_signatures | |
close_sd_signature_id | UUID | FK | electronic_signatures | |
pi_is_external | boolean | NOT NULL |
backend/src 出現 309 次 · 被這些表引用:amendments、animals、documents、euthanasia_byproduct_samples、formulation_records、pi_account_invites、planned_experiments、protocol_activities、protocol_ai_reviews、protocol_attachments、protocol_notice_acknowledgements、protocol_pi_delegates、protocol_versions、review_assignments、review_comments、review_round_history、study_final_reports、user_protocols、vet_review_assignments
review_assignments10 欄 · FK 出 3 / 入 0002_schema.sql:4889
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FK | protocols CASCADE |
reviewer_id | uuid | NOT NULL | FK | users |
assigned_by | uuid | NOT NULL | FK | users |
assigned_at | timestamptz | NOT NULL | ||
completed_at | timestamptz | |||
is_primary_reviewer | boolean | NOT NULL | ||
review_stage | varchar | |||
decision | varchar | |||
decided_at | timestamptz |
backend/src 出現 19 次 · 沒有表引用它
review_comments19 欄 · FK 出 7 / 入 1002_schema.sql:4907
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_version_id | uuid | FK | protocol_versions CASCADE | |
protocol_id | uuid | FK | protocols | |
reviewer_id | uuid | FK | users | |
content | text | NOT NULL | ||
is_resolved | boolean | NOT NULL | ||
resolved_by | uuid | FK | users | |
resolved_at | timestamptz | |||
review_stage | varchar | |||
parent_comment_id | uuid | FK | review_comments CASCADE | |
replied_by | uuid | FK | users | |
draft_content | text | |||
drafted_by | uuid | FK | users | |
draft_updated_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
reviewer_name | text | |||
section_no | varchar | |||
comment_type | varchar | NOT NULL |
backend/src 出現 41 次 · 被這些表引用:review_comments
review_round_history8 欄 · FK 出 2 / 入 0002_schema.sql:4943
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FK | protocols CASCADE |
review_stage | varchar | NOT NULL | ||
round_number | integer | NOT NULL | ||
action | varchar | NOT NULL | ||
actor_id | uuid | NOT NULL | FK | users |
remark | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 1 次 · 沒有表引用它
study_final_reports18 欄 · FK 出 4 / 入 0002_schema.sql:5306
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
report_number | varchar | NOT NULL | UK | |
protocol_id | uuid | NOT NULL | FK | protocols |
title | varchar | NOT NULL | ||
status | varchar | NOT NULL | ||
summary | text | |||
methods | text | |||
results | text | |||
conclusions | text | |||
deviations | text | |||
signed_by | uuid | FK | users | |
signed_at | timestamptz | |||
signature_id | uuid | FK | electronic_signatures | |
qau_statement | text | |||
qau_signed_by | uuid | FK | users | |
qau_signed_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 12 次 · 沒有表引用它
user_protocols5 欄 · FK 出 3 / 入 0002_schema.sql:6057
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
user_id | uuid | NOT NULL | PKFK | users CASCADE |
protocol_id | uuid | NOT NULL | PKFK | protocols CASCADE |
role_in_protocol | protocol_role | NOT NULL | ||
granted_at | timestamptz | NOT NULL | ||
granted_by | uuid | FK | users |
backend/src 出現 54 次 · 沒有表引用它
vet_review_assignments10 欄 · FK 出 3 / 入 0002_schema.sql:6438
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
protocol_id | uuid | NOT NULL | FKUK | protocols CASCADE |
vet_id | uuid | FK | users | |
assigned_by | uuid | FK | users | |
assigned_at | timestamptz | NOT NULL | ||
completed_at | timestamptz | |||
decision | varchar | |||
decision_remark | text | |||
review_form | jsonb | |||
vet_name | text |
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 | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
blood_test_id | uuid | NOT NULL | FK | animal_blood_tests CASCADE |
template_id | uuid | FK | blood_test_templates | |
item_name | varchar | NOT NULL | ||
result_value | varchar | |||
result_unit | varchar | |||
reference_range | varchar | |||
is_abnormal | boolean | NOT NULL | ||
remark | text | |||
sort_order | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
superseded_by_id | uuid | FK | animal_blood_test_items | |
superseded_at | timestamptz | |||
corrected_by | uuid | FK | users | |
correction_reason | text |
backend/src 出現 15 次 · 被這些表引用:animal_blood_test_items
animal_blood_tests17 欄 · FK 出 4 / 入 1002_schema.sql:1775
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FK | animals CASCADE |
test_date | date | NOT NULL | ||
lab_name | varchar | |||
status | varchar | NOT NULL | ||
remark | text | |||
vet_read | boolean | NOT NULL | ||
vet_read_at | timestamptz | |||
deleted_at | timestamptz | |||
deleted_by | uuid | FK | users | |
delete_reason | text | |||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
is_locked | boolean | NOT NULL | ||
locked_at | timestamptz | |||
locked_by | uuid | FK | users |
backend/src 出現 21 次 · 被這些表引用:animal_blood_test_items
animal_field_correction_requests12 欄 · FK 出 3 / 入 0002_schema.sql:1815
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FK | animals CASCADE |
field_name | varchar | NOT NULL | ||
old_value | text | |||
new_value | text | NOT NULL | ||
reason | text | NOT NULL | ||
status | varchar | NOT NULL | ||
requested_by | uuid | NOT NULL | FK | users |
reviewed_by | uuid | FK | users | |
reviewed_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 7 次 · 沒有表引用它
animal_import_batches11 欄 · FK 出 1 / 入 0002_schema.sql:1858
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
import_type | import_type | NOT NULL | ||
file_name | varchar | NOT NULL | ||
total_rows | integer | NOT NULL | ||
success_count | integer | NOT NULL | ||
error_count | integer | NOT NULL | ||
status | import_status | NOT NULL | ||
error_details | jsonb | |||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
completed_at | timestamptz |
backend/src 出現 5 次 · 沒有表引用它
animal_observations29 欄 · FK 出 5 / 入 0002_schema.sql:1877
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FK | animals CASCADE |
event_date | date | NOT NULL | ||
record_type | record_type | NOT NULL | ||
equipment_used | jsonb | |||
anesthesia_start | timestamptz | |||
anesthesia_end | timestamptz | |||
content | text | NOT NULL | ||
no_medication_needed | boolean | NOT NULL | ||
stop_medication | boolean | NOT NULL | ||
treatments | jsonb | |||
remark | text | |||
vet_read | boolean | NOT NULL | ||
vet_read_at | timestamptz | |||
deleted_at | timestamptz | |||
deletion_reason | text | |||
deleted_by | uuid | FK | users | |
is_emergency | boolean | |||
emergency_status | varchar | |||
emergency_reason | text | |||
reviewed_by | uuid | FK | users | |
reviewed_at | timestamptz | |||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
is_locked | boolean | NOT NULL | ||
locked_at | timestamptz | |||
locked_by | uuid | FK | users |
backend/src 出現 36 次 · 沒有表引用它
animal_pathology_reports5 欄 · FK 出 2 / 入 0002_schema.sql:1921
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FKUK | animals CASCADE |
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 3 次 · 沒有表引用它
animal_record_attachments9 欄 · FK 出 0 / 入 0002_schema.sql:1934
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
record_type | animal_record_type | NOT NULL | ||
record_id | uuid | NOT NULL | ||
file_type | animal_file_type | NOT NULL | ||
file_name | varchar | NOT NULL | ||
file_path | varchar | NOT NULL | ||
file_size | integer | NOT NULL | ||
mime_type | varchar | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 3 次 · 沒有表引用它
animal_sacrifices17 欄 · FK 出 3 / 入 0002_schema.sql:1951
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FKUK | animals CASCADE |
sacrifice_date | date | |||
zoletil_dose | varchar | |||
method_electrocution | boolean | NOT NULL | ||
method_bloodletting | boolean | NOT NULL | ||
method_other | text | |||
sampling | text | |||
sampling_other | text | |||
blood_volume_ml | numeric | |||
confirmed_sacrifice | boolean | NOT NULL | ||
is_locked | boolean | NOT NULL | ||
locked_at | timestamptz | |||
locked_by | uuid | FK | users | |
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 17 次 · 沒有表引用它
animal_sources11 欄 · FK 出 0 / 入 1002_schema.sql:1976
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
address | text | |||
contact | varchar | |||
phone | varchar | |||
phone_ext | varchar | |||
is_active | boolean | NOT NULL | ||
sort_order | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 16 次 · 被這些表引用:animals
animal_sudden_deaths10 欄 · FK 出 2 / 入 0002_schema.sql:1995
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FKUK | animals |
discovered_at | timestamptz | NOT NULL | ||
discovered_by | uuid | NOT NULL | FK | users |
probable_cause | text | |||
iacuc_no | varchar | 無 FK | ||
location | varchar | |||
remark | text | |||
requires_pathology | boolean | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 4 次 · 沒有表引用它
animal_surgeries28 欄 · FK 出 4 / 入 0002_schema.sql:2013
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FK | animals CASCADE |
is_first_experiment | boolean | NOT NULL | ||
surgery_date | date | NOT NULL | ||
surgery_site | varchar | NOT NULL | ||
induction_anesthesia | jsonb | |||
pre_surgery_medication | jsonb | |||
positioning | varchar | |||
anesthesia_maintenance | jsonb | |||
anesthesia_observation | text | |||
vital_signs | jsonb | |||
reflex_recovery | text | |||
respiration_rate | integer | |||
post_surgery_medication | jsonb | |||
remark | text | |||
no_medication_needed | boolean | NOT NULL | ||
vet_read | boolean | NOT NULL | ||
vet_read_at | timestamptz | |||
deleted_at | timestamptz | |||
deletion_reason | text | |||
deleted_by | uuid | FK | users | |
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
is_locked | boolean | NOT NULL | ||
locked_at | timestamptz | |||
locked_by | uuid | FK | users |
backend/src 出現 31 次 · 沒有表引用它
animal_transfers14 欄 · FK 出 3 / 入 1002_schema.sql:2056
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FK | animals |
from_iacuc_no | varchar | NOT NULL | ||
to_iacuc_no | varchar | |||
status | animal_transfer_status | NOT NULL | ||
initiated_by | uuid | NOT NULL | FK | users |
reason | text | NOT NULL | ||
remark | text | |||
rejected_by | uuid | FK | users | |
rejected_reason | text | |||
completed_at | timestamptz | |||
transfer_type | varchar | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 31 次 · 被這些表引用:transfer_vet_evaluations
animal_vaccinations10 欄 · FK 出 3 / 入 0002_schema.sql:2085
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FK | animals CASCADE |
administered_date | date | NOT NULL | ||
vaccine | varchar | |||
deworming_dose | varchar | |||
deleted_at | timestamptz | |||
deletion_reason | text | |||
deleted_by | uuid | FK | users | |
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL |
backend/src 出現 11 次 · 沒有表引用它
animal_vet_advice_records12 欄 · FK 出 4 / 入 0002_schema.sql:2103
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FK | animals |
advice_date | date | NOT NULL | ||
observation | text | NOT NULL | ||
suggested_treatment | text | NOT NULL | ||
created_by | uuid | FK | users | |
updated_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
deleted_at | timestamptz | |||
follow_up | text | NOT NULL | ||
source_vet_patrol_entry_id | uuid | FK | vet_patrol_entries CASCADE |
backend/src 出現 12 次 · 沒有表引用它
animal_vet_advices7 欄 · FK 出 3 / 入 0002_schema.sql:2123
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FKUK | animals |
sections | jsonb | NOT NULL | ||
created_by | uuid | FK | users | |
updated_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 7 次 · 沒有表引用它
animal_weights9 欄 · FK 出 3 / 入 0002_schema.sql:2138
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FK | animals CASCADE |
measure_date | date | NOT NULL | ||
weight | numeric | NOT NULL | ||
deleted_at | timestamptz | |||
deletion_reason | text | |||
deleted_by | uuid | FK | users | |
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL |
backend/src 出現 23 次 · 沒有表引用它
animals38 欄 · FK 出 8 / 入 16002_schema.sql:2155
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
ear_tag | varchar | NOT NULL | ||
status | animal_status | NOT NULL | ||
breed | animal_breed | NOT NULL | ||
source_id | uuid | FK | animal_sources | |
gender | animal_gender | NOT NULL | ||
birth_date | date | |||
entry_date | date | NOT NULL | ||
entry_weight | numeric | |||
pen_location | varchar | |||
pre_experiment_code | varchar | |||
iacuc_no | varchar | 無 FK | ||
experiment_date | date | |||
remark | text | |||
deleted_at | timestamptz | |||
deleted_by | uuid | FK | users | |
animal_no | varchar | |||
deletion_reason | text | |||
animal_id | uuid | 無 FK | ||
breed_other | varchar | |||
experiment_assigned_by | uuid | FK | users | |
lab_animal_id | varchar | |||
glp_study_no | varchar | |||
randomization_group | varchar | |||
dosing_group | varchar | |||
quarantine_end_date | date | |||
vet_weight_viewed_at | timestamptz | |||
vet_vaccine_viewed_at | timestamptz | |||
vet_sacrifice_viewed_at | timestamptz | |||
vet_last_viewed_at | timestamptz | |||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
pen_id | uuid | FK | pens | |
species_id | uuid | FK | species | |
reserved_protocol_id | uuid | FK | protocols SET NULL | |
reserved_planned_experiment_id | uuid | FK | planned_experiments SET NULL |
backend/src 出現 341 次 · 被這些表引用:animal_blood_tests、animal_field_correction_requests、animal_observations、animal_pathology_reports、animal_sacrifices、animal_sudden_deaths、animal_surgeries、animal_transfers、animal_vaccinations、animal_vet_advice_records、animal_vet_advices、animal_weights、euthanasia_byproduct_samples、euthanasia_orders、vet_patrol_entries、vet_patrol_entry_animals
blood_test_panel_items3 欄 · FK 出 2 / 入 0002_schema.sql:2391
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
panel_id | uuid | NOT NULL | PKFK | blood_test_panels CASCADE |
template_id | uuid | NOT NULL | PKFK | blood_test_templates CASCADE |
sort_order | integer | NOT NULL |
backend/src 出現 13 次 · 沒有表引用它
blood_test_panels8 欄 · FK 出 0 / 入 1002_schema.sql:2402
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
key | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
icon | varchar | |||
sort_order | integer | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 10 次 · 被這些表引用:blood_test_panel_items
blood_test_presets8 欄 · FK 出 0 / 入 0002_schema.sql:2418
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
name | varchar | NOT NULL | ||
icon | varchar | |||
panel_keys | text[] | NOT NULL | ||
sort_order | integer | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 沒有表引用它
blood_test_templates10 欄 · FK 出 0 / 入 2002_schema.sql:2434
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
default_unit | varchar | |||
reference_range | varchar | |||
default_price | numeric | |||
sort_order | integer | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 15 次 · 被這些表引用:animal_blood_test_items、blood_test_panel_items
care_medication_records24 欄 · FK 出 2 / 入 0002_schema.sql:2541
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
record_type | vet_record_type | NOT NULL | ||
record_id | uuid | NOT NULL | ||
record_mode | care_record_mode | NOT NULL | ||
post_op_days | integer | |||
time_period | varchar | |||
vet_read | boolean | NOT NULL | ||
deleted_at | timestamptz | |||
deletion_reason | text | |||
deleted_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
incision | smallint | |||
attitude_behavior | smallint | |||
appetite | smallint | |||
feces | smallint | |||
urine | smallint | |||
pain_score | smallint | |||
injection_ketorolac | boolean | NOT NULL | ||
injection_meloxicam | boolean | NOT NULL | ||
oral_meloxicam | boolean | NOT NULL | ||
post_medications | jsonb | |||
is_locked | boolean | NOT NULL | ||
locked_at | timestamptz | |||
locked_by | uuid | FK | users |
backend/src 出現 15 次 · 沒有表引用它
euthanasia_appeals12 欄 · FK 出 4 / 入 0002_schema.sql:3236
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
order_id | uuid | NOT NULL | FK | euthanasia_orders CASCADE |
pi_user_id | uuid | NOT NULL | FK | users |
reason | text | NOT NULL | ||
attachment_path | varchar | |||
chair_user_id | uuid | FK | users | |
chair_decision | varchar | |||
chair_decided_at | timestamptz | |||
chair_deadline_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
delegation_id | uuid | FK | protocol_pi_delegates |
backend/src 出現 9 次 · 沒有表引用它
euthanasia_byproduct_samples18 欄 · FK 出 6 / 入 0002_schema.sql:3262
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
euthanasia_id | uuid | FK | euthanasia_orders RESTRICT | |
animal_id | uuid | NOT NULL | FK | animals RESTRICT |
source_protocol_id | uuid | NOT NULL | FK | protocols RESTRICT |
sampled_at | timestamptz | NOT NULL | ||
sample_content | text | NOT NULL | ||
requester_user_id | uuid | FK | users RESTRICT | |
collector_id | uuid | NOT NULL | FK | users RESTRICT |
notes | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
created_by | uuid | NOT NULL | FK | users RESTRICT |
deleted_at | timestamptz | |||
requester_org_name | text | |||
requester_contact_name | text | |||
special_equipment_used | text | |||
work_started_at | timestamptz | |||
work_ended_at | timestamptz |
backend/src 出現 11 次 · 沒有表引用它
euthanasia_orders13 欄 · FK 出 4 / 入 2002_schema.sql:3346
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
animal_id | uuid | NOT NULL | FK | animals CASCADE |
vet_user_id | uuid | NOT NULL | FK | users |
pi_user_id | uuid | NOT NULL | FK | users |
status | euthanasia_order_status | NOT NULL | ||
reason | text | NOT NULL | ||
deadline_at | timestamptz | NOT NULL | ||
pi_responded_at | timestamptz | |||
executed_at | timestamptz | |||
executed_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL |
backend/src 出現 29 次 · 被這些表引用:euthanasia_appeals、euthanasia_byproduct_samples
formulation_records13 欄 · FK 出 4 / 入 0002_schema.sql:3555
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
product_id | uuid | NOT NULL | FK | products |
protocol_id | uuid | FK | protocols | |
formulation_date | date | NOT NULL | ||
batch_number | varchar | |||
concentration | varchar | |||
volume | varchar | |||
prepared_by | uuid | NOT NULL | FK | users |
verified_by | uuid | FK | users | |
verified_at | timestamptz | |||
expiry_date | date | |||
notes | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 3 次 · 沒有表引用它
observation_vet_reads3 欄 · FK 出 1 / 入 0002_schema.sql:4070
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
observation_id | uuid | NOT NULL | PK無 FK | |
vet_user_id | uuid | NOT NULL | PKFK | users |
read_at | timestamptz | NOT NULL |
backend/src 出現 2 次 · 沒有表引用它
species11 欄 · FK 出 1 / 入 2002_schema.sql:5223
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
name_en | varchar | |||
icon | varchar | |||
is_active | boolean | NOT NULL | ||
config | jsonb | |||
sort_order | integer | NOT NULL | ||
parent_id | uuid | FK | species | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
surgery_vet_reads3 欄 · FK 出 1 / 入 0002_schema.sql:5332
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
surgery_id | uuid | NOT NULL | PK無 FK | |
vet_user_id | uuid | NOT NULL | PKFK | users |
read_at | timestamptz | NOT NULL |
backend/src 出現 2 次 · 沒有表引用它
transfer_vet_evaluations7 欄 · FK 出 2 / 入 0002_schema.sql:5372
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
transfer_id | uuid | NOT NULL | FKUK | animal_transfers |
vet_id | uuid | NOT NULL | FK | users |
health_status | text | NOT NULL | ||
is_fit_for_transfer | boolean | NOT NULL | ||
conditions | text | |||
evaluated_at | timestamptz | NOT NULL |
backend/src 出現 3 次 · 沒有表引用它
treatment_drug_options13 欄 · FK 出 2 / 入 0002_schema.sql:5387
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
name | varchar | NOT NULL | ||
display_name | varchar | |||
default_dosage_unit | varchar | |||
available_units | text[] | |||
default_dosage_value | varchar | |||
erp_product_id | uuid | FK | products | |
category | varchar | |||
sort_order | integer | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 17 次 · 沒有表引用它
vet_patrol_entries9 欄 · FK 出 2 / 入 3002_schema.sql:6350
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
report_id | uuid | NOT NULL | FK | vet_patrol_reports CASCADE |
category | varchar | NOT NULL | ||
animal_id | uuid | FK | animals | |
observation | text | NOT NULL | ||
suggestion | text | NOT NULL | ||
follow_up | text | NOT NULL | ||
sort_order | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 26 次 · 被這些表引用:animal_vet_advice_records、vet_patrol_entry_animals、vet_patrol_entry_photos
vet_patrol_entry_animals2 欄 · FK 出 2 / 入 0002_schema.sql:6367
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
entry_id | uuid | NOT NULL | PKFK | vet_patrol_entries CASCADE |
animal_id | uuid | NOT NULL | PKFK | animals CASCADE |
backend/src 出現 6 次 · 沒有表引用它
vet_patrol_entry_photos10 欄 · FK 出 2 / 入 0002_schema.sql:6377
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
entry_id | uuid | NOT NULL | FK | vet_patrol_entries CASCADE |
file_name | varchar | NOT NULL | ||
file_path | text | NOT NULL | ||
file_size | bigint | NOT NULL | ||
mime_type | varchar | NOT NULL | ||
caption | text | NOT NULL | ||
sort_order | integer | NOT NULL | ||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL |
backend/src 出現 15 次 · 沒有表引用它
vet_patrol_photos10 欄 · FK 出 2 / 入 0002_schema.sql:6395
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
report_id | uuid | NOT NULL | FK | vet_patrol_reports CASCADE |
file_name | varchar | NOT NULL | ||
file_path | text | NOT NULL | ||
file_size | bigint | NOT NULL | ||
mime_type | varchar | NOT NULL | ||
caption | text | NOT NULL | ||
sort_order | integer | NOT NULL | ||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL |
backend/src 出現 11 次 · 沒有表引用它
vet_patrol_reports16 欄 · FK 出 4 / 入 2002_schema.sql:6413
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
patrol_date | date | NOT NULL | ||
week_start | date | |||
week_end | date | |||
status | varchar | NOT NULL | ||
created_by | uuid | FK | users | |
updated_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
deleted_at | timestamptz | |||
accompanying_personnel | text | |||
submitted_at | timestamptz | |||
follow_up_user_id | uuid | FK | users | |
follow_up_submitted_at | timestamptz | |||
acknowledged_at | timestamptz | |||
acknowledged_by_id | uuid | FK | users |
backend/src 出現 69 次 · 被這些表引用:vet_patrol_entries、vet_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 | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
facility_id | uuid | NOT NULL | FK | facilities |
code | varchar | NOT NULL | ||
name | varchar | NOT NULL | ||
description | text | |||
is_active | boolean | NOT NULL | ||
config | jsonb | |||
sort_order | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 32 次 · 被這些表引用:environment_monitoring_points、zones
environment_monitoring_points10 欄 · FK 出 2 / 入 1002_schema.sql:3009
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
name | varchar | NOT NULL | ||
location_type | varchar | NOT NULL | ||
building_id | uuid | FK | buildings | |
zone_id | uuid | FK | zones | |
parameters | jsonb | NOT NULL | ||
monitoring_interval | varchar | |||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 被這些表引用:environment_readings
environment_readings10 欄 · FK 出 2 / 入 0002_schema.sql:3027
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
monitoring_point_id | uuid | NOT NULL | FK | environment_monitoring_points CASCADE |
reading_time | timestamptz | NOT NULL | ||
readings | jsonb | NOT NULL | ||
is_out_of_range | boolean | NOT NULL | ||
out_of_range_params | jsonb | |||
recorded_by | uuid | FK | users | |
source | varchar | NOT NULL | ||
notes | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 3 次 · 沒有表引用它
facilities10 欄 · FK 出 0 / 入 1002_schema.sql:3537
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | ||
name | varchar | NOT NULL | ||
address | text | |||
phone | varchar | |||
contact_person | varchar | |||
is_active | boolean | NOT NULL | ||
config | jsonb | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 82 次 · 被這些表引用:buildings
pens12 欄 · FK 出 1 / 入 1002_schema.sql:4286
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
zone_id | uuid | NOT NULL | FK | zones |
code | varchar | NOT NULL | ||
name | varchar | |||
capacity | integer | NOT NULL | ||
current_count | integer | NOT NULL | ||
status | varchar | NOT NULL | ||
row_index | integer | |||
col_index | integer | |||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 56 次 · 被這些表引用:animals
zones10 欄 · FK 出 1 / 入 2002_schema.sql:6457
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
building_id | uuid | NOT NULL | FK | buildings |
code | varchar | NOT NULL | ||
name | varchar | |||
color | varchar | |||
is_active | boolean | NOT NULL | ||
layout_config | jsonb | |||
sort_order | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 29 次 · 被這些表引用:environment_monitoring_points、pens
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 | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
document_id | uuid | NOT NULL | FK | documents CASCADE |
line_no | integer | NOT NULL | ||
product_id | uuid | NOT NULL | FK | products |
qty | numeric | NOT NULL | ||
uom | varchar | NOT NULL | ||
unit_price | numeric | |||
batch_no | varchar | |||
expiry_date | date | |||
remark | text | |||
storage_location_id | uuid | FK | storage_locations | |
storage_location_from_id | uuid | FK | storage_locations | |
storage_location_to_id | uuid | FK | storage_locations | |
warehouse_id | uuid | FK | warehouses |
backend/src 出現 46 次 · 被這些表引用:line_shelf_allocations、stock_ledger
documents28 欄 · FK 出 10 / 入 4002_schema.sql:2915
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
doc_type | doc_type | NOT NULL | ||
doc_no | varchar | NOT NULL | UK | |
status | doc_status | NOT NULL | ||
warehouse_id | uuid | FK | warehouses | |
warehouse_from_id | uuid | FK | warehouses | |
warehouse_to_id | uuid | FK | warehouses | |
partner_id | uuid | FK | partners | |
source_doc_id | uuid | FK | documents | |
doc_date | date | NOT NULL | ||
receipt_status | varchar | |||
stocktake_scope | jsonb | |||
remark | text | |||
iacuc_no | varchar | 無 FK | ||
requires_manager_approval | boolean | |||
scrap_total_amount | numeric | |||
manager_approval_status | varchar | |||
manager_approved_by | uuid | FK | users | |
manager_approved_at | timestamptz | |||
manager_reject_reason | text | |||
created_by | uuid | NOT NULL | FK | users |
approved_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
approved_at | timestamptz | |||
protocol_id | uuid | FK | protocols SET NULL | |
reverses_doc_id | uuid | FK | documents | |
system_generated | boolean | NOT NULL |
backend/src 出現 129 次 · 被這些表引用:document_lines、documents、stock_ledger
expiry_monthly_snapshots12 欄 · FK 出 2 / 入 0002_schema.sql:3432
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
snapshot_ym | char | NOT NULL | ||
product_id | uuid | NOT NULL | FK | products |
sku | varchar | NOT NULL | ||
product_name | varchar | NOT NULL | ||
warehouse_id | uuid | NOT NULL | FK | warehouses |
batch_no | varchar | |||
expiry_date | date | NOT NULL | ||
days_past | smallint | NOT NULL | ||
on_hand_qty | numeric | NOT NULL | ||
base_uom | varchar | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 3 次 · 沒有表引用它
expiry_notification_config6 欄 · FK 出 1 / 入 0002_schema.sql:3473
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
warn_days | smallint | NOT NULL | ||
cutoff_days | smallint | NOT NULL | ||
monthly_threshold_days | smallint | |||
updated_at | timestamptz | NOT NULL | ||
updated_by | uuid | FK | users |
backend/src 出現 3 次 · 沒有表引用它
inventory_snapshots5 欄 · FK 出 2 / 入 0002_schema.sql:3631
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
warehouse_id | uuid | NOT NULL | PKFK | warehouses |
product_id | uuid | NOT NULL | PKFK | products |
on_hand_qty_base | numeric | NOT NULL | ||
avg_cost | numeric | |||
updated_at | timestamptz | NOT NULL |
backend/src 出現 7 次 · 沒有表引用它
line_shelf_allocations9 欄 · FK 出 4 / 入 0002_schema.sql:3833
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
document_line_id | uuid | FK | document_lines SET NULL | |
storage_location_id | uuid | NOT NULL | FK | storage_locations |
product_id | uuid | NOT NULL | FK | products |
batch_no | varchar | |||
expiry_date | date | |||
qty | numeric | NOT NULL | ||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL |
backend/src 出現 6 次 · 沒有表引用它
mig011_conversion_backup4 欄 · FK 出 0 / 入 0011_uom_conversions_from_pack.sql:93
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
product_id | uuid | NOT NULL | ||
uom | varchar | NOT NULL | ||
factor_to_base | numeric | NOT NULL |
backend/src 出現 1 次 · 沒有表引用它
mig011_inserted_conversion1 欄 · FK 出 0 / 入 0011_uom_conversions_from_pack.sql:105
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK |
backend/src 出現 1 次 · 沒有表引用它
mig011_pack_unit_backup2 欄 · FK 出 0 / 入 0011_uom_conversions_from_pack.sql:100
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
product_id | uuid | NOT NULL | PK | |
pack_unit | varchar | NOT NULL |
backend/src 出現 1 次 · 沒有表引用它
partners15 欄 · FK 出 0 / 入 6002_schema.sql:4187
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
partner_type | partner_type | NOT NULL | ||
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
supplier_category | supplier_category | |||
customer_category | customer_category | |||
tax_id | varchar | |||
phone | varchar | |||
phone_ext | varchar | |||
email | varchar | |||
address | text | |||
payment_terms | varchar | |||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 60 次 · 被這些表引用:ap_payments、ar_receipts、documents、equipment_calibrations、equipment_maintenance_records、equipment_suppliers
product_categories6 欄 · FK 出 1 / 入 2002_schema.sql:4356
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
parent_id | uuid | FK | product_categories | |
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 被這些表引用:product_categories、products
product_uom_conversions5 欄 · FK 出 2 / 入 0002_schema.sql:4370
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
product_id | uuid | NOT NULL | FK | products CASCADE |
uom | varchar | NOT NULL | ||
factor_to_base | numeric | NOT NULL | ||
base_uom | varchar | NOT NULL | FK | products CASCADE |
backend/src 出現 31 次 · 沒有表引用它
products36 欄 · FK 出 2 / 入 10002_schema.sql:4382
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
sku | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
spec | text | |||
category_id | uuid | FK | product_categories | |
category_code | char | |||
subcategory_code | char | |||
base_uom | varchar | NOT NULL | ||
pack_unit | varchar | |||
pack_qty | integer | |||
track_batch | boolean | NOT NULL | ||
track_expiry | boolean | NOT NULL | ||
default_expiry_days | integer | |||
safety_stock | numeric | |||
safety_stock_uom | varchar | |||
reorder_point | numeric | |||
reorder_point_uom | varchar | |||
image_url | varchar | |||
license_no | varchar | |||
storage_condition | varchar | |||
barcode | varchar | |||
tags | text[] | |||
status | varchar | NOT NULL | ||
remark | text | |||
is_active | boolean | NOT NULL | ||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
glp_characterization | text | |||
stability_data | jsonb | |||
storage_conditions | varchar | |||
cas_number | varchar | |||
is_test_article | boolean | NOT NULL | ||
is_control_article | boolean | NOT NULL | ||
cost_price | numeric | |||
selling_price | numeric |
backend/src 出現 115 次 · 被這些表引用:document_lines、expiry_monthly_snapshots、formulation_records、inventory_snapshots、line_shelf_allocations、product_uom_conversions、stock_ledger、storage_location_inventory、treatment_drug_options
sku_categories5 欄 · FK 出 0 / 入 1002_schema.sql:5147
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
code | char | NOT NULL | PK | |
name | varchar | NOT NULL | ||
sort_order | integer | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 14 次 · 被這些表引用:sku_subcategories
sku_sequences3 欄 · FK 出 0 / 入 0002_schema.sql:5160
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
category_code | char | NOT NULL | PK | |
subcategory_code | char | NOT NULL | PK | |
last_sequence | integer | NOT NULL |
backend/src 出現 5 次 · 沒有表引用它
sku_subcategories7 欄 · FK 出 1 / 入 0002_schema.sql:5171
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | integer | NOT NULL | PK | |
category_code | char | NOT NULL | FK | sku_categories CASCADE |
code | char | NOT NULL | ||
name | varchar | NOT NULL | ||
sort_order | integer | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 14 次 · 沒有表引用它
stock_ledger15 欄 · FK 出 5 / 入 0002_schema.sql:5242
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
warehouse_id | uuid | NOT NULL | FK | warehouses |
product_id | uuid | NOT NULL | FK | products |
trx_date | timestamptz | NOT NULL | ||
doc_type | doc_type | NOT NULL | ||
doc_id | uuid | NOT NULL | FK | documents |
doc_no | varchar | NOT NULL | ||
line_id | uuid | FK | document_lines | |
direction | stock_direction | NOT NULL | ||
qty_base | numeric | NOT NULL | ||
unit_cost | numeric | |||
batch_no | varchar | |||
expiry_date | date | |||
created_at | timestamptz | NOT NULL | ||
storage_location_id | uuid | FK | storage_locations |
backend/src 出現 55 次 · 沒有表引用它
storage_location_inventory7 欄 · FK 出 2 / 入 0002_schema.sql:5265
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
storage_location_id | uuid | NOT NULL | FK | storage_locations CASCADE |
product_id | uuid | NOT NULL | FK | products CASCADE |
on_hand_qty | numeric | NOT NULL | ||
batch_no | varchar | |||
expiry_date | date | |||
updated_at | timestamptz | NOT NULL |
backend/src 出現 58 次 · 沒有表引用它
storage_locations17 欄 · FK 出 1 / 入 6002_schema.sql:5281
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
warehouse_id | uuid | NOT NULL | FK | warehouses CASCADE |
code | varchar | NOT NULL | ||
name | varchar | |||
location_type | varchar | NOT NULL | ||
row_index | integer | NOT NULL | ||
col_index | integer | NOT NULL | ||
width | integer | NOT NULL | ||
height | integer | NOT NULL | ||
capacity | integer | |||
current_count | integer | |||
color | varchar | |||
zone | varchar | |||
is_active | boolean | NOT NULL | ||
config | jsonb | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 42 次 · 被這些表引用:document_lines、line_shelf_allocations、stock_ledger、storage_location_inventory
warehouses10 欄 · FK 出 0 / 入 8002_schema.sql:6188
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
address | text | |||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
exclude_from_alerts | boolean | NOT NULL | ||
skip_routine_stocktake | boolean | NOT NULL | ||
is_default_issue_source | boolean | NOT NULL |
backend/src 出現 67 次 · 被這些表引用:document_lines、documents、expiry_monthly_snapshots、inventory_snapshots、stock_ledger、storage_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 | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
payment_no | varchar | NOT NULL | UK | |
partner_id | uuid | NOT NULL | FK | partners |
payment_date | date | NOT NULL | ||
amount | numeric | NOT NULL | ||
reference | text | |||
journal_entry_id | uuid | FK | journal_entries | |
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL |
backend/src 出現 3 次 · 沒有表引用它
ar_receipts9 欄 · FK 出 3 / 入 0002_schema.sql:2285
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
receipt_no | varchar | NOT NULL | UK | |
partner_id | uuid | NOT NULL | FK | partners |
receipt_date | date | NOT NULL | ||
amount | numeric | NOT NULL | ||
reference | text | |||
journal_entry_id | uuid | FK | journal_entries | |
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL |
backend/src 出現 3 次 · 沒有表引用它
chart_of_accounts8 欄 · FK 出 1 / 入 2002_schema.sql:2708
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | varchar | NOT NULL | UK | |
name | varchar | NOT NULL | ||
account_type | account_type | NOT NULL | ||
parent_id | uuid | FK | chart_of_accounts | |
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 12 次 · 被這些表引用:chart_of_accounts、journal_entry_lines
journal_entries8 欄 · FK 出 1 / 入 3002_schema.sql:3709
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
entry_no | varchar | NOT NULL | UK | |
entry_date | date | NOT NULL | ||
description | text | |||
source_entity_type | varchar | |||
source_entity_id | uuid | |||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL |
backend/src 出現 12 次 · 被這些表引用:ap_payments、ar_receipts、journal_entry_lines
journal_entry_lines7 欄 · FK 出 2 / 入 0002_schema.sql:3725
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
journal_entry_id | uuid | NOT NULL | FK | journal_entries CASCADE |
line_no | integer | NOT NULL | ||
account_id | uuid | NOT NULL | FK | chart_of_accounts |
debit_amount | numeric | NOT NULL | ||
credit_amount | numeric | NOT NULL | ||
description | text |
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 | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
entitlement_year | integer | NOT NULL | ||
entitled_days | numeric | NOT NULL | ||
used_days | numeric | |||
expires_at | date | NOT NULL | ||
calculation_basis | varchar | |||
seniority_years | numeric | |||
is_expired | boolean | |||
expired_days | numeric | |||
expiry_processed_at | timestamptz | |||
notes | text | |||
adjustment_days | numeric | |||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 21 次 · 被這些表引用:leave_balance_usage、leave_requests
attendance_records25 欄 · FK 出 2 / 入 1002_schema.sql:2320
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
work_date | date | NOT NULL | ||
clock_in_time | timestamptz | |||
clock_out_time | timestamptz | |||
regular_hours | numeric | |||
overtime_hours | numeric | |||
status | varchar | |||
clock_in_source | varchar | |||
clock_in_ip | inet | |||
clock_out_source | varchar | |||
clock_out_ip | inet | |||
clock_in_latitude | float8 | |||
clock_in_longitude | float8 | |||
clock_out_latitude | float8 | |||
clock_out_longitude | float8 | |||
remark | text | |||
is_corrected | boolean | |||
corrected_by | uuid | FK | users | |
corrected_at | timestamptz | |||
correction_reason | text | |||
original_clock_in | timestamptz | |||
original_clock_out | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 19 次 · 被這些表引用:overtime_records
calendar_event_sync15 欄 · FK 出 1 / 入 1002_schema.sql:2470
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
leave_request_id | uuid | NOT NULL | FK | leave_requests CASCADE |
google_event_id | varchar | |||
google_event_etag | varchar | |||
google_event_link | text | |||
sync_version | integer | NOT NULL | ||
local_updated_at | timestamptz | NOT NULL | ||
google_updated_at | timestamptz | |||
last_synced_data | jsonb | |||
sync_status | varchar | NOT NULL | ||
last_error | text | |||
error_count | integer | NOT NULL | ||
last_error_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 12 次 · 被這些表引用:calendar_sync_conflicts
calendar_sync_conflicts15 欄 · FK 出 4 / 入 0002_schema.sql:2493
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
calendar_event_sync_id | uuid | FK | calendar_event_sync SET NULL | |
leave_request_id | uuid | FK | leave_requests SET NULL | |
conflict_type | varchar | NOT NULL | ||
ipig_data | jsonb | NOT NULL | ||
google_data | jsonb | |||
difference_summary | text | |||
status | varchar | NOT NULL | ||
resolved_by | uuid | FK | users | |
resolved_at | timestamptz | |||
resolution_notes | text | |||
requires_new_approval | boolean | NOT NULL | ||
new_approval_request_id | uuid | FK | leave_requests | |
detected_at | timestamptz | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 6 次 · 沒有表引用它
calendar_sync_history17 欄 · FK 出 1 / 入 0002_schema.sql:2516
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
job_type | varchar | NOT NULL | ||
triggered_by | uuid | FK | users | |
started_at | timestamptz | NOT NULL | ||
completed_at | timestamptz | |||
duration_ms | integer | |||
status | varchar | NOT NULL | ||
events_created | integer | NOT NULL | ||
events_updated | integer | NOT NULL | ||
events_deleted | integer | NOT NULL | ||
events_checked | integer | NOT NULL | ||
conflicts_detected | integer | NOT NULL | ||
errors_count | integer | NOT NULL | ||
error_messages | jsonb | |||
progress_percentage | integer | NOT NULL | ||
current_operation | varchar | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 5 次 · 沒有表引用它
comp_time_balances13 欄 · FK 出 2 / 入 1002_schema.sql:2724
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
overtime_record_id | uuid | NOT NULL | FKUK | overtime_records CASCADE |
original_hours | numeric | NOT NULL | ||
used_hours | numeric | |||
earned_date | date | NOT NULL | ||
expires_at | date | NOT NULL | ||
is_expired | boolean | |||
expired_hours | numeric | |||
converted_to_pay | boolean | |||
expiry_processed_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 12 次 · 被這些表引用:leave_balance_usage
competency_assessments13 欄 · FK 出 2 / 入 0002_schema.sql:2745
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users |
assessment_type | varchar | NOT NULL | ||
skill_area | varchar | NOT NULL | ||
assessment_date | date | NOT NULL | ||
assessor_id | uuid | NOT NULL | FK | users |
result | varchar | NOT NULL | ||
score | numeric | |||
method | varchar | |||
valid_until | date | |||
notes | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 6 次 · 沒有表引用它
google_calendar_config25 欄 · FK 出 0 / 入 0002_schema.sql:3576
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
calendar_id | varchar | NOT NULL | ||
calendar_name | varchar | |||
calendar_description | text | |||
auth_method | varchar | NOT NULL | ||
auth_email | varchar | |||
is_configured | boolean | NOT NULL | ||
sync_enabled | boolean | NOT NULL | ||
sync_schedule_morning | time_without_time_zone | |||
sync_schedule_evening | time_without_time_zone | |||
sync_timezone | varchar | |||
sync_approved_leaves | boolean | NOT NULL | ||
sync_overtime | boolean | NOT NULL | ||
event_title_template | varchar | |||
event_color_id | varchar | |||
last_sync_at | timestamptz | |||
last_sync_status | varchar | |||
last_sync_error | text | |||
last_sync_events_pushed | integer | |||
last_sync_events_pulled | integer | |||
last_sync_conflicts | integer | |||
last_sync_duration_ms | integer | |||
next_sync_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 6 次 · 沒有表引用它
leave_approvals7 欄 · FK 出 2 / 入 0002_schema.sql:3764
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
leave_request_id | uuid | NOT NULL | FK | leave_requests CASCADE |
approver_id | uuid | NOT NULL | FK | users |
approval_level | varchar | NOT NULL | ||
action | varchar | NOT NULL | ||
comments | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 10 次 · 沒有表引用它
leave_balance_usage9 欄 · FK 出 3 / 入 0002_schema.sql:3780
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
leave_request_id | uuid | NOT NULL | FK | leave_requests |
source_type | varchar | NOT NULL | ||
annual_leave_entitlement_id | uuid | FK | annual_leave_entitlements | |
comp_time_balance_id | uuid | FK | comp_time_balances | |
days_used | numeric | |||
hours_used | numeric | |||
action | varchar | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 11 次 · 沒有表引用它
leave_requests26 欄 · FK 出 4 / 入 5002_schema.sql:3799
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
proxy_user_id | uuid | FK | users | |
leave_type | leave_type | NOT NULL | ||
start_date | date | NOT NULL | ||
end_date | date | NOT NULL | ||
start_time | time_without_time_zone | |||
end_time | time_without_time_zone | |||
total_days | numeric | NOT NULL | ||
total_hours | numeric | |||
reason | text | |||
supporting_documents | jsonb | |||
annual_leave_source_id | uuid | FK | annual_leave_entitlements | |
is_urgent | boolean | |||
is_retroactive | boolean | |||
status | leave_status | |||
current_approver_id | uuid | FK | users | |
submitted_at | timestamptz | |||
approved_at | timestamptz | |||
rejected_at | timestamptz | |||
cancelled_at | timestamptz | |||
revoked_at | timestamptz | |||
cancellation_reason | text | |||
revocation_reason | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 50 次 · 被這些表引用:calendar_event_sync、calendar_sync_conflicts、leave_approvals、leave_balance_usage
overtime_approvals7 欄 · FK 出 2 / 入 0002_schema.sql:4081
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
overtime_record_id | uuid | NOT NULL | FK | overtime_records CASCADE |
approver_id | uuid | NOT NULL | FK | users |
approval_level | varchar | NOT NULL | ||
action | varchar | NOT NULL | ||
comments | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 5 次 · 沒有表引用它
overtime_records30 欄 · FK 出 5 / 入 2002_schema.sql:4097
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
attendance_id | uuid | FK | attendance_records | |
overtime_date | date | NOT NULL | ||
start_time | timestamptz | NOT NULL | ||
end_time | timestamptz | NOT NULL | ||
hours | numeric | NOT NULL | ||
overtime_type | varchar | NOT NULL | ||
multiplier | numeric | |||
comp_time_hours | numeric | NOT NULL | ||
comp_time_expires_at | date | NOT NULL | ||
comp_time_used_hours | numeric | |||
status | varchar | |||
submitted_at | timestamptz | |||
approved_by | uuid | FK | users | |
approved_at | timestamptz | |||
rejected_by | uuid | FK | users | |
rejected_at | timestamptz | |||
rejection_reason | text | |||
reason | text | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
calc_unit | varchar | NOT NULL | ||
tier1_hours | numeric | NOT NULL | ||
tier2_hours | numeric | NOT NULL | ||
weighted_hours | numeric | NOT NULL | ||
day_count | numeric | NOT NULL | ||
voided_by | uuid | FK | users | |
voided_at | timestamptz | |||
void_reason | text |
backend/src 出現 34 次 · 被這些表引用:comp_time_balances、overtime_approvals
role_training_requirements7 欄 · FK 出 0 / 入 0002_schema.sql:4998
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
role_code | varchar | NOT NULL | 無 FK | |
training_topic | varchar | NOT NULL | ||
is_mandatory | boolean | NOT NULL | ||
recurrence_months | integer | |||
created_at | timestamptz | NOT NULL | ||
deleted_at | timestamptz |
backend/src 出現 6 次 · 沒有表引用它
training_records8 欄 · FK 出 1 / 入 0002_schema.sql:5356
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
course_name | varchar | NOT NULL | ||
completed_at | date | NOT NULL | ||
expires_at | date | |||
notes | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT 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 | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
name | varchar | NOT NULL | ||
model | varchar | |||
serial_number | varchar | |||
location | varchar | |||
notes | text | |||
is_active | boolean | NOT NULL | ||
status | equipment_status | NOT NULL | ||
calibration_type | calibration_type | |||
calibration_cycle | calibration_cycle | |||
inspection_cycle | calibration_cycle | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
purchase_date | date | |||
warranty_expiry | date | |||
department | varchar |
backend/src 出現 239 次 · 被這些表引用:equipment_annual_plans、equipment_calibrations、equipment_disposals、equipment_idle_requests、equipment_maintenance_records、equipment_status_logs、equipment_suppliers
equipment_annual_plans20 欄 · FK 出 1 / 入 0002_schema.sql:3069
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
year | integer | NOT NULL | ||
equipment_id | uuid | NOT NULL | FK | equipment CASCADE |
calibration_type | calibration_type | NOT NULL | ||
cycle | calibration_cycle | NOT NULL | ||
month_1 | boolean | NOT NULL | ||
month_2 | boolean | NOT NULL | ||
month_3 | boolean | NOT NULL | ||
month_4 | boolean | NOT NULL | ||
month_5 | boolean | NOT NULL | ||
month_6 | boolean | NOT NULL | ||
month_7 | boolean | NOT NULL | ||
month_8 | boolean | NOT NULL | ||
month_9 | boolean | NOT NULL | ||
month_10 | boolean | NOT NULL | ||
month_11 | boolean | NOT NULL | ||
month_12 | boolean | NOT NULL | ||
generated_at | timestamptz | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 沒有表引用它
equipment_calibrations25 欄 · FK 出 3 / 入 0002_schema.sql:3097
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
equipment_id | uuid | NOT NULL | FK | equipment CASCADE |
calibrated_at | date | NOT NULL | ||
next_due_at | date | |||
result | varchar | |||
notes | text | |||
calibration_type | calibration_type | NOT NULL | ||
partner_id | uuid | FK | partners | |
report_number | varchar | |||
inspector | varchar | |||
equipment_serial_number | varchar | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
certificate_number | varchar | |||
performed_by | varchar | 無 FK | ||
acceptance_criteria | varchar | |||
measurement_uncertainty | varchar | |||
validation_phase | validation_phase | |||
protocol_number | varchar | |||
reference_standard_id | uuid | FK | reference_standards | |
calibration_lab_name | varchar | |||
calibration_lab_accreditation | varchar | |||
traceability_statement | text | |||
reading_before | varchar | |||
reading_after | varchar |
backend/src 出現 12 次 · 沒有表引用它
equipment_disposals16 欄 · FK 出 5 / 入 0002_schema.sql:3130
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
equipment_id | uuid | NOT NULL | FK | equipment CASCADE |
status | disposal_status | NOT NULL | ||
disposal_date | date | |||
reason | text | NOT NULL | ||
disposal_method | text | |||
applied_by | uuid | NOT NULL | FK | users |
applied_at | timestamptz | NOT NULL | ||
approved_by | uuid | FK | users | |
approved_at | timestamptz | |||
rejection_reason | text | |||
applicant_signature_id | uuid | FK | electronic_signatures | |
approver_signature_id | uuid | FK | electronic_signatures | |
notes | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 18 次 · 沒有表引用它
equipment_idle_requests15 欄 · FK 出 5 / 入 0002_schema.sql:3154
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
equipment_id | uuid | NOT NULL | FK | equipment CASCADE |
request_type | text | NOT NULL | ||
reason | text | NOT NULL | ||
status | disposal_status | NOT NULL | ||
applied_by | uuid | NOT NULL | FK | users |
applied_at | timestamptz | NOT NULL | ||
applicant_signature_id | uuid | FK | electronic_signatures | |
approved_by | uuid | FK | users | |
approved_at | timestamptz | |||
approver_signature_id | uuid | FK | electronic_signatures | |
rejection_reason | text | |||
notes | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 11 次 · 沒有表引用它
equipment_maintenance_records19 欄 · FK 出 5 / 入 0002_schema.sql:3178
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
equipment_id | uuid | NOT NULL | FK | equipment CASCADE |
maintenance_type | maintenance_type | NOT NULL | ||
status | maintenance_status | NOT NULL | ||
reported_at | date | NOT NULL | ||
completed_at | date | |||
problem_description | text | |||
repair_content | text | |||
repair_partner_id | uuid | FK | partners | |
maintenance_items | text | |||
performed_by | varchar | 無 FK | ||
notes | text | |||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
reviewed_by | uuid | FK | users | |
reviewed_at | timestamptz | |||
reviewer_signature_id | uuid | FK | electronic_signatures | |
review_notes | text |
backend/src 出現 18 次 · 沒有表引用它
equipment_status_logs7 欄 · FK 出 2 / 入 0002_schema.sql:3205
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
equipment_id | uuid | NOT NULL | FK | equipment CASCADE |
old_status | equipment_status | NOT NULL | ||
new_status | equipment_status | NOT NULL | ||
changed_by | uuid | NOT NULL | FK | users |
reason | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 沒有表引用它
equipment_suppliers8 欄 · FK 出 2 / 入 0002_schema.sql:3220
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
equipment_id | uuid | NOT NULL | FK | equipment CASCADE |
partner_id | uuid | NOT NULL | FK | partners CASCADE |
contact_person | varchar | |||
contact_phone | varchar | |||
contact_email | varchar | |||
notes | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 5 次 · 沒有表引用它
reference_standards17 欄 · FK 出 1 / 入 1002_schema.sql:4806
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
name | varchar | NOT NULL | ||
serial_number | varchar | |||
standard_type | varchar | NOT NULL | ||
traceable_to | varchar | |||
national_standard_number | varchar | |||
calibration_lab | varchar | |||
calibration_lab_accreditation | varchar | |||
last_calibrated_at | date | |||
next_due_at | date | |||
certificate_number | varchar | |||
measurement_uncertainty | varchar | |||
status | varchar | NOT NULL | ||
notes | text | |||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT 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_id | uuid | NOT NULL | PK | |
reason | text | NOT NULL | ||
recorded_at | timestamptz | NOT NULL | ||
recorded_by | text | 無 FK |
backend/src 出現 6 次 · 沒有表引用它
audit_logs10 欄 · FK 出 1 / 入 0002_schema.sql:2373
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
actor_user_id | uuid | NOT NULL | FK | users |
action | varchar | NOT NULL | ||
entity_type | varchar | NOT NULL | ||
entity_id | uuid | NOT NULL | ||
before_data | jsonb | |||
after_data | jsonb | |||
ip_address | varchar | |||
user_agent | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 10 次 · 沒有表引用它
change_reasons10 欄 · FK 出 1 / 入 0002_schema.sql:2664
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
entity_type | varchar | NOT NULL | ||
entity_id | text | NOT NULL | ||
change_type | varchar | NOT NULL | ||
reason | text | NOT NULL | ||
old_values | jsonb | |||
new_values | jsonb | |||
changed_fields | text[] | |||
changed_by | uuid | FK | users | |
changed_at | timestamptz | NOT NULL |
backend/src 出現 19 次 · 沒有表引用它
change_requests18 欄 · FK 出 4 / 入 0002_schema.sql:2682
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
change_number | varchar | NOT NULL | UK | |
title | varchar | NOT NULL | ||
change_type | varchar | NOT NULL | ||
description | text | NOT NULL | ||
justification | text | |||
impact_assessment | text | |||
status | varchar | NOT NULL | ||
requested_by | uuid | NOT NULL | FK | users |
reviewed_by | uuid | FK | users | |
reviewed_at | timestamptz | |||
approved_by | uuid | FK | users | |
approved_at | timestamptz | |||
implemented_at | timestamptz | |||
verified_by | uuid | FK | users | |
verified_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 11 次 · 沒有表引用它
controlled_documents17 欄 · FK 出 2 / 入 2002_schema.sql:2767
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
doc_number | varchar | NOT NULL | UK | |
title | varchar | NOT NULL | ||
doc_type | varchar | NOT NULL | ||
category | varchar | |||
current_version | integer | NOT NULL | ||
status | varchar | NOT NULL | ||
effective_date | date | |||
review_due_date | date | |||
owner_id | uuid | FK | users | |
approved_by | uuid | FK | users | |
approved_at | timestamptz | |||
obsoleted_at | timestamptz | |||
retention_years | integer | |||
file_path | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 14 次 · 被這些表引用:document_acknowledgments、document_revisions
data_retention_policies7 欄 · FK 出 0 / 入 0002_schema.sql:2792
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
table_name | text | NOT NULL | UK | |
retention_years | integer | |||
delete_strategy | text | NOT NULL | ||
description | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 5 次 · 沒有表引用它
document_acknowledgments5 欄 · FK 出 2 / 入 0002_schema.sql:2855
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
document_id | uuid | NOT NULL | FK | controlled_documents CASCADE |
user_id | uuid | NOT NULL | FK | users |
acknowledged_at | timestamptz | NOT NULL | ||
version_acknowledged | integer | NOT NULL |
backend/src 出現 2 次 · 沒有表引用它
document_revisions10 欄 · FK 出 4 / 入 0002_schema.sql:2897
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
document_id | uuid | NOT NULL | FK | controlled_documents CASCADE |
version | integer | NOT NULL | ||
change_summary | text | NOT NULL | ||
revised_by | uuid | FK | users | |
reviewed_by | uuid | FK | users | |
approved_by | uuid | FK | users | |
approved_at | timestamptz | |||
file_path | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 3 次 · 沒有表引用它
electronic_signatures20 欄 · FK 出 3 / 入 13002_schema.sql:2966
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
entity_type | varchar | NOT NULL | ||
entity_id | varchar | NOT NULL | ||
signer_id | uuid | NOT NULL | FK | users |
signature_type | varchar | NOT NULL | ||
content_hash | varchar | NOT NULL | ||
signature_data | varchar | NOT NULL | ||
ip_address | varchar | |||
user_agent | text | |||
signed_at | timestamptz | NOT NULL | ||
is_valid | boolean | NOT NULL | ||
invalidated_reason | text | |||
invalidated_at | timestamptz | |||
invalidated_by | uuid | FK | users | |
handwriting_svg | text | |||
stroke_data | jsonb | |||
signature_method | varchar | |||
hmac_version | smallint | NOT NULL | ||
meaning | signature_meaning | NOT NULL | ||
delegation_id | uuid | FK | protocol_pi_delegates |
backend/src 出現 37 次 · 被這些表引用:amendments、equipment_disposals、equipment_idle_requests、equipment_maintenance_records、pdf_artifacts、protocol_notice_acknowledgements、protocols、record_annotations、study_final_reports
management_reviews14 欄 · FK 出 1 / 入 0002_schema.sql:3878
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
review_number | varchar | NOT NULL | UK | |
title | varchar | NOT NULL | ||
review_date | date | NOT NULL | ||
status | varchar | NOT NULL | ||
agenda | text | |||
attendees | jsonb | |||
minutes | text | |||
decisions | jsonb | |||
action_items | jsonb | |||
chaired_by | uuid | FK | users | |
approved_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 沒有表引用它
qa_audit_schedules9 欄 · FK 出 1 / 入 1002_schema.sql:4620
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
year | integer | NOT NULL | ||
title | varchar | NOT NULL | ||
schedule_type | qa_schedule_type | NOT NULL | ||
description | text | |||
status | qa_schedule_status | NOT NULL | ||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 6 次 · 被這些表引用:qa_schedule_items
qa_capa10 欄 · FK 出 2 / 入 0002_schema.sql:4637
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
nc_id | uuid | NOT NULL | FK | qa_non_conformances CASCADE |
action_type | capa_action_type | NOT NULL | ||
description | text | NOT NULL | ||
assignee_id | uuid | FK | users | |
due_date | date | |||
completed_at | timestamptz | |||
status | capa_status | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 4 次 · 沒有表引用它
qa_inspection_items7 欄 · FK 出 1 / 入 0002_schema.sql:4655
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
inspection_id | uuid | NOT NULL | FK | qa_inspections CASCADE |
item_order | integer | NOT NULL | ||
description | text | NOT NULL | ||
result | qa_item_result | NOT NULL | ||
remarks | text | |||
created_at | timestamptz | NOT NULL |
backend/src 出現 4 次 · 沒有表引用它
qa_inspections13 欄 · FK 出 1 / 入 3002_schema.sql:4670
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
inspection_number | varchar | NOT NULL | UK | |
title | varchar | NOT NULL | ||
inspection_type | qa_inspection_type | NOT NULL | ||
inspection_date | date | NOT NULL | ||
inspector_id | uuid | NOT NULL | FK | users |
related_entity_type | varchar | |||
related_entity_id | uuid | |||
status | qa_inspection_status | NOT NULL | ||
findings | text | |||
conclusion | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 7 次 · 被這些表引用:qa_inspection_items、qa_non_conformances、qa_schedule_items
qa_non_conformances16 欄 · FK 出 3 / 入 1002_schema.sql:4691
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
nc_number | varchar | NOT NULL | UK | |
title | varchar | NOT NULL | ||
description | text | NOT NULL | ||
severity | nc_severity | NOT NULL | ||
source | nc_source | NOT NULL | ||
related_inspection_id | uuid | FK | qa_inspections | |
assignee_id | uuid | FK | users | |
due_date | date | |||
status | nc_status | NOT NULL | ||
root_cause | text | |||
closure_notes | text | |||
closed_at | timestamptz | |||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 被這些表引用:qa_capa
qa_schedule_items12 欄 · FK 出 3 / 入 0002_schema.sql:4715
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
schedule_id | uuid | NOT NULL | FK | qa_audit_schedules CASCADE |
inspection_type | qa_inspection_type | NOT NULL | ||
title | varchar | NOT NULL | ||
planned_date | date | NOT NULL | ||
actual_date | date | |||
responsible_person_id | uuid | FK | users | |
related_inspection_id | uuid | FK | qa_inspections | |
status | qa_schedule_item_status | NOT NULL | ||
notes | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 5 次 · 沒有表引用它
qa_sop_acknowledgments4 欄 · FK 出 2 / 入 0002_schema.sql:4735
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
sop_id | uuid | NOT NULL | FK | qa_sop_documents CASCADE |
user_id | uuid | NOT NULL | FK | users |
acknowledged_at | timestamptz | NOT NULL |
backend/src 出現 6 次 · 沒有表引用它
qa_sop_documents19 欄 · FK 出 3 / 入 1002_schema.sql:4747
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
document_number | varchar | NOT NULL | UK | |
title | varchar | NOT NULL | ||
version | varchar | NOT NULL | ||
category | varchar | |||
file_path | varchar | |||
effective_date | date | |||
review_date | date | |||
status | sop_status | NOT NULL | ||
description | text | |||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
reviewed_by | uuid | FK | users | |
reviewed_at | timestamptz | |||
approved_by | uuid | FK | users | |
approved_at | timestamptz | |||
review_due_date | date | |||
revision_history | jsonb |
backend/src 出現 13 次 · 被這些表引用:qa_sop_acknowledgments
record_annotations8 欄 · FK 出 2 / 入 0002_schema.sql:4774
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
record_type | varchar | NOT NULL | ||
record_id | integer | NOT NULL | ||
annotation_type | varchar | NOT NULL | ||
content | text | NOT NULL | ||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
signature_id | uuid | FK | electronic_signatures |
backend/src 出現 3 次 · 沒有表引用它
record_versions8 欄 · FK 出 1 / 入 0002_schema.sql:4790
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
record_type | version_record_type | NOT NULL | ||
record_id | uuid | NOT NULL | ||
version_no | integer | NOT NULL | ||
snapshot | jsonb | NOT NULL | ||
diff_summary | text | |||
changed_by | uuid | FK | users | |
changed_at | timestamptz | NOT NULL |
backend/src 出現 5 次 · 沒有表引用它
risk_register18 欄 · FK 出 1 / 入 0002_schema.sql:4959
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
risk_number | varchar | NOT NULL | UK | |
title | varchar | NOT NULL | ||
description | text | |||
category | varchar | |||
source | varchar | |||
severity | integer | NOT NULL | ||
likelihood | integer | NOT NULL | ||
detectability | integer | |||
risk_score | integer | |||
status | varchar | NOT NULL | ||
mitigation_plan | text | |||
residual_risk_score | integer | |||
owner_id | uuid | FK | users | |
review_date | date | |||
related_nc_id | uuid | 無 FK | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 沒有表引用它
signature_bridge_sessions10 欄 · FK 出 1 / 入 0002_schema.sql:5107
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
mobile_token_hash | varchar | NOT NULL | ||
purpose | varchar | NOT NULL | ||
payload | text | |||
status | varchar | NOT NULL | ||
expires_at | timestamptz | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
submitted_at | timestamptz | |||
consumed_at | timestamptz |
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 | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
api_key_id | uuid | NOT NULL | 無 FK | |
endpoint | varchar | NOT NULL | ||
method | varchar | NOT NULL | ||
query_summary | jsonb | |||
response_status | smallint | NOT NULL | ||
duration_ms | integer | NOT NULL | ||
source_ip | varchar | |||
created_at | timestamptz | NOT NULL | PK |
backend/src 出現 3 次 · 沒有表引用它
attachments10 欄 · FK 出 1 / 入 3002_schema.sql:2302
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
category | varchar | NOT NULL | ||
entity_id | varchar | |||
entity_type | varchar | |||
file_name | varchar | NOT NULL | ||
file_path | varchar | NOT NULL | ||
file_size | integer | NOT NULL | ||
mime_type | varchar | NOT NULL | ||
uploaded_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL |
backend/src 出現 59 次 · 被這些表引用:application_notices、pdf_artifacts、protocol_notice_acknowledgements
event_outbox13 欄 · FK 出 1 / 入 0002_schema.sql:3374
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
channel | text | NOT NULL | ||
payload | jsonb | NOT NULL | ||
status | text | NOT NULL | ||
attempt_count | integer | NOT NULL | ||
next_attempt_at | timestamptz | NOT NULL | ||
last_error | text | |||
enqueued_by | uuid | FK | users | |
enqueued_at | timestamptz | NOT NULL | ||
started_at | timestamptz | |||
done_at | timestamptz | |||
source_entity | text | |||
source_entity_id | uuid |
backend/src 出現 11 次 · 沒有表引用它
export_jobs11 欄 · FK 出 1 / 入 0002_schema.sql:3518
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
export_type | export_type | NOT NULL | ||
export_format | export_format | NOT NULL | ||
status | import_status | NOT NULL | ||
file_name | varchar | |||
file_path | varchar | |||
parameters | jsonb | |||
started_at | timestamptz | |||
completed_at | timestamptz | |||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL |
backend/src 出現 1 次 · 沒有表引用它
import_jobs14 欄 · FK 出 1 / 入 0002_schema.sql:3609
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
import_type | import_type | NOT NULL | ||
status | import_status | NOT NULL | ||
file_name | varchar | NOT NULL | ||
file_path | varchar | NOT NULL | ||
total_rows | integer | |||
processed_rows | integer | |||
success_rows | integer | |||
error_rows | integer | |||
error_details | jsonb | |||
started_at | timestamptz | |||
completed_at | timestamptz | |||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL |
backend/src 出現 1 次 · 沒有表引用它
message_attachments9 欄 · FK 出 2 / 入 0002_schema.sql:3900
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
message_id | uuid | FK | messages CASCADE | |
uploaded_by | uuid | NOT NULL | FK | users |
file_name | varchar | NOT NULL | ||
file_path | text | NOT NULL | ||
file_size | bigint | NOT NULL | ||
mime_type | varchar | NOT NULL | ||
sort_order | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 8 次 · 沒有表引用它
message_thread_participants5 欄 · FK 出 2 / 入 0002_schema.sql:3917
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
thread_id | uuid | NOT NULL | PKFK | message_threads CASCADE |
user_id | uuid | NOT NULL | PKFK | users CASCADE |
joined_at | timestamptz | NOT NULL | ||
last_read_at | timestamptz | |||
left_at | timestamptz |
backend/src 出現 13 次 · 沒有表引用它
message_threads7 欄 · FK 出 1 / 入 2002_schema.sql:3930
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
type | varchar | NOT NULL | ||
subject | varchar | |||
created_by | uuid | NOT NULL | FK | users |
created_at | timestamptz | NOT NULL | ||
last_message_at | timestamptz | NOT NULL | ||
deleted_at | timestamptz |
backend/src 出現 6 次 · 被這些表引用:message_thread_participants、messages
messages7 欄 · FK 出 2 / 入 1002_schema.sql:3946
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
thread_id | uuid | NOT NULL | FK | message_threads CASCADE |
sender_id | uuid | NOT NULL | FK | users |
body | text | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
edited_at | timestamptz | |||
deleted_at | timestamptz |
backend/src 出現 35 次 · 被這些表引用:message_attachments
notification_routing13 欄 · FK 出 1 / 入 0002_schema.sql:3961
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
event_type | varchar | NOT NULL | ||
role_code | varchar | FK | roles | |
channel | varchar | NOT NULL | ||
is_active | boolean | NOT NULL | ||
description | text | |||
frequency | varchar | NOT NULL | ||
hour_of_day | smallint | NOT NULL | ||
day_of_week | smallint | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
target_kind | varchar | NOT NULL | ||
target_value | varchar | NOT NULL |
backend/src 出現 50 次 · 沒有表引用它
notification_settings9 欄 · FK 出 1 / 入 0002_schema.sql:4022
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
user_id | uuid | NOT NULL | PKFK | users CASCADE |
email_low_stock | boolean | NOT NULL | ||
email_expiry_warning | boolean | NOT NULL | ||
email_document_approval | boolean | NOT NULL | ||
email_protocol_status | boolean | NOT NULL | ||
email_monthly_report | boolean | NOT NULL | ||
expiry_warning_days | integer | NOT NULL | ||
low_stock_notify_immediately | boolean | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 22 次 · 沒有表引用它
notifications13 欄 · FK 出 1 / 入 0002_schema.sql:4039
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | NOT NULL | FK | users CASCADE |
type | notification_type | NOT NULL | ||
title | varchar | NOT NULL | ||
content | text | |||
is_read | boolean | NOT NULL | ||
read_at | timestamptz | |||
related_entity_type | varchar | |||
related_entity_id | uuid | |||
created_at | timestamptz | NOT NULL | ||
priority | smallint | NOT NULL | ||
kind | text | NOT NULL | ||
recipient_role | text |
backend/src 出現 59 次 · 沒有表引用它
pdf_artifacts15 欄 · FK 出 3 / 入 0002_schema.sql:4224
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
resource_type | text | NOT NULL | ||
resource_id | text | NOT NULL | ||
pdf_blob_hash | text | NOT NULL | ||
pdf_size_bytes | bigint | NOT NULL | ||
doc_type | text | NOT NULL | ||
generated_by | uuid | NOT NULL | FK | users |
generated_at | timestamptz | NOT NULL | ||
request_ip | inet | |||
user_agent | text | |||
electronic_signature_id | uuid | FK | electronic_signatures | |
hmac_chain_link | text | |||
attachment_id | uuid | FK | attachments | |
storage_strategy | text | NOT NULL | ||
created_at | timestamptz | NOT NULL |
backend/src 出現 6 次 · 沒有表引用它
report_history9 欄 · FK 出 2 / 入 0002_schema.sql:4872
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
scheduled_report_id | uuid | FK | scheduled_reports SET NULL | |
report_type | report_type | NOT NULL | ||
file_name | varchar | NOT NULL | ||
file_path | varchar | NOT NULL | ||
file_size | integer | |||
parameters | jsonb | |||
generated_at | timestamptz | NOT NULL | ||
generated_by | uuid | FK | users |
backend/src 出現 4 次 · 沒有表引用它
scheduled_reports14 欄 · FK 出 1 / 入 1002_schema.sql:5030
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
report_type | report_type | NOT NULL | ||
schedule_type | schedule_type | NOT NULL | ||
day_of_week | integer | |||
day_of_month | integer | |||
hour_of_day | integer | NOT NULL | ||
parameters | jsonb | |||
recipients | uuid[] | NOT NULL | ||
is_active | boolean | NOT NULL | ||
last_run_at | timestamptz | |||
next_run_at | timestamptz | |||
created_by | uuid | FK | users | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 7 次 · 被這些表引用:report_history
security_alert_config4 欄 · FK 出 0 / 入 0002_schema.sql:5052
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
key | varchar | NOT NULL | PK | |
value | text | NOT NULL | ||
description | text | |||
updated_at | timestamptz | NOT NULL |
backend/src 出現 4 次 · 沒有表引用它
security_alerts16 欄 · FK 出 3 / 入 0002_schema.sql:5064
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
alert_type | varchar | NOT NULL | ||
severity | varchar | NOT NULL | ||
title | varchar | NOT NULL | ||
description | text | |||
user_id | uuid | FK | users | |
activity_log_id | uuid | 無 FK | ||
login_event_id | uuid | FK | login_events | |
context_data | jsonb | |||
status | varchar | |||
resolved_by | uuid | FK | users | |
resolved_at | timestamptz | |||
resolution_notes | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
last_notified_at | timestamptz |
backend/src 出現 39 次 · 沒有表引用它
security_notification_channels7 欄 · FK 出 0 / 入 0002_schema.sql:5090
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
channel | varchar | NOT NULL | ||
is_enabled | boolean | NOT NULL | ||
config_json | jsonb | NOT NULL | ||
min_severity | varchar | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 4 次 · 沒有表引用它
system_settings5 欄 · FK 出 1 / 入 0002_schema.sql:5343
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
key | varchar | NOT NULL | PK | |
value | jsonb | NOT NULL | ||
description | text | |||
updated_at | timestamptz | NOT NULL | ||
updated_by | uuid | FK | users |
backend/src 出現 34 次 · 沒有表引用它
user_activity_aggregates16 欄 · FK 出 1 / 入 0002_schema.sql:5409
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
user_id | uuid | FK | users CASCADE | |
aggregate_date | date | NOT NULL | ||
login_count | integer | |||
failed_login_count | integer | |||
session_count | integer | |||
total_session_minutes | integer | |||
page_view_count | integer | |||
action_count | integer | |||
actions_by_category | jsonb | |||
pages_visited | jsonb | |||
entities_modified | jsonb | |||
unique_ip_count | integer | |||
unusual_activity_count | integer | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
backend/src 出現 2 次 · 沒有表引用它
user_activity_logs32 欄 · FK 出 2 / 入 0 · 分區 ×12002_schema.sql:5433
| 欄位 | 型別 | NULL | 鍵 | 指向 |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
actor_user_id | uuid | FK | users | |
actor_email | varchar | |||
actor_display_name | varchar | |||
actor_roles | jsonb | |||
session_id | uuid | 無 FK | ||
session_started_at | timestamptz | |||
event_category | varchar | NOT NULL | ||
event_type | varchar | NOT NULL | ||
event_severity | varchar | |||
entity_type | varchar | |||
entity_id | uuid | |||
entity_display_name | varchar | |||
before_data | jsonb | |||
after_data | jsonb | |||
changed_fields | text[] | |||
ip_address | inet | |||
user_agent | text | |||
request_path | varchar | |||
request_method | varchar | |||
response_status | integer | |||
geo_country | varchar | |||
geo_city | varchar | |||
is_suspicious | boolean | |||
suspicious_reason | text | |||
created_at | timestamptz | NOT NULL | ||
partition_date | date | NOT NULL | PK | |
integrity_hash | varchar | |||
previous_hash | varchar | |||
impersonated_by_user_id | uuid | FK | users | |
hmac_version | smallint | |||
extra_input | text |
backend/src 出現 79 次 · 沒有表引用它
怎麼算的
- 來源是
gitlab/main的backend/migrations,依檔名順序套用CREATE TABLE、ALTER TABLE … ADD COLUMN/ADD CONSTRAINT、CREATE INDEX。FK 總數與 migration 檔中FOREIGN KEY/REFERENCES字樣的出現數逐一對過。 - 分區子表(14 張)併回母表;view(6 個)不畫。
- 「缺 FK」是用欄位名稱(
_id、_by)找候選,再逐欄讀定義人工判定,所以只抓得到名字像外鍵的欄位。命名不規則的關聯(例如只叫owner)抓不到。 - 「文字鍵關聯」是找另一張表 UNIQUE 文字欄位的同名欄位,或
<單數表名>_<欄位>形式。 - 「後端出現次數」是
backend/src全文比對表名,只證明有被提到,不證明有被正確使用。 - 未涵蓋:資料庫實際狀態(本頁不連任何資料庫)、觸發器與 CHECK 約束的內容、應用層的完整性檢查。