👷 build: add session group in agents table (#10868)

add session group
This commit is contained in:
Arvin Xu
2025-12-21 21:38:20 +08:00
committed by GitHub
parent 8abff4c450
commit 50b042f73e
5 changed files with 9173 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
ALTER TABLE "agents" ADD COLUMN IF NOT EXISTS "session_group_id" text;--> statement-breakpoint
DO $$ BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'agents_session_group_id_session_groups_id_fk') THEN
ALTER TABLE "agents" ADD CONSTRAINT "agents_session_group_id_session_groups_id_fk" FOREIGN KEY ("session_group_id") REFERENCES "public"."session_groups"("id") ON DELETE set null ON UPDATE no action;
END IF;
END $$;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "agents_session_group_id_idx" ON "agents" USING btree ("session_group_id");

File diff suppressed because it is too large Load Diff

View File

@@ -448,6 +448,13 @@
"when": 1766157362540,
"tag": "0063_add_columns_for_several_tables",
"breakpoints": true
},
{
"idx": 64,
"version": "7",
"when": 1766297832021,
"tag": "0064_add_agents_session_group_id",
"breakpoints": true
}
],
"version": "6"

View File

@@ -1023,5 +1023,15 @@
"bps": true,
"folderMillis": 1766157362540,
"hash": "7a8ee107778222390e676951173baa81bfa09dd47216a8467575fca54915172c"
},
{
"sql": [
"ALTER TABLE \"agents\" ADD COLUMN IF NOT EXISTS \"session_group_id\" text;",
"\nDO $$ BEGIN\n IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'agents_session_group_id_session_groups_id_fk') THEN\n ALTER TABLE \"agents\" ADD CONSTRAINT \"agents_session_group_id_session_groups_id_fk\" FOREIGN KEY (\"session_group_id\") REFERENCES \"public\".\"session_groups\"(\"id\") ON DELETE set null ON UPDATE no action;\n END IF;\nEND $$;",
"\nCREATE INDEX IF NOT EXISTS \"agents_session_group_id_idx\" ON \"agents\" USING btree (\"session_group_id\");\n"
],
"bps": true,
"folderMillis": 1766297832021,
"hash": "431a620396060130c46d6174d4bef3a517a0872aff8d19f3044bd9e7dec78ba5"
}
]

View File

@@ -15,6 +15,7 @@ import { createInsertSchema } from 'drizzle-zod';
import { idGenerator, randomSlug } from '../utils/idGenerator';
import { timestamps } from './_helpers';
import { files, knowledgeBases } from './file';
import { sessionGroups } from './session';
import { users } from './user';
// Agent table is the main table for storing agents
@@ -60,6 +61,10 @@ export const agents = pgTable(
openingMessage: text('opening_message'),
openingQuestions: text('opening_questions').array().default([]),
sessionGroupId: text('session_group_id').references(() => sessionGroups.id, {
onDelete: 'set null',
}),
...timestamps,
},
(t) => [
@@ -68,6 +73,7 @@ export const agents = pgTable(
index('agents_user_id_idx').on(t.userId),
index('agents_title_idx').on(t.title),
index('agents_description_idx').on(t.description),
index('agents_session_group_id_idx').on(t.sessionGroupId),
],
);