Skip to content

Commit e15dd54

Browse files
authored
Merge pull request elizaOS#1345 from ryanleecode/fix/postgres-adapter-schema
fix: postgres adapter schema
2 parents 0dc60c8 + 245692f commit e15dd54

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

packages/adapter-postgres/schema.sql

+23-15
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,28 @@ CREATE TABLE IF NOT EXISTS rooms (
4747
"createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
4848
);
4949

50-
CREATE TABLE IF NOT EXISTS memories (
51-
"id" UUID PRIMARY KEY,
52-
"type" TEXT NOT NULL,
53-
"createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
54-
"content" JSONB NOT NULL,
55-
"embedding" vector(get_embedding_dimension()), -- Dynamic vector size
56-
"userId" UUID REFERENCES accounts("id"),
57-
"agentId" UUID REFERENCES accounts("id"),
58-
"roomId" UUID REFERENCES rooms("id"),
59-
"unique" BOOLEAN DEFAULT true NOT NULL,
60-
CONSTRAINT fk_room FOREIGN KEY ("roomId") REFERENCES rooms("id") ON DELETE CASCADE,
61-
CONSTRAINT fk_user FOREIGN KEY ("userId") REFERENCES accounts("id") ON DELETE CASCADE,
62-
CONSTRAINT fk_agent FOREIGN KEY ("agentId") REFERENCES accounts("id") ON DELETE CASCADE
63-
);
50+
DO $$
51+
DECLARE
52+
vector_dim INTEGER;
53+
BEGIN
54+
vector_dim := get_embedding_dimension();
55+
56+
EXECUTE format('
57+
CREATE TABLE IF NOT EXISTS memories (
58+
"id" UUID PRIMARY KEY,
59+
"type" TEXT NOT NULL,
60+
"createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
61+
"content" JSONB NOT NULL,
62+
"embedding" vector(%s),
63+
"userId" UUID REFERENCES accounts("id"),
64+
"agentId" UUID REFERENCES accounts("id"),
65+
"roomId" UUID REFERENCES rooms("id"),
66+
"unique" BOOLEAN DEFAULT true NOT NULL,
67+
CONSTRAINT fk_room FOREIGN KEY ("roomId") REFERENCES rooms("id") ON DELETE CASCADE,
68+
CONSTRAINT fk_user FOREIGN KEY ("userId") REFERENCES accounts("id") ON DELETE CASCADE,
69+
CONSTRAINT fk_agent FOREIGN KEY ("agentId") REFERENCES accounts("id") ON DELETE CASCADE
70+
)', vector_dim);
71+
END $$;
6472

6573
CREATE TABLE IF NOT EXISTS goals (
6674
"id" UUID PRIMARY KEY,
@@ -126,4 +134,4 @@ CREATE INDEX IF NOT EXISTS idx_participants_user ON participants("userId");
126134
CREATE INDEX IF NOT EXISTS idx_participants_room ON participants("roomId");
127135
CREATE INDEX IF NOT EXISTS idx_relationships_users ON relationships("userA", "userB");
128136

129-
COMMIT;
137+
COMMIT;

0 commit comments

Comments
 (0)