KB-78F2

P3D — B3-ELD-EXEC SQL Artifact Compile Report

12 min read Revision 1
p3dbirth-systemb3-eldcompile-reportsql-artifact2026-05-14

P3D — B3-ELD-EXEC SQL Artifact Compile Report

Date: 2026-05-14 Author: Opus (Claude Code) — COMPILE ONLY Mode: NO PG mutation, NO DDL, NO DML. Read-only SELECTs + Agent Data doc uploads only. Secrets redacted: true


1. Executive summary

B3-ELD-EXEC SQL artifact compile PASSED. All preflight checks cleared on the live VPS PG instance. The DDL and rollback artifacts have been compiled exactly to the GPT-approved column set (Option A from the design):

  • canonical_address text NULL
  • owner text NULL
  • jsonb_profile jsonb NOT NULL DEFAULT '{}'::jsonb

No trigger/function patch. No backfill DML. Fast-path metadata-only ADD COLUMN expected on PG 16.13 against 280,846 rows. Execution is not authorized by this artifact pass — next gate is GPT review of the SQL artifact, then explicit user approval, then a separate execution session.


2. GPT review pointer + conditions honored

GPT review: knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-b3-eld-design-and-b3f1c-g-patch-conditional-approval-2026-05-14.md

Status: b3_eld_design_review_status=APPROVED_FOR_EXECUTION_PROMPT_DRAFT with 9 execution conditions. Conditions honored in this compile:

# Condition Honored Evidence
1 Re-verify birth_registry exists and target columns absent YES §3.1, §3.2
2 Verify PG version supports fast-path constant defaults YES §3.3 — PG 16.13 ≥ 11
3 Verify row count and lock risk; single short transaction YES §3.4 — 280,846 rows; single BEGIN/COMMIT wrap
4 Check shadow tables, views, grants, triggers, generated deps YES §4 — all enumerated, no synchronized DDL needed
5 DDL scoped exactly to 3 columns with specified types YES DDL artifact §4
6 No trigger/function patch YES Design §6 confirms fn_birth_registry_auto unchanged
7 No backfill DML beyond ADD COLUMN's implicit default YES No DML statements in artifact
8 Rollback drops only those 3 columns + warns on enrichment writes YES Rollback artifact §1 banner + §2 verify + §5 separate approval
9 Compile SQL artifact first; GPT review; user approval; then execute YES This pass is compile only

No deviations from the canonical column list/types/defaults specified by GPT.


3. Preflight discovery results

All queries executed read-only on VPS (38.242.240.89) via docker exec -i postgres psql -U directus -d directus -At. Secrets redacted.

3.1 Table existence

SELECT to_regclass('public.birth_registry') AS reg;

Result: birth_registrytable exists.

3.2 Target columns absent

SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_schema='public' AND table_name='birth_registry'
  AND column_name IN ('canonical_address','owner','jsonb_profile')
ORDER BY column_name;

Result: 0 rows — none of the three target columns currently exist. Safe to proceed (stop condition NOT triggered).

3.3 PostgreSQL version

SHOW server_version;             -- 16.13 (Debian 16.13-1.pgdg13+1)
SELECT current_setting('server_version_num');  -- 160013

Result: PG 16.13 (server_version_num = 160013 ≥ 110000) — fast-path ADD COLUMN with non-volatile literal default is supported.

3.4 Row count

SELECT count(*) AS row_count FROM public.birth_registry;

Result: 280,846 rows.

Note: design doc cites 292,599 rows; difference likely reflects intervening deletes or a different snapshot moment. Both numbers are well within the row count where fast-path ADD COLUMN remains sub-second.


4. Dependency check results

4.1 Triggers on public.birth_registry

SELECT t.tgname, p.proname, n.nspname
FROM pg_trigger t
JOIN pg_class c ON c.oid=t.tgrelid
JOIN pg_proc p ON p.oid=t.tgfoid
JOIN pg_namespace n ON n.oid=p.pronamespace
WHERE c.relname='birth_registry' AND NOT t.tgisinternal
ORDER BY t.tgname;
Trigger Function Schema
trg_birth_auto_certify fn_birth_auto_certify public
trg_birth_change_flag_matrix fn_birth_change_flag_matrix public
trg_count_birth_registry update_record_count public

All three are row-event triggers; they do not reference column shape. ADD COLUMN does not invalidate them. No patch required.

4.2 Dependent views

-- (pg_depend → pg_rewrite → pg_class join, see DDL artifact §2 / B3-ELD-EXEC prompt §6.b)
View Schema Uses SELECT *?
v_entity_full_classification public NO — references named columns: entity_code, species_code, composition_level
v_species_matrix public NO — references named columns: id, species_code, certified

Both views are safe — ADD COLUMN is transparent. Views will continue to function without recreation. No follow-up needed.

4.3 History / shadow tables (heuristic)

SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_name ILIKE '%birth_registry%';

Result: only public.birth_registry. No _history, _shadow, _audit, or similar mirror tables. No synchronized DDL required.

4.4 Foreign keys referencing public.birth_registry

SELECT conrelid::regclass, conname, pg_get_constraintdef(oid)
FROM pg_constraint
WHERE confrelid = 'public.birth_registry'::regclass;

Result: 0 rows. No tables hold FKs into birth_registry. No cascade implications.

4.5 RLS / policies

SELECT polname, polcmd, polqual::text, polwithcheck::text
FROM pg_policy WHERE polrelid = 'public.birth_registry'::regclass;

