-- Baltique OS Core 0.78.43 — Enterprise Background Jobs & Cron Governance
-- Reference SQL. Runtime upgrade is idempotent and schema-safe.
CREATE TABLE IF NOT EXISTS enterprise_cron_governance_jobs (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, job_key VARCHAR(120) NOT NULL, job_label VARCHAR(190) NOT NULL, route_path VARCHAR(255) NULL, status VARCHAR(40) NOT NULL DEFAULT 'disabled', owner_role VARCHAR(80) NOT NULL DEFAULT 'admin', cooldown_seconds INT NOT NULL DEFAULT 300, batch_limit INT NOT NULL DEFAULT 50, evidence_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NULL, PRIMARY KEY(id), UNIQUE KEY uq_enterprise_cron_governance_jobs_key (job_key), KEY idx_enterprise_cron_governance_jobs_status (status)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS enterprise_cron_governance_locks (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, job_key VARCHAR(120) NOT NULL, lock_token VARCHAR(120) NOT NULL, locked_until DATETIME NOT NULL, status VARCHAR(40) NOT NULL DEFAULT 'active', evidence_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NULL, PRIMARY KEY(id), UNIQUE KEY uq_enterprise_cron_governance_locks_job (job_key,status)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS enterprise_cron_governance_runs (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, run_uuid VARCHAR(80) NOT NULL, job_key VARCHAR(120) NULL, status VARCHAR(40) NOT NULL DEFAULT 'OK', jobs_registered INT NOT NULL DEFAULT 0, enabled_jobs 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_cron_governance_runs_uuid (run_uuid)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
