Tiesen LogoYuki UI

Database Concepts

Understanding the database structure and table relationships for the authentication system

The authentication system uses a simplified three-table structure to manage users, authentication accounts, and sessions.

Tables Overview

User Table

Stores core user information and profile data.

FieldTypeKeyDescription
idvarchar(24)PKUnique identifier for each user
namevarchar(100)INDEXUser's display name (required)
emailvarchar(255)UNIQUEUser's email address (required for authentication)
imagevarchar(500)URL to user's profile image
created_attimestampTimestamp when user account was created (auto-set)
updated_attimestampTimestamp when user data was last updated (auto-updated)

Primary Key: id
Unique Index: email
Index: name

Account Table

Links users to their authentication providers (OAuth or credentials).

FieldTypeKeyDescription
user_idvarchar(24)FK, INDEXReferences users.id - the user this account belongs to
providervarchar(50)Authentication provider name (google, github, discord, credentials)
account_idvarchar(100)Unique account ID from the provider or email for credentials
passwordtextHashed password (only for credentials provider, null for OAuth)

Primary Key: id
Foreign Key: user_id references users.id with cascade delete
Unique Index: (provider, account_id)
Index: user_id

Session Table

Manages user sessions for authentication state.

FieldTypeKeyDescription
idvarchar(24)PKUnique session row identifier
user_idvarchar(24)FK, INDEXReferences users.id - the user this session belongs to
tokenvarchar(64)Unique session token identifying the session
expires_attimestampTimestamp when session expires

Primary Key: id
Foreign Key: user_id references users.id with cascade delete
Unique Index: (id, token)
Index: user_id

Relationships

  • User → Account: One-to-Many (a user can have multiple auth methods: OAuth + credentials)
  • User → Session: One-to-Many (a user can have multiple active sessions across devices)
  • Account → User: Many-to-One (each account belongs to one user)
  • Session → User: Many-to-One (each session belongs to one user)

On this page