CREATE TABLE IF NOT EXISTS users (
    username TEXT PRIMARY KEY NOT NULL,
    key TEXT NOT NULL,
    created_at INTEGER NOT NULL DEFAULT (unixepoch())
);

CREATE TABLE IF NOT EXISTS progress (
    username TEXT NOT NULL,
    document TEXT NOT NULL,
    percentage REAL,
    progress TEXT,
    device TEXT,
    device_id TEXT,
    timestamp INTEGER,
    PRIMARY KEY (username, document),
    FOREIGN KEY (username) REFERENCES users(username) ON DELETE CASCADE
);

CREATE INDEX IF NOT EXISTS idx_progress_username ON progress(username);
