-- AUTO TESTER - System Monitoring Migration
-- Created: 2026-04-22
-- Description: Comprehensive system monitoring and backup tables

-- ============================================
-- 1. System Monitoring Tables
-- ============================================

-- System Performance Metrics
CREATE TABLE IF NOT EXISTS `system_performance_metrics` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `metric_type` ENUM('cpu', 'memory', 'disk', 'database', 'api_response_time', 'user_sessions', 'error_rate') NOT NULL,
    `metric_value` DECIMAL(10,2) NOT NULL,
    `metric_unit` VARCHAR(20) COMMENT 'Unit of measurement (%, MB, GB, ms, count)',
    `server_name` VARCHAR(100) DEFAULT 'main_server',
    `component` VARCHAR(100) COMMENT 'Specific component being monitored',
    `threshold_warning` DECIMAL(10,2) COMMENT 'Warning threshold',
    `threshold_critical` DECIMAL(10,2) COMMENT 'Critical threshold',
    `status` ENUM('normal', 'warning', 'critical') DEFAULT 'normal',
    `additional_data` JSON COMMENT 'Additional metric data',
    `recorded_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    
    INDEX `idx_metric_type` (`metric_type`),
    INDEX `idx_recorded_at` (`recorded_at`),
    INDEX `idx_status` (`status`),
    INDEX `idx_component` (`component`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- System Alerts and Notifications
CREATE TABLE IF NOT EXISTS `system_alerts` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `alert_type` ENUM('performance', 'security', 'database', 'backup', 'api', 'system') NOT NULL,
    `alert_level` ENUM('info', 'warning', 'critical', 'emergency') NOT NULL,
    `alert_title` VARCHAR(255) NOT NULL,
    `alert_message` TEXT NOT NULL,
    `alert_source` VARCHAR(100) COMMENT 'Source of the alert',
    `component_affected` VARCHAR(100),
    `metric_data` JSON COMMENT 'Related metric data',
    `resolution_status` ENUM('open', 'investigating', 'resolved', 'false_positive') DEFAULT 'open',
    `resolution_notes` TEXT,
    `resolved_by` INT COMMENT 'User who resolved the alert',
    `resolved_at` DATETIME,
    `auto_resolved` BOOLEAN DEFAULT FALSE,
    `notification_sent` BOOLEAN DEFAULT FALSE,
    `notification_channels` JSON COMMENT 'Channels used for notification',
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    
    FOREIGN KEY (`resolved_by`) REFERENCES `users`(`id`) ON DELETE SET NULL,
    
    INDEX `idx_alert_type` (`alert_type`),
    INDEX `idx_alert_level` (`alert_level`),
    INDEX `idx_resolution_status` (`resolution_status`),
    INDEX `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- API Request Logging
CREATE TABLE IF NOT EXISTS `api_request_logs` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `request_id` VARCHAR(50) UNIQUE NOT NULL COMMENT 'Unique request identifier',
    `endpoint` VARCHAR(255) NOT NULL,
    `method` ENUM('GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS') NOT NULL,
    `request_ip` VARCHAR(45),
    `user_agent` TEXT,
    `user_id` INT COMMENT 'Authenticated user ID',
    `user_role` VARCHAR(50),
    `request_size` INT COMMENT 'Request size in bytes',
    `response_status` INT NOT NULL,
    `response_size` INT COMMENT 'Response size in bytes',
    `response_time_ms` INT NOT NULL COMMENT 'Response time in milliseconds',
    `error_message` TEXT,
    `request_data` JSON COMMENT 'Request data (sanitized)',
    `response_data` JSON COMMENT 'Response data (sanitized)',
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    
    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE SET NULL,
    
    INDEX `idx_endpoint` (`endpoint`),
    INDEX `idx_method` (`method`),
    INDEX `idx_response_status` (`response_status`),
    INDEX `idx_response_time_ms` (`response_time_ms`),
    INDEX `idx_created_at` (`created_at`),
    INDEX `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Database Query Performance
CREATE TABLE IF NOT EXISTS `database_query_logs` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `query_id` VARCHAR(50) UNIQUE NOT NULL,
    `query_type` ENUM('SELECT', 'INSERT', 'UPDATE', 'DELETE', 'ALTER', 'CREATE', 'DROP') NOT NULL,
    `table_name` VARCHAR(100),
    `query_hash` VARCHAR(64) COMMENT 'Hash of the query for grouping similar queries',
    `query_template` TEXT COMMENT 'Parameterized query template',
    `execution_time_ms` INT NOT NULL,
    `rows_affected` INT,
    `rows_examined` INT,
    `index_used` VARCHAR(100),
    `query_explain` JSON COMMENT 'EXPLAIN result for SELECT queries',
    `user_id` INT,
    `session_id` VARCHAR(100),
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    
    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE SET NULL,
    
    INDEX `idx_query_type` (`query_type`),
    INDEX `idx_table_name` (`table_name`),
    INDEX `idx_execution_time_ms` (`execution_time_ms`),
    INDEX `idx_created_at` (`created_at`),
    INDEX `idx_query_hash` (`query_hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ============================================
