-- Create database (run manually or via script if user has permissions)
-- CREATE DATABASE test_upgrade;

-- Connect to test_upgrade before running the following:

CREATE TABLE IF NOT EXISTS upgrade_log (
    uuid UUID NOT NULL,
    start_time TIMESTAMP NOT NULL,
    roomtype_id INTEGER NOT NULL,
    host_str TEXT NOT NULL,
    filename TEXT NOT NULL,
    status TEXT,
    end_time TIMESTAMP,
    file_type TEXT,
    config_version TEXT,
    firmware_version TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS upgrade_state (
    state_key TEXT PRIMARY KEY,
    current_roomtype_index INTEGER DEFAULT 0,
    execution_count INTEGER DEFAULT 0,
    last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
