Files
osirose-new/database-service/SCHEMA.md
raven a8755bd3de Add comprehensive documentation and unit tests
Documentation:
- Add detailed README files for all services (auth, character, database, launcher, packet, utils, world)
- Create API documentation for the database service with detailed endpoint specifications
- Document database schema and relationships
- Add service architecture overviews and configuration instructions

Unit Tests:
- Implement comprehensive test suite for database repositories (user, character, session)
- Add gRPC service tests for database interactions
- Create tests for packet service components (bufferpool, connection, packets)
- Add utility service tests (health check, logging, load balancer, redis cache, service discovery)
- Implement auth service user tests
- Add character service tests

Code Structure:
- Reorganize test files into a more consistent structure
- Create a dedicated tests crate for integration testing
- Add test helpers and mock implementations for easier testing
2025-04-09 13:29:53 -04:00

3.3 KiB

Database Schema

This document describes the database schema used by the Database Service.

Tables

User

Stores user account information.

Column Type Description
id INTEGER Primary key
name VARCHAR Username
email VARCHAR Email address
role VARCHAR User role (e.g., admin, user)
createdAt TIMESTAMP Account creation timestamp
updatedAt TIMESTAMP Last update timestamp

Character

Stores character information.

Column Type Description
id INTEGER Primary key
userId INTEGER Foreign key to User.id
name VARCHAR Character name
money BIGINT Character's currency
inventory JSONB Serialized inventory data
stats JSONB Character statistics
skills JSONB Character skills
looks JSONB Character appearance
position JSONB Character position in world
createdAt TIMESTAMP Character creation timestamp
updatedAt TIMESTAMP Last update timestamp
deletedAt TIMESTAMP Deletion timestamp (if deleted)
isActive BOOLEAN Whether character is active

Session

Stores session information.

Column Type Description
id VARCHAR Session ID (primary key)
userId INTEGER Foreign key to User.id
createdAt TIMESTAMP Session creation timestamp
expiresAt TIMESTAMP Session expiration timestamp

JSON Structures

Inventory

{
  "items": [
    {
      "id": 1,
      "itemId": 1001,
      "count": 5,
      "slot": 0
    }
  ],
  "capacity": 100
}

Stats

{
  "strength": 10,
  "dexterity": 10,
  "intelligence": 10,
  "vitality": 10,
  "hp": 100,
  "mp": 100,
  "level": 1,
  "experience": 0
}

Skills

{
  "skills": [
    {
      "id": 1,
      "level": 1,
      "cooldown": 0
    }
  ]
}

Looks

{
  "race": 1,
  "gender": 0,
  "hair": 1,
  "face": 1,
  "height": 180,
  "skinColor": "#F5DEB3"
}

Position

{
  "mapId": 1,
  "x": 100.0,
  "y": 100.0,
  "z": 0.0,
  "direction": 0
}

Indexes

  • user_name_idx: Index on User.name for fast username lookups
  • user_email_idx: Index on User.email for fast email lookups
  • character_user_id_idx: Index on Character.userId for fast character list retrieval
  • character_name_idx: Index on Character.name for name uniqueness checks
  • session_user_id_idx: Index on Session.userId for user session lookups