-- Pivot Forecast — authentication -- Run after 01_schema.sql: psql -d -f setup_sql/02_auth.sql -- Safe to re-run. -- Application accounts. Passwords are scrypt hashes written by lib/auth.js; -- the plaintext never reaches the database. Manage with ./pf.sh add-user. CREATE TABLE IF NOT EXISTS pf.app_user ( id serial PRIMARY KEY, username text NOT NULL UNIQUE, pass_hash text NOT NULL, display_name text, is_active boolean NOT NULL DEFAULT true, created_at timestamptz NOT NULL DEFAULT now(), last_login_at timestamptz ); -- Session store for express-session (connect-pg-simple layout). Sessions live -- here rather than in memory so a restart doesn't sign everyone out, and so a -- session can be revoked by deleting its row. CREATE TABLE IF NOT EXISTS pf.session ( sid varchar PRIMARY KEY NOT NULL COLLATE "default", sess json NOT NULL, expire timestamp(6) NOT NULL ); CREATE INDEX IF NOT EXISTS session_expire_idx ON pf.session (expire);