extonlawrence commited on
Commit
1607c14
·
1 Parent(s): 4275aca

Add migration for locked and archived persona fields

Browse files
src/lib/migrations/routines/12-add-locked-field-to-personas.ts ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { Migration } from ".";
2
+ import { collections } from "$lib/server/database";
3
+ import { ObjectId } from "mongodb";
4
+
5
+ const migration: Migration = {
6
+ _id: new ObjectId("000000000000000000000012"),
7
+ name: "Add locked field to personas",
8
+ up: async () => {
9
+ const { settings } = collections;
10
+
11
+ // Add locked: true to all default personas
12
+ // Default personas are identified by isDefault: true
13
+ await settings.updateMany(
14
+ { "personas.isDefault": true },
15
+ {
16
+ $set: {
17
+ "personas.$[elem].locked": true,
18
+ updatedAt: new Date(),
19
+ },
20
+ },
21
+ {
22
+ arrayFilters: [{ "elem.isDefault": true }],
23
+ }
24
+ );
25
+
26
+ // Add archived: false by default
27
+ await settings.updateMany(
28
+ { "personas.archived": { $exists: false } },
29
+ {
30
+ $set: {
31
+ "personas.$[elem].archived": false,
32
+ updatedAt: new Date(),
33
+ },
34
+ },
35
+ {
36
+ arrayFilters: [{ "elem.archived": { $exists: false } }],
37
+ }
38
+ );
39
+
40
+ return true;
41
+ },
42
+ };
43
+
44
+ export default migration;