KB-4805 rev 4

IU-0 Pack 1 — Vocab + Schema DDL Design (EXECUTED rev4)

4 min read Revision 4
iu-0pack-1ddl-executedschemavocabbirth-gate2-layerdeferred-requeryrollbacks192

IU-0 Pack 1 — Vocab + Schema DDL Design Pack

Trạng thái: EXECUTED — Pack 1 DONE (2026-05-04) Phiên: S191→S192 (2026-05-04) Input: 09-iu0-minimal-implementation-planning-pack.md rev 7 Scope: Vocab 3 values + DDL 2 tables + birth gate 2-layer + rollback Ranh giới: EXECUTED. Không Qdrant/outbox/worker. Không legacy vector. Rev 4 note: Patch doc hygiene — sửa tên cột dot_config cho khớp runtime thực tế (key/value/updated_at thay config_key/config_value/created_at). Không DDL. Schema trên VPS đã chạy đúng từ CP1 resolution.


1. Vocab registration plan

1.1 DDL — Vocab INSERT (EXECUTED)

INSERT INTO dot_config (key, value, description)
VALUES
  ('vocab.unit_kind.design_doc_section', 'design_doc_section', 'Section trong design document — proposed_pilot'),
  ('vocab.section_type.section', 'section', 'Generic section type cho design docs — proposed_pilot'),
  ('vocab.publication_type.design_doc', 'design_doc', 'Design document publication type — proposed_pilot')
ON CONFLICT (key) DO NOTHING;

1.2 Rollback — Vocab

DELETE FROM dot_config WHERE key IN (
  'vocab.unit_kind.design_doc_section',
  'vocab.section_type.section',
  'vocab.publication_type.design_doc'
);

1.3 Pre-execute checks

  • dot_config schema thực tế: key (PK), value (NOT NULL), description, updated_at (DEFAULT now()).
  • gen_random_uuid(): built-in PG16, không cần extension.

2. DDL — 2 tables (EXECUTED — unchanged from rev3)

(Schema SQL không thay đổi — xem rev3 cho full DDL của information_unit + unit_version + indexes + deferred FK)


3. Birth gate — 2 lớp (EXECUTED)

3.1 Lớp 1: BEFORE INSERT — rev4: WHERE key = thay WHERE config_key =

Vocab lookup dùng WHERE key = 'vocab.unit_kind.' || NEW.unit_kind (3 chỗ: unit_kind, section_type, publication_type).

3.2 Lớp 2: CONSTRAINT TRIGGER DEFERRED — unchanged

Re-query final row, kiểm U5/U6/version ownership/anchor consistency.

3.3 Rollback — Birth gate

DROP TRIGGER IF EXISTS trg_iu_birth_gate_layer1 ON information_unit;
DROP TRIGGER IF EXISTS trg_iu_birth_gate_layer2 ON information_unit;
DROP FUNCTION IF EXISTS fn_iu_birth_gate_layer1();
DROP FUNCTION IF EXISTS fn_iu_birth_gate_layer2();

4. Smoke tests — 14/14 PASS (EXECUTED 2026-05-04)

T1–T13 block tests PASS. T14 positive deferred PASS. Test data cleaned up. Full results in execution report.


6. Full rollback

DELETE FROM unit_version WHERE unit_id IN (SELECT id FROM information_unit WHERE canonical_address LIKE 'test.%');
DELETE FROM information_unit WHERE canonical_address LIKE 'test.%';
DROP TRIGGER IF EXISTS trg_iu_birth_gate_layer1 ON information_unit;
DROP TRIGGER IF EXISTS trg_iu_birth_gate_layer2 ON information_unit;
DROP FUNCTION IF EXISTS fn_iu_birth_gate_layer1();
DROP FUNCTION IF EXISTS fn_iu_birth_gate_layer2();
DROP TRIGGER IF EXISTS trg_iu_updated_at ON information_unit;
ALTER TABLE information_unit DROP CONSTRAINT IF EXISTS fk_iu_version_anchor;
DROP TABLE IF EXISTS unit_version CASCADE;
DROP TABLE IF EXISTS information_unit CASCADE;
DROP FUNCTION IF EXISTS fn_iu_updated_at();
DELETE FROM dot_config WHERE key IN (
  'vocab.unit_kind.design_doc_section',
  'vocab.section_type.section',
  'vocab.publication_type.design_doc'
);

CHANGELOG

Rev Ngày Thay đổi
1 2026-05-04 Draft
2 2026-05-04 L2 re-query final row fix + anchor consistency
3 2026-05-04 GPT review PASS. Publication vocab check, empty string rejection, T14 positive deferred
4 2026-05-04 Doc hygiene post-execution. config_keykey, config_valuevalue, bỏ created_at. Birth gate L1 WHERE key =. Trạng thái EXECUTED. Smoke results filled. Chỉ tài liệu, không DDL.

Pack 1 DDL Design rev4 | EXECUTED 2026-05-04 | Doc hygiene: dot_config key/value/updated_at khớp runtime