-- Pixmenia v22 phpMyAdmin safe additive schema
-- Use this when updating production through phpMyAdmin.
-- This file only creates missing guard tables and settings. It does not overwrite customer data.

CREATE TABLE IF NOT EXISTS `schema_migrations` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `migration_key` VARCHAR(150) NOT NULL UNIQUE,
  `applied_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `asset_repair_logs` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `checked_count` INT NOT NULL DEFAULT 0,
  `fixed_count` INT NOT NULL DEFAULT 0,
  `missing_count` INT NOT NULL DEFAULT 0,
  `report_json` LONGTEXT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `system_update_warnings` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `warning_key` VARCHAR(120) NOT NULL UNIQUE,
  `warning_text` TEXT NOT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `system_update_warnings` (`warning_key`, `warning_text`) VALUES
('phpmyadmin_safe_mode','This database is protected for additive phpMyAdmin updates. Use additive updates only on customer tables.')
ON DUPLICATE KEY UPDATE `warning_text`=VALUES(`warning_text`);

INSERT INTO `schema_migrations` (`migration_key`) VALUES ('v22_phpmyadmin_safe_mode')
ON DUPLICATE KEY UPDATE `migration_key`=VALUES(`migration_key`);
