KB-6650 rev 4
PostgreSQL — Shared Workflow Database SSOT
2 min read Revision 4
postgresqlworkflowprefectkestrassot
PostgreSQL 16 — Sole Database SSOT
Version: 2.0 | Cập nhật: 2026-03-26 S139. Status: Active (Production VPS). SOLE DATABASE cho toàn bộ hệ thống.
I. PURPOSE
PostgreSQL 16 là CƠ SỞ DỮ LIỆU DUY NHẤT của hệ thống Incomex.
Dùng cho:
- Directus (main application data — TẤT CẢ collections)
- Integrity system (triggers, views, functions)
- Counting (17+ counting triggers, verify_counts())
- Guards (fn_guard_meta_catalog_delete, etc.)
KHÔNG CÒN dùng:
MySQL→ Retired hoàn toàn (S104-S110)Firestore→ RetiredPrefect/Kestra schemas→ Không sử dụng
II. DEPLOYMENT
| Thuộc tính | Giá trị |
|---|---|
| Runtime | Docker on VPS |
| Container | postgres (KHÔNG phải workflow-postgres) |
| Port | 5432 |
| User | directus |
| Database | directus |
| Version | PostgreSQL 16 |
| Access | docker exec -i postgres psql -U directus -d directus |
III. KEY PG OBJECTS
Triggers (26 total)
trg_count_*cho managed collections (realtime counting)fn_refresh_cat_all(CAT-ALL auto-refresh)fn_guard_meta_catalog_delete(prevent accidental delete)
Functions
verify_counts()— integrity check, 0 MISMATCH = healthyretire_entity(text)— ⚠️ TD-380: broken, query old tabledeprecate_entity(text)— ⚠️ TD-380: broken
Views/Tables
v_registry_counts— ⚠️ TD-375: hiện là TABLE writable, cần convert VIEW
IV. ASSEMBLY FIRST — Q0
"Has PostgreSQL already solved this?" — Assembly Gate Question 0.
PG does counting, relations, constraints, guards. Bài học S111: 4 layers of counting code = wrong. 1 correct SQL query = right.
v2.0 | 2026-03-26 S139. Full rewrite: PG = sole DB. MySQL/Firestore retired. Trước đó: v1.1 (2026-02-28, Prefect/Kestra only).