@lenne.tech/nest-server 11.4.0 → 11.4.2
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.
- package/dist/core/common/pipes/map-and-validate.pipe.js +59 -0
- package/dist/core/common/pipes/map-and-validate.pipe.js.map +1 -1
- package/dist/core/modules/migrate/templates/migration-project.template.ts +53 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/core/common/pipes/map-and-validate.pipe.ts +67 -0
- package/src/core/modules/migrate/MIGRATION_FROM_NODEPIT.md +150 -71
- package/src/core/modules/migrate/README.md +9 -8
- package/src/core/modules/migrate/templates/migration-project.template.ts +53 -0
- package/dist/core/modules/migrate/templates/migration-with-helper.template.d.ts +0 -2
- package/dist/core/modules/migrate/templates/migration-with-helper.template.js +0 -10
- package/dist/core/modules/migrate/templates/migration-with-helper.template.js.map +0 -1
- package/dist/core/modules/migrate/templates/migration.template.d.ts +0 -2
- package/dist/core/modules/migrate/templates/migration.template.js +0 -15
- package/dist/core/modules/migrate/templates/migration.template.js.map +0 -1
- package/src/core/modules/migrate/templates/migration-with-helper.template.ts +0 -72
- package/src/core/modules/migrate/templates/migration.template.ts +0 -59
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Db } from 'mongodb';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Migration template for nest-server
|
|
5
|
-
*
|
|
6
|
-
* This template can be used with the migrate CLI:
|
|
7
|
-
* migrate create --template-file ./node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/templates/migration.template.js
|
|
8
|
-
*
|
|
9
|
-
* Or copy this file to your project's migrations-utils folder and customize it.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Get database connection
|
|
14
|
-
*
|
|
15
|
-
* IMPORTANT: Replace this function with your actual database connection logic.
|
|
16
|
-
* This is a placeholder that should import your project's config.
|
|
17
|
-
*/
|
|
18
|
-
const getDb = async (): Promise<Db> => {
|
|
19
|
-
// TODO: Import your config and return the database connection
|
|
20
|
-
// Example:
|
|
21
|
-
// import config from '../src/config.env';
|
|
22
|
-
// const { MongoClient } = require('mongodb');
|
|
23
|
-
// const client = await MongoClient.connect(config.mongoose.uri);
|
|
24
|
-
// return client.db();
|
|
25
|
-
|
|
26
|
-
throw new Error(
|
|
27
|
-
'Please configure the getDb() function in this migration file or use the migration helper from @lenne.tech/nest-server',
|
|
28
|
-
);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Run migration
|
|
33
|
-
*
|
|
34
|
-
* Code your update script here!
|
|
35
|
-
*/
|
|
36
|
-
export const up = async () => {
|
|
37
|
-
const db: Db = await getDb();
|
|
38
|
-
|
|
39
|
-
// Example: Add a new field to all documents in a collection
|
|
40
|
-
// await db.collection('users').updateMany(
|
|
41
|
-
// { email: { $exists: false } },
|
|
42
|
-
// { $set: { email: '' } }
|
|
43
|
-
// );
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Rollback migration
|
|
48
|
-
*
|
|
49
|
-
* Code your downgrade script here!
|
|
50
|
-
*/
|
|
51
|
-
export const down = async () => {
|
|
52
|
-
const db: Db = await getDb();
|
|
53
|
-
|
|
54
|
-
// Example: Remove the field added in the up() function
|
|
55
|
-
// await db.collection('users').updateMany(
|
|
56
|
-
// {},
|
|
57
|
-
// { $unset: { email: '' } }
|
|
58
|
-
// );
|
|
59
|
-
};
|