fix, feat(telegram): fix typo, make chat_id unique (#99)

* 📝 doc(db): add database schema changes for chat_id
- update the schema to enforce unique constraints on chat_id
- added onConflictDoUpdate to handle duplicate entries

* 🔧 chore(telegram-bot): Rename embedding dimension variable
This commit is contained in:
Leohearts
2025-03-26 17:10:54 +08:00
committed by GitHub
parent c7aa0e5436
commit b34c397b8e
4 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -13,6 +13,6 @@ LLM_VISION_MODEL=''
EMBEDDING_API_BASE_URL=''
EMBEDDING_API_KEY=''
EMBEDDING_MODEL=''
EMBEDDING_DIMENSIONS=''
EMBEDDING_DIMENSION=''
ADMIN_USER_IDS=''
@@ -19,7 +19,7 @@ CREATE TABLE "chat_messages" (
CREATE TABLE "joined_chats" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"platform" text DEFAULT '' NOT NULL,
"chat_id" text DEFAULT '' NOT NULL,
"chat_id" text DEFAULT '' UNIQUE NOT NULL,
"chat_name" text DEFAULT '' NOT NULL,
"created_at" bigint DEFAULT 0 NOT NULL,
"updated_at" bigint DEFAULT 0 NOT NULL
+1 -1
View File
@@ -60,7 +60,7 @@ export const joinedChatsTable = pgTable('joined_chats', () => {
return {
id: uuid().primaryKey().defaultRandom(),
platform: text().notNull().default(''),
chat_id: text().notNull().default(''),
chat_id: text().notNull().default('').unique(),
chat_name: text().notNull().default(''),
created_at: bigint({ mode: 'number' }).notNull().default(0).$defaultFn(() => Date.now()),
updated_at: bigint({ mode: 'number' }).notNull().default(0).$defaultFn(() => Date.now()),
+7 -1
View File
@@ -19,5 +19,11 @@ export async function recordJoinedChat(chatId: string, chatName: string) {
chat_id: chatId,
chat_name: chatName,
})
.onConflictDoNothing()
.onConflictDoUpdate({
target: joinedChatsTable.chat_id,
set: {
chat_name: chatName,
updated_at: Date.now(),
},
})
}