user_sessions table

The user_sessions table in the Reddit Clone Database Schema schema has 9 columns, keyed by id, with 2 foreign keys to users and user_devices.

Only the hash of the token is stored. Revocation is a timestamp rather than a delete, so a forced logout leaves evidence and the session list can show what was ended and when.

Columns (9)

Columns of the user_sessions table
ColumnTypeConstraintsDescription
iduuidprimary key
user_iduuidnot null, references users.id
token_hashvarchar(255)unique, not null
device_iduuidreferences user_devices.id
ip_addressvarchar(45)
user_agentvarchar(500)
created_attimestamptznot null
expires_attimestamptznot null
revoked_attimestamptz

Indexes (1)

  • (user_id, expires_at)

Relationships