Database Schema

The friend system uses a simple relational database schema with tables for users, friendships, friend requests, blocked users, rooms, and invitations.

Entity Relationships

users 1────N friendships N────1 users users 1────N friend_requests N────1 users users 1────N blocked_users N────1 users users 1────N rooms users 1────N invitations N────1 users

Table Definitions

users

Stores user profiles and online status. Note: The users table is optional if using external user management.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEYUnique user identifier
usernameTEXTNOT NULLDisplay name
statusTEXTDEFAULT 'offline'online, offline, away, in_room
last_seenINTEGERUnix timestamp of last activity
created_atINTEGERNOT NULLUnix timestamp

friendships

Stores accepted friend relationships between users.

ColumnTypeConstraintsDescription
idINTEGERPRIMARY KEY AUTOINCREMENT
user_idTEXTNOT NULL, FKFirst user
friend_idTEXTNOT NULL, FKSecond user (friend)
statusTEXTDEFAULT 'active'active, blocked
created_atINTEGERNOT NULLUnix timestamp when friendship created

friend_requests

Stores pending friend requests.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEYUnique request ID
sender_idTEXTNOT NULL, FKUser who sent the request
receiver_idTEXTNOT NULL, FKUser who received the request
statusTEXTDEFAULT 'pending'pending, accepted, rejected, cancelled
created_atINTEGERNOT NULLUnix timestamp
updated_atINTEGERUnix timestamp of last change

blocked_users

Stores user block entries for moderation.

ColumnTypeConstraintsDescription
idINTEGERPRIMARY KEY AUTOINCREMENT
user_idTEXTNOT NULL, FKUser who blocked
blocked_user_idTEXTNOT NULL, FKUser who was blocked
created_atINTEGERNOT NULLUnix timestamp

rooms

Stores game room/session information.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEYUnique room identifier
host_idTEXTNOT NULL, FKUser ID of room host
nameTEXTDisplay name for room
max_playersINTEGERDEFAULT 0Maximum player capacity
current_playersINTEGERDEFAULT 0Current player count
is_privateINTEGERDEFAULT 01 if password protected
custom_propertiesTEXTJSON string of game-specific data
created_atINTEGERNOT NULLUnix timestamp

invitations

Stores game invitations between friends.

ColumnTypeConstraintsDescription
idTEXTPRIMARY KEYUnique invitation ID
sender_idTEXTNOT NULL, FKUser who sent invitation
receiver_idTEXTNOT NULL, FKUser who received invitation
room_idTEXTFKRoom being invited to
messageTEXTPersonal message from sender
statusTEXTDEFAULT 'pending'pending, accepted, declined, expired
created_atINTEGERNOT NULLUnix timestamp
updated_atINTEGERUnix timestamp of last change

SQL Schema File

The complete SQL schema is available at .Server/websocket/database/external_schema.sql. You can use this to:

  • Set up the database manually
  • Extend the schema with additional tables
  • Create indexes for performance optimization