-- 2. Backup and Recovery Tables
-- ============================================

-- Backup Jobs
CREATE TABLE IF NOT EXISTS `backup_jobs` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `job_name` VARCHAR(100) UNIQUE NOT NULL,
    `backup_type` ENUM('full', 'incremental', 'differential') NOT NULL,
    `backup_target` ENUM('database', 'files', 'system') NOT NULL,
    `backup_source` VARCHAR(255) NOT NULL COMMENT 'Database name or file path',
    `backup_destination` VARCHAR(500) NOT NULL COMMENT 'Backup storage location',
    `compression` ENUM('none', 'gzip', 'zip', 'bzip2') DEFAULT 'gzip',
    `encryption` BOOLEAN DEFAULT FALSE,
    `encryption_key` VARCHAR(255) COMMENT 'Encrypted encryption key',
    `schedule_type` ENUM('manual', 'daily', 'weekly', 'monthly', 'hourly') NOT NULL,
    `schedule_expression` VARCHAR(100) COMMENT 'Cron expression or schedule details',
    `retention_days` INT DEFAULT 30 COMMENT 'How many days to keep backups',
    `max_backup_size_gb` DECIMAL(10,2) COMMENT 'Maximum backup size in GB',
    `pre_backup_commands` JSON COMMENT 'Commands to run before backup',
    `post_backup_commands` JSON COMMENT 'Commands to run after backup',
    `notification_on_success` BOOLEAN DEFAULT TRUE,
    `notification_on_failure` BOOLEAN DEFAULT TRUE,
    `notification_emails` JSON COMMENT 'Email addresses for notifications',
    `is_active` BOOLEAN DEFAULT TRUE,
    `last_run_at` DATETIME,
    `next_run_at` DATETIME,
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    
    INDEX `idx_backup_type` (`backup_type`),
    INDEX `idx_backup_target` (`backup_target`),
    INDEX `idx_schedule_type` (`schedule_type`),
    INDEX `idx_is_active` (`is_active`),
    INDEX `idx_next_run_at` (`next_run_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Backup Execution History
CREATE TABLE IF NOT EXISTS `backup_executions` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `backup_job_id` INT NOT NULL,
    `execution_id` VARCHAR(50) UNIQUE NOT NULL,
    `status` ENUM('running', 'completed', 'failed', 'cancelled') NOT NULL,
    `started_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    `completed_at` DATETIME,
    `duration_seconds` INT,
    `backup_size_bytes` BIGINT,
    `backup_size_compressed_bytes` BIGINT,
    `compression_ratio` DECIMAL(5,2),
    `files_count` INT,
    `error_message` TEXT,
    `error_details` JSON COMMENT 'Detailed error information',
    `backup_path` VARCHAR(500),
    `checksum_md5` VARCHAR(32),
    `checksum_sha256` VARCHAR(64),
    `verification_status` ENUM('verified', 'failed', 'not_verified') DEFAULT 'not_verified',
    `restored_tested` BOOLEAN DEFAULT FALSE COMMENT 'If backup was tested via restoration',
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    
    FOREIGN KEY (`backup_job_id`) REFERENCES `backup_jobs`(`id`) ON DELETE CASCADE,
    
    INDEX `idx_backup_job_id` (`backup_job_id`),
    INDEX `idx_status` (`status`),
    INDEX `idx_started_at` (`started_at`),
    INDEX `idx_verification_status` (`verification_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Disaster Recovery Plans
CREATE TABLE IF NOT EXISTS `disaster_recovery_plans` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `plan_name` VARCHAR(100) UNIQUE NOT NULL,
    `plan_type` ENUM('database', 'application', 'infrastructure', 'full_system') NOT NULL,
    `description` TEXT,
    `rto_minutes` INT COMMENT 'Recovery Time Objective in minutes',
    `rpo_minutes` INT COMMENT 'Recovery Point Objective in minutes',
    `priority_level` ENUM('low', 'medium', 'high', 'critical') NOT NULL,
    `backup_requirements` JSON COMMENT 'Required backups for recovery',
    `recovery_steps` JSON COMMENT 'Step-by-step recovery procedures',
    `contact_personnel` JSON COMMENT 'Emergency contact information',
    `external_dependencies` JSON COMMENT 'External systems and dependencies',
    `test_frequency_days` INT DEFAULT 30 COMMENT 'How often to test the plan',
    `last_tested_at` DATETIME,
    `last_test_result` ENUM('success', 'failure', 'partial') COMMENT 'Result of last test',
    `test_notes` TEXT,
    `is_active` BOOLEAN DEFAULT TRUE,
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    
    INDEX `idx_plan_type` (`plan_type`),
    INDEX `idx_priority_level` (`priority_level`),
    INDEX `idx_is_active` (`is_active`),
    INDEX `idx_last_tested_at` (`last_tested_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ============================================
-- 3. Security Audit Tables
-- ============================================

-- Security Audit Log
CREATE TABLE IF NOT EXISTS `security_audit_log` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `event_type` ENUM('login', 'logout', 'permission_change', 'data_access', 'config_change', 'security_violation', 'failed_login', 'password_change', 'api_access') NOT NULL,
    `event_level` ENUM('info', 'warning', 'critical') NOT NULL,
    `user_id` INT,
    `username` VARCHAR(100),
    `ip_address` VARCHAR(45),
    `user_agent` TEXT,
    `session_id` VARCHAR(100),
    `resource_accessed` VARCHAR(255),
    `action_performed` VARCHAR(255),
    `old_values` JSON COMMENT 'Previous values for updates',
    `new_values` JSON COMMENT 'New values for updates',
    `success` BOOLEAN DEFAULT TRUE,
    `failure_reason` VARCHAR(255),
    `additional_data` JSON,
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    
    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE SET NULL,
    
    INDEX `idx_event_type` (`event_type`),
    INDEX `idx_event_level` (`event_level`),
    INDEX `idx_user_id` (`user_id`),
    INDEX `idx_ip_address` (`ip_address`),
    INDEX `idx_created_at` (`created_at`),
    INDEX `idx_success` (`success`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Failed Login Attempts
CREATE TABLE IF NOT EXISTS `failed_login_attempts` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `username` VARCHAR(100) NOT NULL,
    `ip_address` VARCHAR(45) NOT NULL,
    `user_agent` TEXT,
    `attempt_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
    `failure_reason` ENUM('invalid_username', 'invalid_password', 'account_locked', 'rate_limit', 'other') NOT NULL,
    `is_blocked` BOOLEAN DEFAULT FALSE COMMENT 'If IP is temporarily blocked',
    `block_expires_at` DATETIME,
    `session_id` VARCHAR(100),
    
    INDEX `idx_username` (`username`),
    INDEX `idx_ip_address` (`ip_address`),
    INDEX `idx_attempt_time` (`attempt_time`),
    INDEX `idx_is_blocked` (`is_blocked`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ============================================
-- 4. System Configuration and Health
-- ============================================

-- System Configuration History
CREATE TABLE IF NOT EXISTS `system_config_history` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `config_key` VARCHAR(100) NOT NULL,
    `config_value` TEXT,
    `config_type` ENUM('database', 'application', 'security', 'performance', 'feature') NOT NULL,
    `old_value` TEXT,
    `new_value` TEXT,
    `change_reason` VARCHAR(255),
    `changed_by` INT,
    `change_source` VARCHAR(100) COMMENT 'Source of change (manual, migration, script)',
    `impact_assessment` VARCHAR(255),
    `rollback_available` BOOLEAN DEFAULT FALSE,
    `rollback_instructions` TEXT,
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    
    FOREIGN KEY (`changed_by`) REFERENCES `users`(`id`) ON DELETE SET NULL,
    
    INDEX `idx_config_key` (`config_key`),
    INDEX `idx_config_type` (`config_type`),
    INDEX `idx_changed_by` (`changed_by`),
    INDEX `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- System Health Status
CREATE TABLE IF NOT EXISTS `system_health_status` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `component_name` VARCHAR(100) NOT NULL,
    `component_type` ENUM('database', 'api', 'frontend', 'storage', 'network', 'external_service') NOT NULL,
    `status` ENUM('healthy', 'degraded', 'unhealthy', 'unknown') NOT NULL,
    `response_time_ms` INT,
    `uptime_percentage` DECIMAL(5,2),
    `error_rate` DECIMAL(5,2),
    `last_check_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    `status_duration_minutes` INT COMMENT 'How long current status has persisted',
    `health_metrics` JSON COMMENT 'Detailed health metrics',
    `dependencies` JSON COMMENT 'Dependencies this component has',
    `affected_services` JSON COMMENT 'Services affected by this component',
    `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
    `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    
    UNIQUE KEY `unique_component` (`component_name`, `component_type`),
    INDEX `idx_component_type` (`component_type`),
    INDEX `idx_status` (`status`),
    INDEX `idx_last_check_at` (`last_check_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ============================================
-- 5. Insert Default Data
-- ============================================

-- Default Backup Jobs
INSERT INTO `backup_jobs` (`job_name`, `backup_type`, `backup_target`, `backup_source`, `backup_destination`, `schedule_type`, `schedule_expression`, `retention_days`) VALUES
('daily_database_backup', 'full', 'database', 'autotester_db', '/backups/database/', 'daily', '0 2 * * *', 30),
('weekly_full_backup', 'full', 'system', '/var/www/autotester', '/backups/full/', 'weekly', '0 3 * * 0', 90),
('hourly_config_backup', 'incremental', 'files', '/var/www/autotester/config', '/backups/config/', 'hourly', '0 * * * *', 7),
('monthly_archive_backup', 'full', 'system', '/var/www/autotester', '/backups/archive/', 'monthly', '0 4 1 * *', 365);

-- Default Disaster Recovery Plans
INSERT INTO `disaster_recovery_plans` (`plan_name`, `plan_type`, `description`, `rto_minutes`, `rpo_minutes`, `priority_level`) VALUES
('database_recovery', 'database', 'Complete database recovery from backups', 60, 15, 'critical'),
('application_recovery', 'application', 'Application deployment and configuration recovery', 120, 30, 'critical'),
('full_system_recovery', 'full_system', 'Complete system recovery including all components', 240, 60, 'high');

-- Default System Health Components
INSERT INTO `system_health_status` (`component_name`, `component_type`, `status`) VALUES
('main_database', 'database', 'healthy'),
('api_server', 'api', 'healthy'),
('web_frontend', 'frontend', 'healthy'),
('file_storage', 'storage', 'healthy'),
('payment_gateway', 'external_service', 'unknown'),
('email_service', 'external_service', 'unknown');

-- ============================================
-- 6. Create Views for Monitoring
-- ============================================

-- System Performance Summary View
CREATE VIEW `system_performance_summary` AS
SELECT 
    DATE(recorded_at) as performance_date,
    metric_type,
    AVG(metric_value) as avg_value,
    MIN(metric_value) as min_value,
    MAX(metric_value) as max_value,
    COUNT(*) as measurement_count,
    SUM(CASE WHEN status = 'critical' THEN 1 ELSE 0 END) as critical_count,
    SUM(CASE WHEN status = 'warning' THEN 1 ELSE 0 END) as warning_count
FROM system_performance_metrics
WHERE recorded_at >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY)
GROUP BY DATE(recorded_at), metric_type
ORDER BY performance_date DESC, metric_type;

-- API Performance Summary View
CREATE VIEW `api_performance_summary` AS
SELECT 
    DATE(created_at) as api_date,
    endpoint,
    method,
    COUNT(*) as request_count,
    AVG(response_time_ms) as avg_response_time,
    MIN(response_time_ms) as min_response_time,
    MAX(response_time_ms) as max_response_time,
    SUM(CASE WHEN response_status >= 400 THEN 1 ELSE 0 END) as error_count,
    ROUND(SUM(CASE WHEN response_status >= 400 THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 2) as error_rate
FROM api_request_logs
WHERE created_at >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)
GROUP BY DATE(created_at), endpoint, method
ORDER BY api_date DESC, error_rate DESC;

-- Backup Status Summary View
CREATE VIEW `backup_status_summary` AS
SELECT 
    bj.job_name,
    bj.backup_type,
    bj.schedule_type,
    COUNT(be.id) as total_executions,
    SUM(CASE WHEN be.status = 'completed' THEN 1 ELSE 0 END) as successful_executions,
    SUM(CASE WHEN be.status = 'failed' THEN 1 ELSE 0 END) as failed_executions,
    ROUND(SUM(CASE WHEN be.status = 'completed' THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 2) as success_rate,
    AVG(be.duration_seconds) as avg_duration_seconds,
    AVG(be.backup_size_bytes) as avg_backup_size_bytes,
    MAX(be.started_at) as last_execution,
    bj.next_run_at
FROM backup_jobs bj
LEFT JOIN backup_executions be ON bj.id = be.backup_job_id
WHERE bj.is_active = 1
GROUP BY bj.id, bj.job_name, bj.backup_type, bj.schedule_type, bj.next_run_at
ORDER BY bj.job_name;

-- ============================================
-- 7. Create Triggers for Automatic Monitoring
-- ============================================

DELIMITER $$

-- Trigger for API Request Logging
CREATE TRIGGER `trigger_api_request_cleanup`
AFTER INSERT ON `api_request_logs`
FOR EACH ROW
BEGIN
    -- Clean up old API logs (keep last 30 days)
    DELETE FROM api_request_logs 
    WHERE created_at < DATE_SUB(NOW(), INTERVAL 30 DAY)
    AND id NOT IN (
        SELECT id FROM (
            SELECT id FROM api_request_logs 
            WHERE created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)
            ORDER BY created_at DESC
            LIMIT 10000
        ) as recent_logs
    );
END$$

-- Trigger for Performance Alert Generation
CREATE TRIGGER `trigger_performance_alert`
AFTER INSERT ON `system_performance_metrics`
FOR EACH ROW
BEGIN
    IF NEW.status = 'critical' THEN
        INSERT INTO system_alerts 
        (alert_type, alert_level, alert_title, alert_message, alert_source, component_affected, metric_data)
        VALUES (
            'performance',
            'critical',
            CONCAT('Critical Performance Alert: ', NEW.component),
            CONCAT('Component ', NEW.component, ' has reached critical performance levels with value ', NEW.metric_value, NEW.metric_unit),
            'system_monitoring',
            NEW.component,
            JSON_OBJECT('metric_type', NEW.metric_type, 'value', NEW.metric_value, 'unit', NEW.metric_unit, 'threshold', NEW.threshold_critical)
        );
    ELSEIF NEW.status = 'warning' THEN
        INSERT INTO system_alerts 
        (alert_type, alert_level, alert_title, alert_message, alert_source, component_affected, metric_data)
        VALUES (
            'performance',
            'warning',
            CONCAT('Performance Warning: ', NEW.component),
            CONCAT('Component ', NEW.component, ' has reached warning levels with value ', NEW.metric_value, NEW.metric_unit),
            'system_monitoring',
            NEW.component,
            JSON_OBJECT('metric_type', NEW.metric_type, 'value', NEW.metric_value, 'unit', NEW.metric_unit, 'threshold', NEW.threshold_warning)
        );
    END IF;
END$$

DELIMITER ;

-- ============================================
-- Migration Complete
-- ============================================

-- Log the migration
INSERT INTO system_logs (log_type, message, details, created_at) VALUES
('migration', 'System monitoring and backup migration completed', JSON_OBJECT(
    'migration_version', '006',
    'tables_created', 11,
    'views_created', 3,
    'triggers_created', 2,
    'backup_jobs_inserted', 4,
    'disaster_plans_inserted', 3,
    'health_components_inserted', 5,
    'migration_date', CURRENT_TIMESTAMP
), CURRENT_TIMESTAMP);
