Spaces:
Runtime error
Runtime error
Commit ·
d922910
1
Parent(s): 76a5c60
Add database migration to replace customPrompts with personas in user settings
Browse files
src/lib/migrations/routines/11-add-personas.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Migration } from ".";
|
| 2 |
+
import { collections } from "$lib/server/database";
|
| 3 |
+
import { DEFAULT_PERSONAS } from "$lib/server/defaultPersonas";
|
| 4 |
+
import { ObjectId } from "mongodb";
|
| 5 |
+
|
| 6 |
+
const migration: Migration = {
|
| 7 |
+
_id: new ObjectId("000000000000000000000011"),
|
| 8 |
+
name: "Add personas to settings",
|
| 9 |
+
up: async () => {
|
| 10 |
+
const { settings } = collections;
|
| 11 |
+
|
| 12 |
+
// Add personas array and activePersona to all existing settings
|
| 13 |
+
await settings.updateMany(
|
| 14 |
+
{},
|
| 15 |
+
{
|
| 16 |
+
$set: {
|
| 17 |
+
activePersona: "default",
|
| 18 |
+
personas: DEFAULT_PERSONAS.map((p) => ({
|
| 19 |
+
...p,
|
| 20 |
+
createdAt: new Date(),
|
| 21 |
+
updatedAt: new Date(),
|
| 22 |
+
})),
|
| 23 |
+
updatedAt: new Date(),
|
| 24 |
+
},
|
| 25 |
+
// Remove customPrompts field
|
| 26 |
+
$unset: {
|
| 27 |
+
customPrompts: "",
|
| 28 |
+
},
|
| 29 |
+
}
|
| 30 |
+
);
|
| 31 |
+
|
| 32 |
+
return true;
|
| 33 |
+
},
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
export default migration;
|