File size: 963 Bytes
1607c14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { Migration } from ".";
import { collections } from "$lib/server/database";
import { ObjectId } from "mongodb";

const migration: Migration = {
	_id: new ObjectId("000000000000000000000012"),
	name: "Add locked field to personas",
	up: async () => {
		const { settings } = collections;

		// Add locked: true to all default personas
		// Default personas are identified by isDefault: true
		await settings.updateMany(
			{ "personas.isDefault": true },
			{
				$set: {
					"personas.$[elem].locked": true,
					updatedAt: new Date(),
				},
			},
			{
				arrayFilters: [{ "elem.isDefault": true }],
			}
		);

		// Add archived: false by default
		await settings.updateMany(
			{ "personas.archived": { $exists: false } },
			{
				$set: {
					"personas.$[elem].archived": false,
					updatedAt: new Date(),
				},
			},
			{
				arrayFilters: [{ "elem.archived": { $exists: false } }],
			}
		);

		return true;
	},
};

export default migration;