Đ43 Phase 1 Prerequisite — Create dot_operations table + seed 18 ops Đ35 v5.1
-- ============================================================================= -- Đ43 BLOCK 1 — PHASE 1 PREREQUISITE: dot_operations table -- Target DB: directus -- Idempotent: YES (IF NOT EXISTS + ON CONFLICT DO NOTHING) -- Spec: Đ35 v5.1 FINAL §4.1 (BAN HÀNH 2026-04-14 S177 Fix 8) -- Why: File 01-dieu43-block1-schema.sql §5.6 INSERT 2 rows vào dot_operations. -- Fix 10 verify: bảng này CHƯA tồn tại trên VPS (PR #655 S155 0 CREATE TABLE). -- Đ35 v5.1 BLOCK 1 đã BAN HÀNH nhưng CHƯA chạy migration trên VPS. -- File này trích minimal từ Đ35 v5.1 §4.1 — CHỈ bảng dot_operations + -- seed 18 ops. Không đụng 5 reference tables khác của Đ35 -- (dot_tiers / dot_trigger_types / dot_coverage_statuses / -- dot_domains / dot_coverage_required / dot_config) — retrofit Đ35 -- đầy đủ là mission riêng (14 TODO Đ35, ngoài scope Đ43 Phase 1). -- ============================================================================= -- DOT-MIGRATION-APPLY-OK -- Author: Claude Desktop (Opus 4.7), S178 Fix 11 -- Date: 2026-04-17 -- Run order: CHẠY TRƯỚC file 01-dieu43-block1-schema.sql -- =============================================================================
BEGIN;
-- Đ35 v5.1 §4.1 — Reference table dot_operations -- Schema 3 cột: code (PK), name (NOT NULL), description
CREATE TABLE IF NOT EXISTS dot_operations ( code TEXT PRIMARY KEY, name TEXT NOT NULL, description TEXT );
-- Seed 18 ops theo Đ35 v5.1 §4.1 (nguyên văn): -- 9 op từ v5.0: health, create, sync, ensure, register, report, -- execute, refresh, classify -- 9 op MỚI v5.1: verify, delete, update, restore, import, snapshot, -- seed, audit, backfill -- Case: lowercase (tuân Đ35 seed). Đ43 sẽ INSERT thêm 2 op UPPERCASE -- (CONTEXT_PACK_BUILD, CONTEXT_PACK_VERIFY) ở file 01 — không conflict vì -- PRIMARY KEY TEXT case-sensitive.
INSERT INTO dot_operations(code, name, description) VALUES -- 9 op từ Đ35 v5.0: ('health', 'Kiểm tra sức khoẻ', ''), ('create', 'Tạo mới', ''), ('sync', 'Đồng bộ', ''), ('ensure', 'Đảm bảo tồn tại', ''), ('register', 'Đăng ký', ''), ('report', 'Báo cáo', ''), ('execute', 'Thực thi', ''), ('refresh', 'Làm mới', ''), ('classify', 'Phân loại', ''), -- 9 op MỚI từ Đ35 v5.1 (CLI S177 C6 phát hiện 8/12 op runtime ngoài v5.0): ('verify', 'Kiểm tra hợp lệ', ''), ('delete', 'Xoá', ''), ('update', 'Cập nhật', ''), ('restore', 'Khôi phục', ''), ('import', 'Nhập liệu', ''), ('snapshot', 'Chụp ảnh', ''), ('seed', 'Gieo dữ liệu', ''), ('audit', 'Kiểm toán', ''), ('backfill', 'Điền ngược', '') ON CONFLICT (code) DO NOTHING;
COMMIT;
-- ============================================================================= -- POST-PREREQ VERIFY BLOCK (tách sau COMMIT) -- =============================================================================
SELECT 'dot_operations_table_exists' AS check_name, CASE WHEN EXISTS(SELECT 1 FROM pg_tables WHERE tablename='dot_operations') THEN 'YES' ELSE 'NO' END AS result UNION ALL SELECT 'dot_operations_row_count', COUNT()::text FROM dot_operations UNION ALL SELECT 'dot_operations_has_18_seed_ops', CASE WHEN (SELECT COUNT() FROM dot_operations WHERE code IN ('health','create','sync','ensure','register','report', 'execute','refresh','classify','verify','delete', 'update','restore','import','snapshot','seed', 'audit','backfill')) = 18 THEN 'YES' ELSE 'NO' END;
-- Expected output (3 rows): -- dot_operations_table_exists | YES -- dot_operations_row_count | 18 (hoặc >=18 nếu đã có thêm từ các migration khác) -- dot_operations_has_18_seed_ops | YES
-- ============================================================================= -- END — idempotent, chạy lại không lỗi (CONFLICT DO NOTHING trên code PK) -- =============================================================================