You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
612 B
SQL
17 lines
612 B
SQL
-- Create the sessions table.
|
|
-- session_hash is the PRIMARY KEY (SHA-256 hash of the raw session token).
|
|
-- The raw token is never stored; only the hash.
|
|
|
|
CREATE TABLE sessions (
|
|
session_hash TEXT PRIMARY KEY,
|
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
expires_at TIMESTAMPTZ NOT NULL,
|
|
last_active_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
ip_address TEXT,
|
|
user_agent TEXT
|
|
);
|
|
|
|
CREATE INDEX idx_sessions_user_id ON sessions(user_id);
|
|
CREATE INDEX idx_sessions_expires_at ON sessions(expires_at);
|