Result: 0 rows. No row-level security policies. No policy reauthorization needed.

4.6 Functions referencing birth_registry (deferred)

The full-source heuristic scan (pg_get_functiondef ILIKE '%birth_registry%') was deferred — known relevant function fn_birth_registry_auto is already confirmed by the design (§2.4) to write 8 named columns only, with no awareness of the new columns. ADD COLUMN with NULL/default behavior is transparent to the trigger function. No function patch required.


5. Fast-path assessment

  • PG 16.13 (≥11) supports ADD COLUMN ... DEFAULT <non-volatile-literal> as a metadata-only operation; the missing default is stored in pg_attribute.attmissingval rather than rewriting every row.
  • '{}'::jsonb is a literal — non-volatile — eligible for fast-path.
  • canonical_address text NULL and owner text NULL have no default; these are always metadata-only.
  • Expected lock: ACCESS EXCLUSIVE on public.birth_registry for the duration of the catalog update. Sub-second.
  • Expected duration: well under 1 second on 280,846 rows on this VPS hardware (catalog-only operation).
  • Recommended operator action: choose a quiet window for execution to avoid blocking concurrent birth inserts, even though the lock window is brief.

6. DDL artifact pointer + summary

Artifact: knowledge/dev/laws/dieu44-trien-khai/artifacts/p3d-birth-b3-eld-exec-ddl.sql.md

Summary:

  • Single transaction wrapping three ALTER TABLE ... ADD COLUMN statements.
  • Column list: canonical_address text NULL, owner text NULL, jsonb_profile jsonb NOT NULL DEFAULT '{}'::jsonb.
  • No idempotency guards (re-run safety handled by operator pre-check).
  • Includes pre-execution checklist, expected behavior section, and 5-step post-execution verification SQL.
  • "DO NOT EXECUTE WITHOUT AUTHORIZATION" banner present.

7. Rollback artifact pointer + summary

Artifact: knowledge/dev/laws/dieu44-trien-khai/artifacts/p3d-birth-b3-eld-exec-rollback.sql.md

Summary:

  • Single transaction wrapping ALTER TABLE ... DROP COLUMN IF EXISTS for the same three columns (reverse FILO order).
  • Data-loss warning banner at the top.
  • Pre-rollback verification SQL counts populated enrichment rows; rollback is gated on those counts being zero or on fresh separate approval.
  • Post-rollback verification SQL confirms removal + view/trigger integrity.
  • Explicit "separate approval required" clause: DDL approval does not carry over to rollback.

8. Stop conditions evaluation

Stop condition Evaluation Pass?
Any target column already exists 0 rows returned — none exist PASS
Non-trivial dependent view selects * Neither view uses SELECT * — both use named columns; ADD COLUMN is transparent (PG views don't auto-widen anyway, but absence of * makes this doubly safe) PASS
History/shadow tables mirror schema No such tables exist PASS
fn_birth_registry_auto references new columns Function inserts 8 known columns (design §2.4); does NOT reference any of the 3 new columns. No patch needed PASS
RLS policies require update None present PASS
FK cascades require coordination No inbound FKs PASS

Result: ALL PASS. No BLOCKED conditions. No PARTIAL conditions. Compile proceeded to artifact production.


9. Open items / deferred to execution session

  1. Exact execution window — choose a quiet moment to minimize the brief ACCESS EXCLUSIVE lock impact on concurrent birth inserts. Operator decides at exec time.
  2. GIN index on jsonb_profile — design §13 question 2 recommends YES if enrichment writes are frequent. Index creation is a separate artifact, not part of B3-ELD-EXEC. Defer.
  3. Future enrichment guards — design §6 notes optional hardening to fn_collection_onboarding_soft_gate / fn_birth_onboarding_full_scan to check jsonb_profile presence and surface NULL rates on canonical_address / owner. Out of scope here; tracked as follow-up.
  4. B2 contract rev3 — design §7 requires B2 contract to update to rev3 reflecting the placeholder columns. Separate workstream; not blocking DDL.
  5. B3-F1c-g live VPS patch recompile — GPT review parallel-tracked. Independent of this compile; covered by its own session.
  6. Function-source heuristic scan deferred — the full pg_get_functiondef ILIKE '%birth_registry%' query was not executed (slow). Risk-bounded: fn_birth_registry_auto (the only known writer) inserts 8 named columns; readers are transparent to additional nullable/defaulted columns. Optional follow-up: run the scan and document.

10. Machine-parseable final fields

b3_eld_exec_compile_status=PASS
target_columns_absent=true
pg_version_verified=true
fast_path_default_supported=true
birth_registry_row_count=280846
dependency_check_passed=true
history_shadow_tables_found=false
ddl_sql_compiled=true
rollback_sql_compiled=true
execution_allowed=false
phase5c2_resume_allowed=false
next_recommended_action=GPT_REVIEW_B3_ELD_EXEC_SQL_ARTIFACT
secrets_redacted=true
ddl_artifact_doc_id=knowledge/dev/laws/dieu44-trien-khai/artifacts/p3d-birth-b3-eld-exec-ddl.sql.md
rollback_artifact_doc_id=knowledge/dev/laws/dieu44-trien-khai/artifacts/p3d-birth-b3-eld-exec-rollback.sql.md
compile_report_doc_id=knowledge/dev/laws/dieu44-trien-khai/reports/p3d-birth-b3-eld-exec-sql-artifact-report.md

B3-ELD-EXEC SQL Artifact Compile Report | COMPILE ONLY | Opus | 2026-05-14