-- ============================================================================
-- eDNC Special Character Fix - Database Tables
-- Run on PRODUCTION database to enable eDNC logging
-- Created: 2025-12-12
-- ============================================================================

-- Log individual events (cleaned, failed, started, stopped, etc.)
CREATE TABLE IF NOT EXISTS ednc_logs (
    logid INT AUTO_INCREMENT PRIMARY KEY,
    hostname VARCHAR(50) NOT NULL,
    filename VARCHAR(255) NOT NULL,
    action ENUM('cleaned', 'ok', 'failed', 'error', 'started', 'stopped') NOT NULL,
    bytes_removed INT DEFAULT 0,
    version VARCHAR(20),
    message VARCHAR(500),
    created DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_hostname (hostname),
    INDEX idx_created (created),
    INDEX idx_action (action)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Track installations per PC
CREATE TABLE IF NOT EXISTS ednc_installations (
    installid INT AUTO_INCREMENT PRIMARY KEY,
    hostname VARCHAR(50) NOT NULL UNIQUE,
    version VARCHAR(20),
    watch_folder VARCHAR(255),
    file_filter VARCHAR(50),
    first_seen DATETIME DEFAULT CURRENT_TIMESTAMP,
    last_seen DATETIME DEFAULT CURRENT_TIMESTAMP,
    is_active TINYINT(1) DEFAULT 1,
    total_cleaned INT DEFAULT 0,
    total_failed INT DEFAULT 0,
    INDEX idx_hostname (hostname),
    INDEX idx_active (is_active)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Verify tables created
SELECT 'ednc_logs' AS table_name, COUNT(*) AS row_count FROM ednc_logs
UNION ALL
SELECT 'ednc_installations', COUNT(*) FROM ednc_installations;
