-- Backup Configuration Table
CREATE TABLE IF NOT EXISTS backup_config (
    id INT AUTO_INCREMENT PRIMARY KEY,
    backup_type VARCHAR(20) NOT NULL DEFAULT 'database',
    frequency VARCHAR(20) NOT NULL DEFAULT 'daily',
    backup_time TIME NOT NULL DEFAULT '02:00:00',
    retention_days INT NOT NULL DEFAULT 30,
    storage_location VARCHAR(255) NOT NULL DEFAULT '../backups/',
    storage_type VARCHAR(20) NOT NULL DEFAULT 'local',
    is_active TINYINT(1) NOT NULL DEFAULT 1,
    created_by INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY unique_config (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Backup History Table
CREATE TABLE IF NOT EXISTS backup_history (
    id INT AUTO_INCREMENT PRIMARY KEY,
    backup_type VARCHAR(20) NOT NULL,
    file_name VARCHAR(255) NOT NULL,
    file_path VARCHAR(500) NOT NULL,
    file_size BIGINT NOT NULL DEFAULT 0,
    status VARCHAR(20) NOT NULL DEFAULT 'completed',
    start_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    end_time TIMESTAMP NULL,
    is_deleted TINYINT(1) NOT NULL DEFAULT 0,
    error_message TEXT,
    INDEX idx_status (status),
    INDEX idx_deleted (is_deleted),
    INDEX idx_time (start_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
