Skip to content

Commit 7fb29ea

Browse files
committed
feat: add migration to update reports with assistantId to use contentId
1 parent 719bb8a commit 7fb29ea

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { collections } from "$lib/server/database";
2+
import type { Migration } from ".";
3+
import { ObjectId } from "mongodb";
4+
5+
const migration: Migration = {
6+
_id: new ObjectId("000000000000000000000010"),
7+
name: "Update reports with assistantId to use contentId",
8+
up: async () => {
9+
await collections.reports.updateMany(
10+
{
11+
assistantId: { $exists: true, $ne: null },
12+
},
13+
[
14+
{
15+
$set: {
16+
object: "assistant",
17+
contentId: "$assistantId",
18+
},
19+
},
20+
{
21+
$unset: "assistantId",
22+
},
23+
]
24+
);
25+
return true;
26+
},
27+
};
28+
29+
export default migration;

src/lib/migrations/routines/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import trimMessageUpdates from "./06-trim-message-updates";
1010
import resetTools from "./07-reset-tools-in-settings";
1111
import updateFeaturedToReview from "./08-update-featured-to-review";
1212
import deleteEmptyConversations from "./09-delete-empty-conversations";
13+
import updateReportsAssistantId from "./10-update-reports-assistantid";
14+
1315
export interface Migration {
1416
_id: ObjectId;
1517
name: string;
@@ -30,4 +32,5 @@ export const migrations: Migration[] = [
3032
resetTools,
3133
updateFeaturedToReview,
3234
deleteEmptyConversations,
35+
updateReportsAssistantId,
3336
];

0 commit comments

Comments
 (0)