@elizaos/plugin-sql 1.0.0-alpha.7 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/migrate.js CHANGED
@@ -1,22 +1,23 @@
1
1
  import {
2
2
  PGliteClientManager,
3
- PostgresConnectionManager,
3
+ PostgresConnectionManager
4
+ } from "./chunk-PSEXCDLP.js";
5
+ import {
4
6
  __name
5
- } from "./chunk-LLEN3JTK.js";
7
+ } from "./chunk-I3JSTNED.js";
6
8
 
7
9
  // src/migrate.ts
8
10
  import { logger } from "@elizaos/core";
9
11
  import { config } from "dotenv";
12
+ import { Pool } from "pg";
10
13
  config({ path: "../../.env" });
11
14
  async function runMigrations() {
12
15
  if (process.env.POSTGRES_URL) {
13
16
  try {
14
- const connectionManager = new PostgresConnectionManager(
15
- process.env.POSTGRES_URL
16
- );
17
+ const pool = new Pool({ connectionString: process.env.POSTGRES_URL });
18
+ const connectionManager = new PostgresConnectionManager(pool, process.env.POSTGRES_URL);
17
19
  await connectionManager.initialize();
18
20
  await connectionManager.runMigrations();
19
- await connectionManager.close();
20
21
  logger.success("PostgreSQL migrations completed successfully");
21
22
  process.exit(0);
22
23
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/migrate.ts"],"sourceRoot":"./","sourcesContent":["import { logger } from \"@elizaos/core\";\nimport { config } from \"dotenv\";\nimport { PGliteClientManager } from \"./pg-lite/manager.js\";\nimport { PostgresConnectionManager } from \"./pg/manager.js\";\n\nconfig({ path: \"../../.env\" });\n\n/**\n * Runs the database migrations based on the environment variable POSTGRES_URL.\n * If the POSTGRES_URL is provided, it indicates the use of a PostgreSQL database and the corresponding migration logic needs to be implemented.\n * If POSTGRES_URL is not provided, it uses a PGlite database and runs the migrations on it.\n * @returns {Promise<void>} A promise that resolves once the migrations are completed successfully or rejects if an error occurs.\n */\nasync function runMigrations() {\n\tif (process.env.POSTGRES_URL) {\n\t\ttry {\n\t\t\tconst connectionManager = new PostgresConnectionManager(\n\t\t\t\tprocess.env.POSTGRES_URL,\n\t\t\t);\n\t\t\tawait connectionManager.initialize();\n\t\t\tawait connectionManager.runMigrations();\n\t\t\tawait connectionManager.close();\n\t\t\tlogger.success(\"PostgreSQL migrations completed successfully\");\n\t\t\tprocess.exit(0);\n\t\t} catch (error) {\n\t\t\tlogger.warn(\"PostgreSQL migration failed:\", error);\n\t\t\tprocess.exit(1);\n\t\t}\n\t} else {\n\t\tlogger.info(\"Using PGlite database\");\n\t\tconst clientManager = new PGliteClientManager({\n\t\t\tdataDir: \"../../pglite\",\n\t\t});\n\n\t\ttry {\n\t\t\tawait clientManager.initialize();\n\t\t\tawait clientManager.runMigrations();\n\t\t\tlogger.success(\"PGlite migrations completed successfully\");\n\t\t\tawait clientManager.close();\n\t\t\tprocess.exit(0);\n\t\t} catch (error) {\n\t\t\tlogger.error(\"PGlite migration failed:\", error);\n\t\t\ttry {\n\t\t\t\tawait clientManager.close();\n\t\t\t} catch (closeError) {\n\t\t\t\tlogger.error(\"Failed to close PGlite connection:\", closeError);\n\t\t\t}\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n}\n\nrunMigrations().catch((error) => {\n\tlogger.error(\"Unhandled error in migrations:\", error);\n\tprocess.exit(1);\n});\n"],"mappings":";;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,cAAc;AAIvB,OAAO,EAAE,MAAM,aAAa,CAAC;AAQ7B,eAAe,gBAAgB;AAC9B,MAAI,QAAQ,IAAI,cAAc;AAC7B,QAAI;AACH,YAAM,oBAAoB,IAAI;AAAA,QAC7B,QAAQ,IAAI;AAAA,MACb;AACA,YAAM,kBAAkB,WAAW;AACnC,YAAM,kBAAkB,cAAc;AACtC,YAAM,kBAAkB,MAAM;AAC9B,aAAO,QAAQ,8CAA8C;AAC7D,cAAQ,KAAK,CAAC;AAAA,IACf,SAAS,OAAO;AACf,aAAO,KAAK,gCAAgC,KAAK;AACjD,cAAQ,KAAK,CAAC;AAAA,IACf;AAAA,EACD,OAAO;AACN,WAAO,KAAK,uBAAuB;AACnC,UAAM,gBAAgB,IAAI,oBAAoB;AAAA,MAC7C,SAAS;AAAA,IACV,CAAC;AAED,QAAI;AACH,YAAM,cAAc,WAAW;AAC/B,YAAM,cAAc,cAAc;AAClC,aAAO,QAAQ,0CAA0C;AACzD,YAAM,cAAc,MAAM;AAC1B,cAAQ,KAAK,CAAC;AAAA,IACf,SAAS,OAAO;AACf,aAAO,MAAM,4BAA4B,KAAK;AAC9C,UAAI;AACH,cAAM,cAAc,MAAM;AAAA,MAC3B,SAAS,YAAY;AACpB,eAAO,MAAM,sCAAsC,UAAU;AAAA,MAC9D;AACA,cAAQ,KAAK,CAAC;AAAA,IACf;AAAA,EACD;AACD;AArCe;AAuCf,cAAc,EAAE,MAAM,CAAC,UAAU;AAChC,SAAO,MAAM,kCAAkC,KAAK;AACpD,UAAQ,KAAK,CAAC;AACf,CAAC;","names":[]}
1
+ {"version":3,"sources":["../src/migrate.ts"],"sourceRoot":"./","sourcesContent":["import { logger } from '@elizaos/core';\nimport { config } from 'dotenv';\nimport { PGliteClientManager } from './pglite/manager.js';\nimport { PostgresConnectionManager } from './pg/manager.js';\nimport { drizzle } from 'drizzle-orm/node-postgres';\nimport { Pool } from 'pg';\n\nconfig({ path: '../../.env' });\n\n/**\n * Runs the database migrations based on the environment variable POSTGRES_URL.\n * If the POSTGRES_URL is provided, it indicates the use of a PostgreSQL database and the corresponding migration logic needs to be implemented.\n * If POSTGRES_URL is not provided, it uses a PGlite database and runs the migrations on it.\n * @returns {Promise<void>} A promise that resolves once the migrations are completed successfully or rejects if an error occurs.\n */\nasync function runMigrations() {\n if (process.env.POSTGRES_URL) {\n try {\n const pool = new Pool({ connectionString: process.env.POSTGRES_URL });\n const connectionManager = new PostgresConnectionManager(pool, process.env.POSTGRES_URL);\n await connectionManager.initialize();\n await connectionManager.runMigrations();\n // await connectionManager.close();\n logger.success('PostgreSQL migrations completed successfully');\n process.exit(0);\n } catch (error) {\n logger.warn('PostgreSQL migration failed:', error);\n process.exit(1);\n }\n } else {\n logger.info('Using PGlite database');\n const clientManager = new PGliteClientManager({\n dataDir: '../../pglite',\n });\n\n try {\n await clientManager.initialize();\n await clientManager.runMigrations();\n logger.success('PGlite migrations completed successfully');\n await clientManager.close();\n process.exit(0);\n } catch (error) {\n logger.error('PGlite migration failed:', error);\n try {\n await clientManager.close();\n } catch (closeError) {\n logger.error('Failed to close PGlite connection:', closeError);\n }\n process.exit(1);\n }\n }\n}\n\nrunMigrations().catch((error) => {\n logger.error('Unhandled error in migrations:', error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,cAAc;AAIvB,SAAS,YAAY;AAErB,OAAO,EAAE,MAAM,aAAa,CAAC;AAQ7B,eAAe,gBAAgB;AAC7B,MAAI,QAAQ,IAAI,cAAc;AAC5B,QAAI;AACF,YAAM,OAAO,IAAI,KAAK,EAAE,kBAAkB,QAAQ,IAAI,aAAa,CAAC;AACpE,YAAM,oBAAoB,IAAI,0BAA0B,MAAM,QAAQ,IAAI,YAAY;AACtF,YAAM,kBAAkB,WAAW;AACnC,YAAM,kBAAkB,cAAc;AAEtC,aAAO,QAAQ,8CAA8C;AAC7D,cAAQ,KAAK,CAAC;AAAA,IAChB,SAAS,OAAO;AACd,aAAO,KAAK,gCAAgC,KAAK;AACjD,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,OAAO;AACL,WAAO,KAAK,uBAAuB;AACnC,UAAM,gBAAgB,IAAI,oBAAoB;AAAA,MAC5C,SAAS;AAAA,IACX,CAAC;AAED,QAAI;AACF,YAAM,cAAc,WAAW;AAC/B,YAAM,cAAc,cAAc;AAClC,aAAO,QAAQ,0CAA0C;AACzD,YAAM,cAAc,MAAM;AAC1B,cAAQ,KAAK,CAAC;AAAA,IAChB,SAAS,OAAO;AACd,aAAO,MAAM,4BAA4B,KAAK;AAC9C,UAAI;AACF,cAAM,cAAc,MAAM;AAAA,MAC5B,SAAS,YAAY;AACnB,eAAO,MAAM,sCAAsC,UAAU;AAAA,MAC/D;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF;AApCe;AAsCf,cAAc,EAAE,MAAM,CAAC,UAAU;AAC/B,SAAO,MAAM,kCAAkC,KAAK;AACpD,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
@@ -0,0 +1,199 @@
1
+ CREATE EXTENSION IF NOT EXISTS vector;
2
+ --> statement-breakpoint
3
+ CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
4
+ --> statement-breakpoint
5
+ CREATE TABLE "agents" (
6
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
7
+ "enabled" boolean DEFAULT true NOT NULL,
8
+ "createdAt" timestamptz DEFAULT now() NOT NULL,
9
+ "updatedAt" timestamptz DEFAULT now() NOT NULL,
10
+ "name" text,
11
+ "username" text,
12
+ "system" text,
13
+ "bio" jsonb NOT NULL,
14
+ "message_examples" jsonb DEFAULT '[]'::jsonb,
15
+ "post_examples" jsonb DEFAULT '[]'::jsonb,
16
+ "topics" jsonb DEFAULT '[]'::jsonb,
17
+ "adjectives" jsonb DEFAULT '[]'::jsonb,
18
+ "knowledge" jsonb DEFAULT '[]'::jsonb,
19
+ "plugins" jsonb DEFAULT '[]'::jsonb,
20
+ "settings" jsonb DEFAULT '{}'::jsonb,
21
+ "style" jsonb DEFAULT '{}'::jsonb,
22
+ CONSTRAINT "name_unique" UNIQUE("name")
23
+ );
24
+ --> statement-breakpoint
25
+ CREATE TABLE "cache" (
26
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
27
+ "key" text NOT NULL,
28
+ "agentId" uuid NOT NULL,
29
+ "value" jsonb NOT NULL,
30
+ "createdAt" timestamptz DEFAULT now() NOT NULL,
31
+ "expiresAt" timestamptz,
32
+ CONSTRAINT "cache_key_agent_unique" UNIQUE("key","agentId")
33
+ );
34
+ --> statement-breakpoint
35
+ CREATE TABLE "components" (
36
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
37
+ "entityId" uuid NOT NULL,
38
+ "agentId" uuid NOT NULL,
39
+ "roomId" uuid NOT NULL,
40
+ "worldId" uuid,
41
+ "sourceEntityId" uuid,
42
+ "type" text NOT NULL,
43
+ "data" jsonb DEFAULT '{}'::jsonb,
44
+ "createdAt" timestamptz DEFAULT now() NOT NULL
45
+ );
46
+ --> statement-breakpoint
47
+ CREATE TABLE "embeddings" (
48
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
49
+ "memory_id" uuid,
50
+ "created_at" timestamptz DEFAULT now() NOT NULL,
51
+ "dim_384" vector(384),
52
+ "dim_512" vector(512),
53
+ "dim_768" vector(768),
54
+ "dim_1024" vector(1024),
55
+ "dim_1536" vector(1536),
56
+ "dim_3072" vector(3072),
57
+ CONSTRAINT "embedding_source_check" CHECK ("memory_id" IS NOT NULL)
58
+ );
59
+ --> statement-breakpoint
60
+ CREATE TABLE "entities" (
61
+ "id" uuid PRIMARY KEY NOT NULL,
62
+ "agentId" uuid NOT NULL,
63
+ "createdAt" timestamptz DEFAULT now() NOT NULL,
64
+ "names" text[] DEFAULT '{}'::text[],
65
+ "metadata" jsonb DEFAULT '{}'::jsonb,
66
+ CONSTRAINT "id_agent_id_unique" UNIQUE("id","agentId")
67
+ );
68
+ --> statement-breakpoint
69
+ CREATE TABLE "logs" (
70
+ "id" uuid DEFAULT gen_random_uuid() NOT NULL,
71
+ "createdAt" timestamptz DEFAULT now() NOT NULL,
72
+ "entityId" uuid NOT NULL,
73
+ "body" jsonb NOT NULL,
74
+ "type" text NOT NULL,
75
+ "roomId" uuid NOT NULL
76
+ );
77
+ --> statement-breakpoint
78
+ CREATE TABLE "memories" (
79
+ "id" uuid PRIMARY KEY NOT NULL,
80
+ "type" text NOT NULL,
81
+ "createdAt" timestamptz DEFAULT now() NOT NULL,
82
+ "content" jsonb NOT NULL,
83
+ "entityId" uuid,
84
+ "agentId" uuid,
85
+ "roomId" uuid,
86
+ "unique" boolean DEFAULT true NOT NULL,
87
+ "metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
88
+ CONSTRAINT "fragment_metadata_check" CHECK (
89
+ CASE
90
+ WHEN metadata->>'type' = 'fragment' THEN
91
+ metadata ? 'documentId' AND
92
+ metadata ? 'position'
93
+ ELSE true
94
+ END
95
+ ),
96
+ CONSTRAINT "document_metadata_check" CHECK (
97
+ CASE
98
+ WHEN metadata->>'type' = 'document' THEN
99
+ metadata ? 'timestamp'
100
+ ELSE true
101
+ END
102
+ )
103
+ );
104
+ --> statement-breakpoint
105
+ CREATE TABLE "participants" (
106
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
107
+ "createdAt" timestamptz DEFAULT now() NOT NULL,
108
+ "entityId" uuid,
109
+ "roomId" uuid,
110
+ "agentId" uuid,
111
+ "roomState" text
112
+ );
113
+ --> statement-breakpoint
114
+ CREATE TABLE "relationships" (
115
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
116
+ "createdAt" timestamptz DEFAULT now() NOT NULL,
117
+ "sourceEntityId" uuid NOT NULL,
118
+ "targetEntityId" uuid NOT NULL,
119
+ "agentId" uuid NOT NULL,
120
+ "tags" text[],
121
+ "metadata" jsonb,
122
+ CONSTRAINT "unique_relationship" UNIQUE("sourceEntityId","targetEntityId","agentId")
123
+ );
124
+ --> statement-breakpoint
125
+ CREATE TABLE "rooms" (
126
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
127
+ "agentId" uuid,
128
+ "source" text NOT NULL,
129
+ "type" text NOT NULL,
130
+ "serverId" text,
131
+ "worldId" uuid,
132
+ "name" text,
133
+ "metadata" jsonb,
134
+ "channelId" text,
135
+ "createdAt" timestamptz DEFAULT now() NOT NULL
136
+ );
137
+ --> statement-breakpoint
138
+ CREATE TABLE "tasks" (
139
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
140
+ "name" text NOT NULL,
141
+ "description" text NOT NULL,
142
+ "room_id" uuid,
143
+ "world_id" uuid,
144
+ "agent_id" uuid NOT NULL,
145
+ "tags" text[],
146
+ "metadata" jsonb,
147
+ "created_at" timestamp DEFAULT now(),
148
+ "updated_at" timestamp DEFAULT now()
149
+ );
150
+ --> statement-breakpoint
151
+ CREATE TABLE "worlds" (
152
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
153
+ "agentId" uuid NOT NULL,
154
+ "name" text NOT NULL,
155
+ "metadata" jsonb,
156
+ "serverId" text NOT NULL,
157
+ "createdAt" timestamptz DEFAULT now() NOT NULL
158
+ );
159
+ --> statement-breakpoint
160
+ ALTER TABLE "cache" ADD CONSTRAINT "cache_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
161
+ ALTER TABLE "components" ADD CONSTRAINT "components_entityId_entities_id_fk" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
162
+ ALTER TABLE "components" ADD CONSTRAINT "components_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
163
+ ALTER TABLE "components" ADD CONSTRAINT "components_roomId_rooms_id_fk" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
164
+ ALTER TABLE "components" ADD CONSTRAINT "components_worldId_worlds_id_fk" FOREIGN KEY ("worldId") REFERENCES "public"."worlds"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
165
+ ALTER TABLE "components" ADD CONSTRAINT "components_sourceEntityId_entities_id_fk" FOREIGN KEY ("sourceEntityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
166
+ ALTER TABLE "embeddings" ADD CONSTRAINT "embeddings_memory_id_memories_id_fk" FOREIGN KEY ("memory_id") REFERENCES "public"."memories"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
167
+ ALTER TABLE "embeddings" ADD CONSTRAINT "fk_embedding_memory" FOREIGN KEY ("memory_id") REFERENCES "public"."memories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
168
+ ALTER TABLE "entities" ADD CONSTRAINT "entities_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
169
+ ALTER TABLE "logs" ADD CONSTRAINT "logs_entityId_entities_id_fk" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
170
+ ALTER TABLE "logs" ADD CONSTRAINT "logs_roomId_rooms_id_fk" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
171
+ ALTER TABLE "logs" ADD CONSTRAINT "fk_room" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
172
+ ALTER TABLE "logs" ADD CONSTRAINT "fk_user" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
173
+ ALTER TABLE "memories" ADD CONSTRAINT "memories_entityId_entities_id_fk" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
174
+ ALTER TABLE "memories" ADD CONSTRAINT "memories_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
175
+ ALTER TABLE "memories" ADD CONSTRAINT "memories_roomId_rooms_id_fk" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
176
+ ALTER TABLE "memories" ADD CONSTRAINT "fk_room" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
177
+ ALTER TABLE "memories" ADD CONSTRAINT "fk_user" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
178
+ ALTER TABLE "memories" ADD CONSTRAINT "fk_agent" FOREIGN KEY ("agentId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
179
+ ALTER TABLE "participants" ADD CONSTRAINT "participants_entityId_entities_id_fk" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
180
+ ALTER TABLE "participants" ADD CONSTRAINT "participants_roomId_rooms_id_fk" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
181
+ ALTER TABLE "participants" ADD CONSTRAINT "participants_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
182
+ ALTER TABLE "participants" ADD CONSTRAINT "fk_room" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
183
+ ALTER TABLE "participants" ADD CONSTRAINT "fk_user" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
184
+ ALTER TABLE "relationships" ADD CONSTRAINT "relationships_sourceEntityId_entities_id_fk" FOREIGN KEY ("sourceEntityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
185
+ ALTER TABLE "relationships" ADD CONSTRAINT "relationships_targetEntityId_entities_id_fk" FOREIGN KEY ("targetEntityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
186
+ ALTER TABLE "relationships" ADD CONSTRAINT "relationships_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
187
+ ALTER TABLE "relationships" ADD CONSTRAINT "fk_user_a" FOREIGN KEY ("sourceEntityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
188
+ ALTER TABLE "relationships" ADD CONSTRAINT "fk_user_b" FOREIGN KEY ("targetEntityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
189
+ ALTER TABLE "rooms" ADD CONSTRAINT "rooms_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
190
+ ALTER TABLE "rooms" ADD CONSTRAINT "rooms_worldId_worlds_id_fk" FOREIGN KEY ("worldId") REFERENCES "public"."worlds"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
191
+ ALTER TABLE "worlds" ADD CONSTRAINT "worlds_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
192
+ CREATE INDEX "idx_embedding_memory" ON "embeddings" USING btree ("memory_id");--> statement-breakpoint
193
+ CREATE INDEX "idx_memories_type_room" ON "memories" USING btree ("type","roomId");--> statement-breakpoint
194
+ CREATE INDEX "idx_memories_metadata_type" ON "memories" USING btree (((metadata->>'type')));--> statement-breakpoint
195
+ CREATE INDEX "idx_memories_document_id" ON "memories" USING btree (((metadata->>'documentId')));--> statement-breakpoint
196
+ CREATE INDEX "idx_fragments_order" ON "memories" USING btree (((metadata->>'documentId')),((metadata->>'position')));--> statement-breakpoint
197
+ CREATE INDEX "idx_participants_user" ON "participants" USING btree ("entityId");--> statement-breakpoint
198
+ CREATE INDEX "idx_participants_room" ON "participants" USING btree ("roomId");--> statement-breakpoint
199
+ CREATE INDEX "idx_relationships_users" ON "relationships" USING btree ("sourceEntityId","targetEntityId");