Skip to content

Commit 1b7035e

Browse files
committed
fix plugin installation and migration in projectss
1 parent b03b080 commit 1b7035e

File tree

7 files changed

+1725
-38
lines changed

7 files changed

+1725
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
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+
"createdAt" timestamptz DEFAULT now() NOT NULL,
8+
"updatedAt" timestamptz DEFAULT now() NOT NULL,
9+
"name" text,
10+
"username" text,
11+
"system" text,
12+
"bio" jsonb NOT NULL,
13+
"message_examples" jsonb DEFAULT '[]'::jsonb,
14+
"post_examples" jsonb DEFAULT '[]'::jsonb,
15+
"topics" jsonb DEFAULT '[]'::jsonb,
16+
"adjectives" jsonb DEFAULT '[]'::jsonb,
17+
"knowledge" jsonb DEFAULT '[]'::jsonb,
18+
"plugins" jsonb DEFAULT '[]'::jsonb,
19+
"settings" jsonb DEFAULT '{}'::jsonb,
20+
"style" jsonb DEFAULT '{}'::jsonb,
21+
CONSTRAINT "name_unique" UNIQUE("name")
22+
);
23+
--> statement-breakpoint
24+
CREATE TABLE "cache" (
25+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
26+
"key" text NOT NULL,
27+
"agentId" uuid NOT NULL,
28+
"value" jsonb NOT NULL,
29+
"createdAt" timestamptz DEFAULT now() NOT NULL,
30+
"expiresAt" timestamptz,
31+
CONSTRAINT "cache_key_agent_unique" UNIQUE("key","agentId")
32+
);
33+
--> statement-breakpoint
34+
CREATE TABLE "components" (
35+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
36+
"entityId" uuid NOT NULL,
37+
"agentId" uuid NOT NULL,
38+
"roomId" uuid NOT NULL,
39+
"worldId" uuid,
40+
"sourceEntityId" uuid,
41+
"type" text NOT NULL,
42+
"data" jsonb DEFAULT '{}'::jsonb,
43+
"createdAt" timestamptz DEFAULT now() NOT NULL
44+
);
45+
--> statement-breakpoint
46+
CREATE TABLE "embeddings" (
47+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
48+
"memory_id" uuid,
49+
"created_at" timestamptz DEFAULT now() NOT NULL,
50+
"dim_384" vector(384),
51+
"dim_512" vector(512),
52+
"dim_768" vector(768),
53+
"dim_1024" vector(1024),
54+
"dim_1536" vector(1536),
55+
"dim_3072" vector(3072),
56+
CONSTRAINT "embedding_source_check" CHECK ("memory_id" IS NOT NULL)
57+
);
58+
--> statement-breakpoint
59+
CREATE TABLE "entities" (
60+
"id" uuid PRIMARY KEY NOT NULL,
61+
"agentId" uuid NOT NULL,
62+
"createdAt" timestamptz DEFAULT now() NOT NULL,
63+
"names" text[] DEFAULT '{}'::text[],
64+
"metadata" jsonb DEFAULT '{}'::jsonb,
65+
CONSTRAINT "id_agent_id_unique" UNIQUE("id","agentId")
66+
);
67+
--> statement-breakpoint
68+
CREATE TABLE "logs" (
69+
"id" uuid DEFAULT gen_random_uuid() NOT NULL,
70+
"createdAt" timestamptz DEFAULT now() NOT NULL,
71+
"entityId" uuid NOT NULL,
72+
"body" jsonb NOT NULL,
73+
"type" text NOT NULL,
74+
"roomId" uuid NOT NULL
75+
);
76+
--> statement-breakpoint
77+
CREATE TABLE "memories" (
78+
"id" uuid PRIMARY KEY NOT NULL,
79+
"type" text NOT NULL,
80+
"createdAt" timestamptz DEFAULT now() NOT NULL,
81+
"content" jsonb NOT NULL,
82+
"entityId" uuid,
83+
"agentId" uuid,
84+
"roomId" uuid,
85+
"unique" boolean DEFAULT true NOT NULL,
86+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
87+
CONSTRAINT "fragment_metadata_check" CHECK (
88+
CASE
89+
WHEN metadata->>'type' = 'fragment' THEN
90+
metadata ? 'documentId' AND
91+
metadata ? 'position'
92+
ELSE true
93+
END
94+
),
95+
CONSTRAINT "document_metadata_check" CHECK (
96+
CASE
97+
WHEN metadata->>'type' = 'document' THEN
98+
metadata ? 'timestamp'
99+
ELSE true
100+
END
101+
)
102+
);
103+
--> statement-breakpoint
104+
CREATE TABLE "participants" (
105+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
106+
"createdAt" timestamptz DEFAULT now() NOT NULL,
107+
"entityId" uuid,
108+
"roomId" uuid,
109+
"agentId" uuid,
110+
"roomState" text
111+
);
112+
--> statement-breakpoint
113+
CREATE TABLE "relationships" (
114+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
115+
"createdAt" timestamptz DEFAULT now() NOT NULL,
116+
"sourceEntityId" uuid NOT NULL,
117+
"targetEntityId" uuid NOT NULL,
118+
"agentId" uuid NOT NULL,
119+
"tags" text[],
120+
"metadata" jsonb,
121+
CONSTRAINT "unique_relationship" UNIQUE("sourceEntityId","targetEntityId","agentId")
122+
);
123+
--> statement-breakpoint
124+
CREATE TABLE "rooms" (
125+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
126+
"agentId" uuid,
127+
"source" text NOT NULL,
128+
"type" text NOT NULL,
129+
"serverId" text,
130+
"worldId" uuid,
131+
"name" text,
132+
"metadata" jsonb,
133+
"channelId" text,
134+
"createdAt" timestamptz DEFAULT now() NOT NULL
135+
);
136+
--> statement-breakpoint
137+
CREATE TABLE "tasks" (
138+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
139+
"name" text NOT NULL,
140+
"description" text NOT NULL,
141+
"room_id" uuid,
142+
"world_id" uuid,
143+
"agent_id" uuid NOT NULL,
144+
"tags" text[],
145+
"metadata" jsonb,
146+
"created_at" timestamp DEFAULT now(),
147+
"updated_at" timestamp DEFAULT now()
148+
);
149+
--> statement-breakpoint
150+
CREATE TABLE "worlds" (
151+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
152+
"agentId" uuid NOT NULL,
153+
"name" text NOT NULL,
154+
"metadata" jsonb,
155+
"serverId" text NOT NULL,
156+
"createdAt" timestamptz DEFAULT now() NOT NULL
157+
);
158+
--> statement-breakpoint
159+
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
160+
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
161+
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
162+
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
163+
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
164+
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
165+
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
166+
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
167+
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
168+
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
169+
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
170+
ALTER TABLE "logs" ADD CONSTRAINT "fk_room" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
171+
ALTER TABLE "logs" ADD CONSTRAINT "fk_user" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
172+
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
173+
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
174+
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
175+
ALTER TABLE "memories" ADD CONSTRAINT "fk_room" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
176+
ALTER TABLE "memories" ADD CONSTRAINT "fk_user" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
177+
ALTER TABLE "memories" ADD CONSTRAINT "fk_agent" FOREIGN KEY ("agentId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
178+
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
179+
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
180+
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
181+
ALTER TABLE "participants" ADD CONSTRAINT "fk_room" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
182+
ALTER TABLE "participants" ADD CONSTRAINT "fk_user" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
183+
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
184+
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
185+
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
186+
ALTER TABLE "relationships" ADD CONSTRAINT "fk_user_a" FOREIGN KEY ("sourceEntityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
187+
ALTER TABLE "relationships" ADD CONSTRAINT "fk_user_b" FOREIGN KEY ("targetEntityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
188+
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
189+
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
190+
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
191+
CREATE INDEX "idx_embedding_memory" ON "embeddings" USING btree ("memory_id");--> statement-breakpoint
192+
CREATE INDEX "idx_memories_type_room" ON "memories" USING btree ("type","roomId");--> statement-breakpoint
193+
CREATE INDEX "idx_memories_metadata_type" ON "memories" USING btree (((metadata->>'type')));--> statement-breakpoint
194+
CREATE INDEX "idx_memories_document_id" ON "memories" USING btree (((metadata->>'documentId')));--> statement-breakpoint
195+
CREATE INDEX "idx_fragments_order" ON "memories" USING btree (((metadata->>'documentId')),((metadata->>'position')));--> statement-breakpoint
196+
CREATE INDEX "idx_participants_user" ON "participants" USING btree ("entityId");--> statement-breakpoint
197+
CREATE INDEX "idx_participants_room" ON "participants" USING btree ("roomId");--> statement-breakpoint
198+
CREATE INDEX "idx_relationships_users" ON "relationships" USING btree ("sourceEntityId","targetEntityId");

0 commit comments

Comments
 (0)