18 — IU-0 Birth Trigger Existing Pipeline Execution Pack
18 — IU-0 Birth Trigger Existing Pipeline Execution Pack
Date: 2026-05-05 | Rev 1 Status: EXECUTION DESIGN — chờ GPT/User approve Controlling: 16b rev2 + investigation report + GPT directive Scope: 1 CREATE TRIGGER. Không replace function. Không chạy DOT-119. Không tạo IU rows (trừ test nếu approve).
§1. Evidence
| Doc | Path |
|---|---|
| Investigation | reports/existing-birth-code-column-patterns-report.md |
| Design | design/16b-iu0-existing-birth-pipeline-adaptation.md rev2 |
| GPT directive | reviews/gpt-review-existing-birth-code-column-patterns-and-doc-cleanup-directive-2026-05-05.md |
| Pack 1 schema | reports/iu0-pack1-execution-report.md |
| Pack 2A registration | reviews/iu0-pack2a-closure-and-next-gates-2026-05-04.md |
| Description Policy | reviews/gpt-ratification-description-policy-runtime-post-execution-2026-05-04.md |
§2. Scope
DO: Install 1 birth trigger cho information_unit. DO NOT: Không replace fn_birth_registry_auto. Không chạy DOT-119. Không birth trigger cho unit_version (subordinate). Không Pack 2B CRUD ngoài 1 test row nếu approve. Không vector/outbox/Directus.
§3. Options
| Option | Trigger SQL | entity_code format | Precedent |
|---|---|---|---|
| A (recommended) | EXECUTE FUNCTION fn_birth_registry_auto('__force_synthetic__') |
information_unit::<uuid> (double colon) |
70k rows synthetic v2 |
| B | EXECUTE FUNCTION fn_birth_registry_auto_id() |
information_unit:<uuid> (single colon) |
323 rows governance tables |
| C | Sửa DOT-119 trước → dùng tool | Phụ thuộc tool | Scope lớn, không cần cho IU |
Recommendation: Option A. Dùng fn v2 installed, synthetic fallback, khớp 70k precedent. Không động function.
§4. Preflight
-- 4a: fn_birth_registry_auto vẫn có synthetic fallback
SELECT pg_get_functiondef('fn_birth_registry_auto'::regproc) LIKE '%TG_TABLE_NAME%||%::%||%NEW.id%' AS has_synthetic;
-- Expected: true. Nếu false → STOP.
-- 4b: Chưa có trg_birth_information_unit
SELECT tgname FROM pg_trigger WHERE tgrelid = 'information_unit'::regclass AND tgname = 'trg_birth_information_unit';
-- Expected: 0 rows. Nếu exists → STOP.
-- 4c: information_unit.id UUID NOT NULL
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = 'information_unit' AND column_name = 'id';
-- Expected: uuid, NO, gen_random_uuid().
-- 4d: IU registered observed
SELECT collection_name, governance_role, description_policy
FROM collection_registry WHERE collection_name = 'information_unit';
-- Expected: observed, structured_exempt.
-- 4e: IU row count
SELECT count(*) FROM information_unit;
-- Expected: 0.
-- 4f: birth_registry unique constraint
SELECT conname FROM pg_constraint
WHERE conrelid = 'birth_registry'::regclass AND contype = 'u';
-- Ghi constraint name.
§5. Execute — CREATE TRIGGER
CREATE TRIGGER trg_birth_information_unit
AFTER INSERT ON information_unit
FOR EACH ROW
EXECUTE FUNCTION fn_birth_registry_auto('__force_synthetic__');
Verify:
SELECT tgname, tgenabled, pg_get_triggerdef(oid)
FROM pg_trigger
WHERE tgrelid = 'information_unit'::regclass AND tgname = 'trg_birth_information_unit';
-- Expected: 1 row, enabled.
§6. Test (nếu GPT/User approve test row)
BEGIN;
-- Insert 1 test IU + UV
WITH test_iu AS (
INSERT INTO information_unit (
canonical_address, unit_kind, section_type,
lifecycle_status, identity_profile, owner_ref
) VALUES (
'test.birth.verify',
'design_doc_section',
'section',
'draft',
'{"title": "Birth trigger verify", "content_source": "test"}'::jsonb,
'system'
)
RETURNING id
),
test_uv AS (
INSERT INTO unit_version (unit_id, version_seq, body, lifecycle_status)
SELECT id, 1, 'Birth trigger test body', 'draft' FROM test_iu
RETURNING id, unit_id
)
UPDATE information_unit
SET content_anchor_ref = test_uv.id::text, version_anchor_ref = test_uv.id
FROM test_uv WHERE information_unit.id = test_uv.unit_id;
-- Verify birth_registry
SELECT entity_code, collection_name, species_code, governance_role
FROM birth_registry
WHERE entity_code LIKE 'information_unit::%'
ORDER BY born_at DESC LIMIT 1;
-- Expected: entity_code = 'information_unit::<uuid>', collection_name = 'information_unit'
ROLLBACK;
-- Test row + birth_registry entry both rolled back.
-- Verify clean
SELECT count(*) FROM information_unit WHERE canonical_address = 'test.birth.verify';
-- Expected: 0
SELECT count(*) FROM birth_registry WHERE entity_code LIKE 'information_unit::%';
-- Expected: 0
§7. Rollback
DROP TRIGGER IF EXISTS trg_birth_information_unit ON information_unit;
Không sửa function. Không cleanup khác.
§8. Report Path
knowledge/dev/laws/dieu44-trien-khai/reports/iu0-existing-birth-trigger-execution-report.md
§9. STOP Conditions
| # | Condition | Action |
|---|---|---|
| 1 | fn không có synthetic fallback | STOP |
| 2 | trg_birth_information_unit đã tồn tại | STOP |
| 3 | DOT-119 được propose chạy | STOP |
| 4 | Function replace được propose | STOP |
| 5 | IU rows > 0 ngoài test | STOP |
| 6 | Vector/outbox/Directus mutation | STOP |
§10. Hard Stop After Report
- Không Pack 2B CRUD mở rộng cho đến khi trigger verified
- Không chạy DOT-119
- GPT/User review report required
18 rev 1 | 2026-05-05 | Opus 4.6 | 1 CREATE TRIGGER + preflight + test + rollback. Supersedes file 16/17. Chờ approve.