diff --git a/docs/docs/advanced/infrastructure.md b/docs/docs/advanced/infrastructure.md index f637756b49..0a70d74a36 100644 --- a/docs/docs/advanced/infrastructure.md +++ b/docs/docs/advanced/infrastructure.md @@ -41,6 +41,7 @@ The database schema includes several key tables: ```sql CREATE EXTENSION IF NOT EXISTS vector; CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; +CREATE EXTENSION IF NOT EXISTS pgcrypto; ``` 2. **Initialize Core Tables** @@ -48,30 +49,37 @@ CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; ```sql -- Create base tables CREATE TABLE accounts ( - "id" UUID PRIMARY KEY, - "createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, + "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(), + "createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, "name" TEXT, - "username" TEXT, - "email" TEXT NOT NULL, + "username" TEXT UNIQUE, + "email" TEXT NOT NULL UNIQUE, "avatarUrl" TEXT, "details" JSONB DEFAULT '{}'::jsonb ); CREATE TABLE rooms ( - "id" UUID PRIMARY KEY, - "createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP + "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(), + "createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE memories ( - "id" UUID PRIMARY KEY, + "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(), "type" TEXT NOT NULL, - "createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, + "createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, "content" JSONB NOT NULL, "embedding" vector(1536), "userId" UUID REFERENCES accounts("id"), "agentId" UUID REFERENCES accounts("id"), "roomId" UUID REFERENCES rooms("id"), - "unique" BOOLEAN DEFAULT true NOT NULL + "isUnique" BOOLEAN DEFAULT true NOT NULL +); + +CREATE TABLE participants ( + "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(), + "userId" UUID REFERENCES accounts("id"), + "roomId" UUID REFERENCES rooms("id"), + "joinedAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP ); ``` @@ -80,9 +88,12 @@ CREATE TABLE memories ( ```sql CREATE INDEX idx_memories_embedding ON memories USING hnsw ("embedding" vector_cosine_ops); + CREATE INDEX idx_memories_type_room ON memories("type", "roomId"); + CREATE INDEX idx_participants_user ON participants("userId"); CREATE INDEX idx_participants_room ON participants("roomId"); + ``` ### Connection Configuration