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:
@@ -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
|
||||
|
||||
@@ -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()),
|
||||
|
||||
@@ -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(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user