@velocitycareerlabs/migrations 1.24.0-dev-build.1d6c1d5bb → 1.24.0-dev-build.1f1cfedde
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/package.json +2 -2
- package/src/migrations.js +30 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velocitycareerlabs/migrations",
|
|
3
|
-
"version": "1.24.0-dev-build.
|
|
3
|
+
"version": "1.24.0-dev-build.1f1cfedde",
|
|
4
4
|
"description": "package for functions needed to support migrations",
|
|
5
5
|
"repository": "https://github.com/velocitycareerlabs/packages",
|
|
6
6
|
"main": "index.js",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"jest": "29.7.0",
|
|
31
31
|
"prettier": "2.8.8"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "5083b020cac6464424da46733e19c9e2dc710eeb"
|
|
34
34
|
}
|
package/src/migrations.js
CHANGED
|
@@ -79,4 +79,33 @@ const bulkMigrateAtomic = async (func, db, client) => {
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
const buildWrites = async (
|
|
83
|
+
collectionName,
|
|
84
|
+
filter,
|
|
85
|
+
projection,
|
|
86
|
+
buildFunc,
|
|
87
|
+
db
|
|
88
|
+
) => {
|
|
89
|
+
const collection = db.collection(collectionName);
|
|
90
|
+
const cursor = await collection.find(filter).project(projection);
|
|
91
|
+
return buildUpdatesFromCursor(buildFunc, cursor);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const buildUpdatesFromCursor = async (buildFunc, cursor) => {
|
|
95
|
+
const writes = [];
|
|
96
|
+
for await (const doc of cursor) {
|
|
97
|
+
const write = buildFunc(doc);
|
|
98
|
+
if (write != null) {
|
|
99
|
+
writes.push(write);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
await cursor.rewind();
|
|
103
|
+
return writes;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
module.exports = {
|
|
107
|
+
injectEnv,
|
|
108
|
+
bulkWriteInSession,
|
|
109
|
+
bulkMigrateAtomic,
|
|
110
|
+
buildWrites,
|
|
111
|
+
};
|