Skip to content

Commit

Permalink
Merge pull request #424 from tarrencev/patch-1
Browse files Browse the repository at this point in the history
fix: Update adapters.md psql schema
  • Loading branch information
ponderingdemocritus authored Nov 20, 2024
2 parents 5fa2184 + 4fafa3b commit 95c3055
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion docs/docs/packages/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,42 @@ async searchMemories(params: {
### PostgreSQL Schema

```sql
-- migrations/20240318103238_remote_schema.sql
CREATE EXTENSION IF NOT EXISTS vector;

CREATE TABLE IF NOT EXISTS accounts (
id UUID PRIMARY KEY,
"createdAt" DEFAULT CURRENT_TIMESTAMP,
"name" TEXT,
"username" TEXT,
"email" TEXT NOT NULL,
"avatarUrl" TEXT,
"details" JSONB DEFAULT '{}'::"jsonb",
"is_agent" BOOLEAN DEFAULT false NOT NULL,
"location" TEXT,
"profile_line" TEXT,
"signed_tos" BOOLEAN DEFAULT false NOT NULL
);

ALTER TABLE ONLY accounts ADD CONSTRAINT users_email_key UNIQUE (email);

CREATE TABLE IF NOT EXISTS participants (
"id" UUID PRIMARY KEY,
"createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
"userId" UUID REFERENCES accounts(id),
"roomId" UUID REFERENCES rooms(id),
"userState" TEXT, -- For MUTED, NULL, or FOLLOWED states
"last_message_read" UUID
);

ALTER TABLE ONLY participants ADD CONSTRAINT participants_id_key UNIQUE (id);
ALTER TABLE ONLY participants ADD CONSTRAINT participants_roomId_fkey FOREIGN KEY ("roomId") REFERENCES rooms(id);
ALTER TABLE ONLY participants ADD CONSTRAINT participants_userId_fkey FOREIGN KEY ("userId") REFERENCES accounts(id);

CREATE TABLE rooms (
id UUID PRIMARY KEY,
"createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE memories (
id UUID PRIMARY KEY,
type TEXT NOT NULL,
Expand All @@ -440,6 +473,9 @@ CREATE TABLE memories (
"createdAt" TIMESTAMP NOT NULL
);

ALTER TABLE ONLY memories ADD CONSTRAINT memories_roomId_fkey FOREIGN KEY ("roomId") REFERENCES rooms(id);
ALTER TABLE ONLY memories ADD CONSTRAINT memories_userId_fkey FOREIGN KEY ("userId") REFERENCES accounts(id);

CREATE INDEX memory_embedding_idx ON
memories USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);
Expand All @@ -452,6 +488,11 @@ CREATE TABLE relationships (
"createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE ONLY relationships ADD CONSTRAINT friendships_id_key UNIQUE (id);
ALTER TABLE ONLY relationships ADD CONSTRAINT relationships_userA_fkey FOREIGN KEY ("userA") REFERENCES accounts(id);
ALTER TABLE ONLY relationships ADD CONSTRAINT relationships_userB_fkey FOREIGN KEY ("userB") REFERENCES accounts(id);
ALTER TABLE ONLY relationships ADD CONSTRAINT relationships_userId_fkey FOREIGN KEY ("userId") REFERENCES accounts(id);

CREATE TABLE goals (
id UUID PRIMARY KEY,
"roomId" UUID NOT NULL,
Expand Down

0 comments on commit 95c3055

Please sign in to comment.