@unchainedshop/core-users 1.2.40 → 2.0.0-beta2
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.
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { UsersCollection } from '../db/UsersCollection';
|
|
2
|
+
const convertTagsToLowerCase = async (collection) => {
|
|
3
|
+
let bulk = collection.initializeUnorderedBulkOp();
|
|
4
|
+
let count = 0;
|
|
5
|
+
const cursor = await collection.find({ tags: { $regex: '.*[A-Z]' } });
|
|
6
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
7
|
+
for await (const doc of cursor) {
|
|
8
|
+
const transformedTags = doc.tags.map((tag) => tag.toLowerCase());
|
|
9
|
+
count += 1;
|
|
10
|
+
bulk.find({ _id: doc._id }).updateOne({ $set: { tags: transformedTags } });
|
|
11
|
+
if (count % 500 === 0) {
|
|
12
|
+
bulk.execute();
|
|
13
|
+
bulk = collection.initializeUnorderedBulkOp();
|
|
14
|
+
count = 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (count > 0)
|
|
18
|
+
bulk.execute();
|
|
19
|
+
};
|
|
2
20
|
export default function addMigrations(repository) {
|
|
3
21
|
repository?.register({
|
|
4
22
|
id: 20220603115000,
|
|
@@ -15,5 +33,13 @@ export default function addMigrations(repository) {
|
|
|
15
33
|
}));
|
|
16
34
|
},
|
|
17
35
|
});
|
|
36
|
+
repository?.register({
|
|
37
|
+
id: 20220920122500,
|
|
38
|
+
name: 'Convert user tags to lower case for easy search',
|
|
39
|
+
up: async () => {
|
|
40
|
+
const Users = await UsersCollection(repository.db);
|
|
41
|
+
await convertTagsToLowerCase(Users);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
18
44
|
}
|
|
19
45
|
//# sourceMappingURL=addMigrations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addMigrations.js","sourceRoot":"","sources":["../../src/module/addMigrations.ts"],"names":[],"mappings":"
|
|
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AG,MAAM,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACnD,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,IAAI,CAC5B,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,sBAAsB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EACvE,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CACzD,CAAC,OAAO,EAAE,CAAC;YAEZ,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;gBACvB,MAAM,KAAK,CAAC,SAAS,CACnB;oBACE,GAAG,EAAE,IAAI,CAAC,GAAG;iBACd,EACD;oBACE,IAAI,EAAE,EAAE,IAAI,EAAG,IAAI,CAAC,OAAe,CAAC,YAAY,EAAE;iBACnD,CACF,CAAC;YACJ,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,UAAU,EAAE,QAAQ,CAAC;QACnB,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,iDAAiD;QACvD,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACnD,MAAM,sBAAsB,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-users",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta2",
|
|
4
4
|
"main": "lib/users-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/users-index.js",
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unchainedshop/events": "^
|
|
34
|
-
"@unchainedshop/file-upload": "^
|
|
35
|
-
"@unchainedshop/logger": "^
|
|
36
|
-
"@unchainedshop/roles": "^
|
|
37
|
-
"@unchainedshop/utils": "^
|
|
33
|
+
"@unchainedshop/events": "^2.0.0-beta2",
|
|
34
|
+
"@unchainedshop/file-upload": "^2.0.0-beta2",
|
|
35
|
+
"@unchainedshop/logger": "^2.0.0-beta2",
|
|
36
|
+
"@unchainedshop/roles": "^2.0.0-beta2",
|
|
37
|
+
"@unchainedshop/utils": "^2.0.0-beta2",
|
|
38
38
|
"locale": "^0.1.0",
|
|
39
39
|
"simpl-schema": "^3.0.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "^16.11.
|
|
43
|
-
"@unchainedshop/types": "^
|
|
44
|
-
"jest": "^29.2.
|
|
42
|
+
"@types/node": "^16.11.68",
|
|
43
|
+
"@unchainedshop/types": "^2.0.0-beta2",
|
|
44
|
+
"jest": "^29.2.1",
|
|
45
45
|
"ts-jest": "^29.0.3",
|
|
46
46
|
"typescript": "^4.8.4"
|
|
47
47
|
}
|
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import { Migration, MigrationRepository } from '@unchainedshop/types/core';
|
|
2
|
+
import { Collection } from 'mongodb';
|
|
2
3
|
|
|
3
4
|
import { UsersCollection } from '../db/UsersCollection';
|
|
4
5
|
|
|
6
|
+
const convertTagsToLowerCase = async (collection: Collection<any>) => {
|
|
7
|
+
let bulk = collection.initializeUnorderedBulkOp();
|
|
8
|
+
let count = 0;
|
|
9
|
+
|
|
10
|
+
const cursor = await collection.find({ tags: { $regex: '.*[A-Z]' } });
|
|
11
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
12
|
+
for await (const doc of cursor) {
|
|
13
|
+
const transformedTags = doc.tags.map((tag) => tag.toLowerCase());
|
|
14
|
+
count += 1;
|
|
15
|
+
bulk.find({ _id: doc._id }).updateOne({ $set: { tags: transformedTags } });
|
|
16
|
+
if (count % 500 === 0) {
|
|
17
|
+
bulk.execute();
|
|
18
|
+
bulk = collection.initializeUnorderedBulkOp();
|
|
19
|
+
count = 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (count > 0) bulk.execute();
|
|
23
|
+
};
|
|
24
|
+
|
|
5
25
|
export default function addMigrations(repository: MigrationRepository<Migration>) {
|
|
6
26
|
repository?.register({
|
|
7
27
|
id: 20220603115000,
|
|
@@ -27,4 +47,13 @@ export default function addMigrations(repository: MigrationRepository<Migration>
|
|
|
27
47
|
);
|
|
28
48
|
},
|
|
29
49
|
});
|
|
50
|
+
|
|
51
|
+
repository?.register({
|
|
52
|
+
id: 20220920122500,
|
|
53
|
+
name: 'Convert user tags to lower case for easy search',
|
|
54
|
+
up: async () => {
|
|
55
|
+
const Users = await UsersCollection(repository.db);
|
|
56
|
+
await convertTagsToLowerCase(Users);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
30
59
|
}
|