-- 011_token_security.sql: Token rotation and revocation tracking

CREATE TABLE IF NOT EXISTS revoked_token_families (
    family      TEXT NOT NULL PRIMARY KEY,
    user_id     INTEGER NOT NULL,
    revoked_at  TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS refresh_tokens (
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id     INTEGER NOT NULL,
    family      TEXT NOT NULL,
    created_at  TEXT NOT NULL DEFAULT (datetime('now')),
    expires_at  TEXT NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_revoked_families_user ON revoked_token_families(user_id);
CREATE INDEX IF NOT EXISTS idx_refresh_tokens_user ON refresh_tokens(user_id);
