@@ -47,20 +47,28 @@ CREATE TABLE IF NOT EXISTS rooms (
47
47
" createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
48
48
);
49
49
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 $$;
64
72
65
73
CREATE TABLE IF NOT EXISTS goals (
66
74
" id" UUID PRIMARY KEY ,
@@ -126,4 +134,4 @@ CREATE INDEX IF NOT EXISTS idx_participants_user ON participants("userId");
126
134
CREATE INDEX IF NOT EXISTS idx_participants_room ON participants(" roomId" );
127
135
CREATE INDEX IF NOT EXISTS idx_relationships_users ON relationships(" userA" , " userB" );
128
136
129
- COMMIT ;
137
+ COMMIT ;
0 commit comments