-- Baltique OS Core 0.78.37 — Enterprise Data Migration Dry Run

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS enterprise_data_migration_sources (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, source_key VARCHAR(160) NOT NULL, source_label VARCHAR(255) NOT NULL, source_type VARCHAR(80) NOT NULL DEFAULT 'legacy', status VARCHAR(40) NOT NULL DEFAULT 'mapped', mapping_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NULL, PRIMARY KEY(id), UNIQUE KEY uq_enterprise_data_migration_sources_key (source_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS enterprise_data_migration_dry_runs (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, run_uuid VARCHAR(80) NOT NULL, source_key VARCHAR(160) NOT NULL, status VARCHAR(40) NOT NULL DEFAULT 'completed', scanned_rows INT NOT NULL DEFAULT 0, valid_rows INT NOT NULL DEFAULT 0, warning_rows INT NOT NULL DEFAULT 0, error_rows 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_data_migration_dry_runs_uuid (run_uuid), KEY idx_enterprise_data_migration_dry_runs_source (source_key, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS enterprise_data_migration_findings (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, run_uuid VARCHAR(80) NOT NULL, finding_key VARCHAR(160) NOT NULL, severity VARCHAR(40) NOT NULL DEFAULT 'warning', source_table VARCHAR(120) NULL, source_id VARCHAR(120) NULL, message TEXT NULL, remediation TEXT NULL, evidence_json JSON NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(id), KEY idx_enterprise_data_migration_findings_run (run_uuid, severity)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS enterprise_data_migration_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', sources_seeded INT NOT NULL DEFAULT 0, findings_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_data_migration_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_07837', '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_data_migration_auto_import_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_data_migration_auto_overwrite_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_data_migration_auto_delete_source_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_data_migration_cron_enabled', '0', NOW(), NOW()) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value), updated_at=NOW();
