@lenne.tech/nest-server 11.4.0 → 11.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ import { getDb, uploadFileToGridFS } from '@lenne.tech/nest-server';
2
+ import { Db, ObjectId } from 'mongodb';
3
+ import config from '../src/config.env';
4
+
5
+ /**
6
+ * Migration template for nest-server projects
7
+ *
8
+ * This template is ready-to-use for @lenne.tech/nest-server projects.
9
+ * It imports the necessary helpers and config automatically.
10
+ *
11
+ * Available helpers:
12
+ * - getDb(uri): Get MongoDB connection
13
+ * - uploadFileToGridFS(uri, filePath, options): Upload file to GridFS
14
+ */
15
+
16
+ const MONGO_URL = config.mongoose.uri;
17
+
18
+ /**
19
+ * Run migration
20
+ *
21
+ * Code your update script here!
22
+ */
23
+ export const up = async () => {
24
+ const db: Db = await getDb(MONGO_URL);
25
+
26
+ // Example: Add a new field to all documents in a collection
27
+ // await db.collection('users').updateMany(
28
+ // { email: { $exists: false } },
29
+ // { $set: { email: '' } }
30
+ // );
31
+
32
+ // Example: Upload a file to GridFS
33
+ // const fileId: ObjectId = await uploadFileToGridFS(
34
+ // MONGO_URL,
35
+ // '../assets/image.png',
36
+ // { bucketName: 'images', filename: 'logo.png' }
37
+ // );
38
+ };
39
+
40
+ /**
41
+ * Rollback migration
42
+ *
43
+ * Code your downgrade script here!
44
+ */
45
+ export const down = async () => {
46
+ const db: Db = await getDb(MONGO_URL);
47
+
48
+ // Example: Remove the field added in the up() function
49
+ // await db.collection('users').updateMany(
50
+ // {},
51
+ // { $unset: { email: '' } }
52
+ // );
53
+ };