-- Baltique OS Core 0.78.40 — Enterprise Observability & Error Console
-- Reference SQL. Runtime upgrade is idempotent and schema-safe.
CREATE TABLE IF NOT EXISTS enterprise_observability_sources (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, source_key VARCHAR(120) NOT NULL, source_label VARCHAR(190) NOT NULL, source_type VARCHAR(80) NOT NULL DEFAULT 'internal', status VARCHAR(40) NOT NULL DEFAULT 'active', severity VARCHAR(40) NOT NULL DEFAULT 'info', sample_path VARCHAR(255) NULL, pii_capture_enabled TINYINT(1) NOT NULL DEFAULT 0, retention_days INT NOT NULL DEFAULT 30, evidence_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NULL, PRIMARY KEY(id), UNIQUE KEY uq_enterprise_observability_sources_key (source_key), KEY idx_enterprise_observability_sources_status (status,severity)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS enterprise_observability_incidents (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, incident_uuid VARCHAR(80) NOT NULL, source_key VARCHAR(120) NOT NULL, severity VARCHAR(40) NOT NULL DEFAULT 'info', status VARCHAR(40) NOT NULL DEFAULT 'open', title VARCHAR(190) NOT NULL, message TEXT NULL, remediation TEXT NULL, evidence_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NULL, PRIMARY KEY(id), UNIQUE KEY uq_enterprise_observability_incidents_uuid (incident_uuid), KEY idx_enterprise_observability_incidents_status (status,severity)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS enterprise_observability_runs (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, run_uuid VARCHAR(80) NOT NULL, run_type VARCHAR(80) NOT NULL DEFAULT 'manual', status VARCHAR(40) NOT NULL DEFAULT 'OK', findings INT NOT NULL DEFAULT 0, critical_findings 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_observability_runs_uuid (run_uuid)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
