Site/src/lib/server/init.surql and initialized on every startup.
Database Configuration
Core Tables
User Table
Stores user accounts and profiles.- First registered user automatically becomes admin
- Email validation via assertion
- Computed
statusfield based on activity - Description history tracking (array of objects)
- Custom CSS for profile pages
Asset Table
Catalog items (clothing, gear, models, etc.).- 2: T-Shirt
- 8: Hat
- 11: Shirt
- 12: Pants
- 13: Decal
- 18: Face
Pending: Awaiting moderationVisible: Approved and publicHidden: Removed from public view
Place Table
Game servers and experiences.- Dedicated: Always-on server with fixed address
- Dynamic: On-demand server spawned by platform
- Private: Invitation-only via privateTicket
Comment Table
Unified comment system for status posts, forum posts, and asset comments.["status"]: User status post["status", "abc123"]: Reply to status post["forum", "general"]: Forum topic["forum", "general", "xyz789"]: Forum reply["asset", "123456789"]: Asset comment
author: Fetches username via graph traversallikes/dislikes: Whether current user has liked/dislikedscore: Net votes (likes - dislikes)
Graph Relationships
SurrealDB’s graph capabilities model social features as edges.Social Graph
Content Relationships
Session Management
Custom Functions
SurrealDB supports custom functions for reusable logic.fn::assetId()
Generate random 9-digit asset ID:fn::auditLog()
Create audit log entry:fn::notify()
Create notification:fn::getComments()
Recursively fetch nested comments (up to 10 levels deep):Event Triggers
Automatic audit logging for administrative actions.Query Patterns
Graph Traversal
Get user’s friends:Fetching with Relations
Get user’s inventory (wearable assets):Computed Aggregations
Count user’s friends:Using SurrealQL in TypeScript
The Site service imports.surql files:
Type Safety
The Site service defines TypeScript interfaces matching the schema:Schema Evolution
TheOVERWRITE keyword in schema definitions ensures the schema updates on every startup:
- Schema migrations during deployment
- Field additions without manual migration
- Development flexibility
Performance Considerations
Indexes
Currently, only username has an index:- Asset visibility + type (catalog queries)
- Comment type (forum/status filtering)
- Place deleted flag (games list)
Computed Fields
Computed fields run on every query:user.status: Joins toplayingtablecomment.author: Graph traversalcomment.score: Aggregates likes/dislikes
Graph Queries
Graph traversals can be expensive. UseLIMIT and pagination:
Backup and Recovery
SurrealDB stores data indata/surreal/ using the SurrealKV engine.
Backup:
data/surreal/ while database is stopped, or use SurrealDB’s live backup features.