botserver/docs/src/appendix-i
2025-11-24 14:15:01 -03:00
..
assets - From 1 to 4 validated. 2025-11-23 17:02:22 -03:00
README.md - Fix .svgs. 2025-11-24 14:15:01 -03:00
relationships.md - From 8 to 13.5 2025-11-24 13:02:30 -03:00
schema.md - Fix .svgs. 2025-11-24 14:15:01 -03:00
tables.md - From 8 to 13.5 2025-11-24 13:02:30 -03:00

Appendix I Database Model

Database Schema Overview

The core database schema for GeneralBots is defined in src/shared/models.rs. It uses Diesel with PostgreSQL and includes the following primary tables:

Table Description
users Stores user accounts, authentication tokens, and profile data.
sessions Tracks active BotSession instances, their start/end timestamps, and associated user.
knowledge_bases Metadata for each .gbkb collection (name, vector store configuration, creation date).
messages Individual chat messages (role=user/assistant, content, timestamp, linked to a session).
tools Registered custom tools per session (name, definition JSON, activation status).
files References to files managed by the .gbdrive package (path, size, MIME type, storage location).

Relationships

  • User ↔ Sessions Onetomany: a user can have many sessions.
  • Session ↔ Messages Onetomany: each session contains a sequence of messages.
  • Session ↔ KnowledgeBase Manytoone: a session uses a single knowledge base at a time.
  • Session ↔ Tools Onetomany: tools are scoped to the session that registers them.
  • File ↔ KnowledgeBase Optional link for documents stored in a knowledge base.

Key Tables

User Table

  • id: Integer primary key
  • username: String
  • email: String
  • password_hash: String
  • created_at: Timestamp

Session Table

  • id: Integer primary key
  • user_id: Foreign key to User
  • started_at: Timestamp
  • last_active: Timestamp
  • knowledge_base_id: Integer

Message Table

  • id: Integer primary key
  • session_id: Foreign key to Session
  • role: String ("user" or "assistant")
  • content: Text
  • timestamp: Timestamp

The schema is automatically migrated when the server starts.


General Bots