CREATE TABLE IF NOT EXISTS urls (
    id INT AUTO_INCREMENT PRIMARY KEY,
    url VARCHAR(1024) NOT NULL,
    is_active TINYINT(1) DEFAULT 1,
    last_status VARCHAR(20) DEFAULT 'unknown', -- 'ok', 'error'
    last_latency FLOAT DEFAULT 0,
    last_checked_at TIMESTAMP NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS logs (
    id INT AUTO_INCREMENT PRIMARY KEY,
    url_id INT NOT NULL,
    status VARCHAR(20) NOT NULL,
    latency FLOAT DEFAULT 0,
    error_message TEXT DEFAULT NULL,
    checked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (url_id) REFERENCES urls(id) ON DELETE CASCADE
) ENGINE=InnoDB;
