-- Migration: Add new columns to competitor_secret_formulas for enhanced analysis -- Run this once to upgrade the table schema ALTER TABLE `competitor_secret_formulas` ADD COLUMN `tier` VARCHAR(20) DEFAULT 'standard' AFTER `country_code`, ADD COLUMN `min_fare` DECIMAL(8,3) DEFAULT 0 AFTER `price_per_min`, ADD COLUMN `rmse` DECIMAL(10,4) DEFAULT 0 AFTER `min_fare`, ADD COLUMN `r_squared` DECIMAL(10,4) DEFAULT 0 AFTER `rmse`, ADD COLUMN `surge_multiplier` DECIMAL(5,3) DEFAULT 1.0 AFTER `r_squared`, ADD COLUMN `peak_hours` VARCHAR(255) DEFAULT '[]' AFTER `surge_multiplier`; -- Make the unique key include tier for multi-tier support ALTER TABLE `competitor_secret_formulas` DROP INDEX `idx_comp_country`, ADD UNIQUE KEY `idx_comp_country_tier` (`competitor_name`, `country_code`, `tier`); -- New table for surge insights CREATE TABLE IF NOT EXISTS `competitor_surge_insights` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `competitor_name` VARCHAR(100) NOT NULL, `country_code` VARCHAR(5) NOT NULL, `surge_multiplier` DECIMAL(5,3) NOT NULL, `peak_start_hour` INT NOT NULL, `peak_end_hour` INT NOT NULL, `sample_count` INT NOT NULL, `detected_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY `unique_surge` (`competitor_name`, `country_code`, `peak_start_hour`, `peak_end_hour`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;