Skip to content

Commit 8243f01

Browse files
authored
♻️ refactor: update sql and types (#4979)
1 parent 74fd0dc commit 8243f01

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

src/database/migrations/0006_add_knowledge_base.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ CREATE TABLE IF NOT EXISTS "unstructured_chunks" (
121121
"file_id" varchar
122122
);
123123
--> statement-breakpoint
124-
ALTER TABLE "files_to_messages" RENAME TO "messages_files";
124+
ALTER TABLE "files_to_messages" RENAME TO "messages_files";--> statement-breakpoint
125125
DROP TABLE "files_to_agents";--> statement-breakpoint
126126
ALTER TABLE "files" ADD COLUMN "file_hash" varchar(64);--> statement-breakpoint
127127
ALTER TABLE "files" ADD COLUMN "chunk_task_id" uuid;--> statement-breakpoint

src/database/migrations/0007_fix_embedding_table.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ CREATE TEMP TABLE embeddings_temp AS
33
SELECT DISTINCT ON (chunk_id) *
44
FROM embeddings
55
ORDER BY chunk_id, random();
6+
--> statement-breakpoint
67

78
-- step 2: delete all rows from the original table
89
DELETE FROM embeddings;
10+
--> statement-breakpoint
911

1012
-- step 3: insert the rows we want to keep back into the original table
1113
INSERT INTO embeddings
1214
SELECT * FROM embeddings_temp;
15+
--> statement-breakpoint
1316

1417
-- step 4: drop the temporary table
1518
DROP TABLE embeddings_temp;
19+
--> statement-breakpoint
1620

1721
-- step 5: now it's safe to add the unique constraint
1822
ALTER TABLE "embeddings" ADD CONSTRAINT "embeddings_chunk_id_unique" UNIQUE("chunk_id");

src/database/server/models/topic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Column, count, inArray, sql } from 'drizzle-orm';
22
import { and, desc, eq, exists, isNull, like, or } from 'drizzle-orm/expressions';
33

44
import { LobeChatDatabase } from '@/database/type';
5+
import { idGenerator } from '@/database/utils/idGenerator';
56

67
import { NewMessage, TopicItem, messages, topics } from '../../schemas';
7-
import { idGenerator } from '@/database/utils/idGenerator';
88

99
export interface CreateTopicParams {
1010
favorite?: boolean;

src/services/import/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class ClientService {
3232
}
3333

3434
if (sessionGroups.length > 0) {
35-
const res = await SessionGroupModel.batchCreate(sessionGroups);
35+
const res = await SessionGroupModel.batchCreate(sessionGroups as any);
3636
sessionGroupResult = this.mapImportResult(res);
3737
}
3838

src/types/importer.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
MessageRoleType,
99
} from '@/types/message';
1010
import { MetaData } from '@/types/meta';
11-
import { SessionGroupId, SessionGroupItem } from '@/types/session';
11+
import { SessionGroupId } from '@/types/session';
1212
import { ChatTopic } from '@/types/topic';
1313

1414
interface ImportSession {
@@ -64,9 +64,17 @@ interface ImportMessage {
6464
updatedAt: number;
6565
}
6666

67+
interface ImportSessionGroup {
68+
createdAt: number;
69+
id: string;
70+
name: string;
71+
sort?: number | null;
72+
updatedAt: number;
73+
}
74+
6775
export interface ImporterEntryData {
6876
messages?: ImportMessage[];
69-
sessionGroups?: SessionGroupItem[];
77+
sessionGroups?: ImportSessionGroup[];
7078
sessions?: ImportSession[];
7179
topics?: ChatTopic[];
7280
version: number;

0 commit comments

Comments
 (0)