-- Baltique OS Core 0.78.33 — Performance / OVH Cache Guard
-- Reference migration. Runtime PHP upgrade performs idempotent schema checks.

CREATE TABLE IF NOT EXISTS enterprise_performance_cache_policies (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  policy_key VARCHAR(160) NOT NULL,
  policy_label VARCHAR(255) NOT NULL,
  scope_key VARCHAR(120) NOT NULL,
  ttl_seconds INT NOT NULL DEFAULT 60,
  batch_limit INT NOT NULL DEFAULT 100,
  enabled TINYINT(1) NOT NULL DEFAULT 1,
  description TEXT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL,
  PRIMARY KEY(id),
  KEY idx_enterprise_performance_cache_policies_first (policy_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS enterprise_performance_query_snapshots (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  snapshot_key VARCHAR(160) NOT NULL,
  metric_key VARCHAR(120) NOT NULL,
  metric_value DECIMAL(18,4) NULL,
  status VARCHAR(40) NOT NULL DEFAULT 'observed',
  evidence_json JSON NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL,
  PRIMARY KEY(id),
  KEY idx_enterprise_performance_query_snapshots_first (snapshot_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS enterprise_performance_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',
  policies_seeded INT NOT NULL DEFAULT 0,
  snapshots_written INT NOT NULL DEFAULT 0,
  evidence_json JSON NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL,
  PRIMARY KEY(id),
  KEY idx_enterprise_performance_runs_first (run_uuid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
