Skip to main content

Database Schema

Hyperscape uses PostgreSQL in production and SQLite for local development, with Drizzle ORM for type-safe database access.
Database schema is defined in packages/server/src/database/schema.ts.

Overview


Core Tables

Users

Characters

Skills are stored as individual columns (e.g., smithingLevel, smithingXp) rather than JSONB for efficient querying and indexing.

Inventory

Equipment


Bank System

Bank Storage

Bank Tabs


World Persistence

World Chunks


Player Sessions


Quest System Tables

Quest Progress

Tracks player quest state:
Status Values:
  • not_started — Quest not started
  • in_progress — Quest active
  • completed — Quest finished
ready_to_complete is a derived status computed at runtime when objectives are met. It’s not stored in the database.

Quest Audit Log

Immutable audit trail for security and debugging:
Features:
  • Immutable log (no updates or deletes)
  • Used for fraud detection and debugging
  • Indexed for efficient queries by player, quest, and timestamp

Statistics Tables

NPC Kills


Quest System Tables

quest_progress

Tracks player quest state:
Key Features:
  • UNIQUE constraint on (playerId, questId) prevents duplicate progress entries
  • CASCADE DELETE cleans up on character deletion
  • stageProgress JSONB stores flexible progress data (e.g., {"kills": 7, "copper_ore": 3})
  • status values: not_started, in_progress, completed
ready_to_complete is a derived status computed by QuestSystem when status === "in_progress" AND the current stage objective is met. It’s not stored in the database.

quest_audit_log

Immutable audit trail for security and analytics:
Use Cases:
  • Fraud detection and investigation
  • Debugging quest progression bugs
  • Analytics for game design
  • Customer support inquiries

Repository Pattern

All database access goes through typed repositories:

Data Types

Timestamps

All timestamps use bigint storing Unix milliseconds for precision:

Positions

Positions use real (float) for sub-tile precision:

IDs

All IDs are text storing UUIDs as strings:

Migrations

Drizzle handles migrations automatically. Run from packages/server/:

Recent Migrations

Migrations are located in packages/server/src/database/migrations/.

Quest System Tables

quest_progress

Tracks player quest progression:
Status Values:
  • not_started — Quest not yet started
  • in_progress — Quest active, objectives incomplete
  • completed — Quest finished, rewards claimed
Note: ready_to_complete is a derived status (computed when status === "in_progress" AND current stage objective is met). Stage Progress Format:

quest_audit_log

Immutable audit trail for quest actions:
Use Cases:
  • Fraud detection and investigation
  • Debugging quest progression bugs
  • Analytics for game design
  • Customer support inquiries

Activity & Moderation Tables

activity_log

Tracks player actions for admin panel:

trades

Trade transaction history:

user_bans

Moderation ban records: