-- The account that logs in to the web UI. The first visit to the UI creates it. CREATE TABLE "app_user" ( id UUID NOT NULL PRIMARY KEY, username VARCHAR(64) NOT NULL UNIQUE, password_hash TEXT NOT NULL, -- Argon2id, in PHC string format listenbrainz_token TEXT, -- Used for Listenbrainz endpoints that need one (e.g. LB Radio) listenbrainz_user VARCHAR(250), -- The Listenbrainz user the token belongs to created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); -- Logged in browsers. Only a hash of the session token is stored. CREATE TABLE "user_session" ( token_hash BYTEA NOT NULL PRIMARY KEY, -- SHA-256 of the token in the session cookie user_id UUID NOT NULL REFERENCES "app_user" (id) ON DELETE CASCADE, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), expires_at TIMESTAMPTZ NOT NULL ); CREATE INDEX "user_session_expires_at" ON "user_session" (expires_at);