-- Baltique OS Core 0.78.38 — Enterprise Operational Readiness Review

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS enterprise_operational_readiness_domains (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, domain_key VARCHAR(160) NOT NULL, domain_label VARCHAR(255) NOT NULL, owner_role VARCHAR(80) NOT NULL DEFAULT 'admin', required_flag TINYINT(1) NOT NULL DEFAULT 1, active TINYINT(1) NOT NULL DEFAULT 1, sort_order INT NOT NULL DEFAULT 100, evidence_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NULL, PRIMARY KEY(id), UNIQUE KEY uq_enterprise_operational_readiness_domains_key (domain_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS enterprise_operational_readiness_items (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, domain_key VARCHAR(160) NOT NULL, item_key VARCHAR(160) NOT NULL, item_label VARCHAR(255) NOT NULL, status VARCHAR(40) NOT NULL DEFAULT 'pending', severity VARCHAR(40) NOT NULL DEFAULT 'major', owner_role VARCHAR(80) NOT NULL DEFAULT 'admin', evidence_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NULL, PRIMARY KEY(id), UNIQUE KEY uq_enterprise_operational_readiness_items_key (domain_key,item_key), KEY idx_enterprise_operational_readiness_items_status (status,severity)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS enterprise_operational_readiness_reviews (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, review_uuid VARCHAR(80) NOT NULL, status VARCHAR(40) NOT NULL DEFAULT 'HOLD', score INT NOT NULL DEFAULT 0, critical_blockers INT NOT NULL DEFAULT 0, warning_count INT NOT NULL DEFAULT 0, evidence_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NULL, PRIMARY KEY(id), UNIQUE KEY uq_enterprise_operational_readiness_reviews_uuid (review_uuid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS enterprise_operational_readiness_runs (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, run_uuid VARCHAR(80) NOT NULL, run_type VARCHAR(60) NOT NULL DEFAULT 'manual', status VARCHAR(40) NOT NULL DEFAULT 'completed', domains_seeded INT NOT NULL DEFAULT 0, items_seeded INT NOT NULL DEFAULT 0, evidence_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NULL, PRIMARY KEY(id), UNIQUE KEY uq_enterprise_operational_readiness_runs_run (run_uuid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO app_settings (setting_key,setting_value,created_at,updated_at) VALUES ('core_version_07838', '1', NOW(), NOW()) ON DUPLICATE KEY UPDATE setting_value='1', updated_at=NOW();

INSERT INTO app_settings (setting_key,setting_value,created_at,updated_at) VALUES ('enterprise_operational_readiness_auto_go_live_enabled', '0', NOW(), NOW()) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value), updated_at=NOW();

INSERT INTO app_settings (setting_key,setting_value,created_at,updated_at) VALUES ('enterprise_operational_readiness_auto_assign_owner_enabled', '0', NOW(), NOW()) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value), updated_at=NOW();

INSERT INTO app_settings (setting_key,setting_value,created_at,updated_at) VALUES ('enterprise_operational_readiness_auto_patient_message_enabled', '0', NOW(), NOW()) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value), updated_at=NOW();

INSERT INTO app_settings (setting_key,setting_value,created_at,updated_at) VALUES ('enterprise_operational_readiness_cron_enabled', '0', NOW(), NOW()) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value), updated_at=NOW();
