-- Admin flag and rotating refresh tokens. ALTER TABLE users ADD COLUMN is_admin INTEGER NOT NULL DEFAULT 0; -- Accounts that already exist: the oldest one becomes the admin. UPDATE users SET is_admin = 1 WHERE id = (SELECT MIN(id) FROM users); -- Only a hash of the token is stored, never the token itself. CREATE TABLE refresh_tokens ( id INTEGER PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, token_hash TEXT NOT NULL UNIQUE, -- SHA-256 of the token, hex created_at INTEGER NOT NULL, -- unix seconds expires_at INTEGER NOT NULL, -- unix seconds revoked_at INTEGER -- unix seconds, NULL while active ); CREATE INDEX idx_refresh_tokens_user ON refresh_tokens(user_id);