@aneuhold/be-ts-db-lib 3.0.2 → 3.0.4
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/CHANGELOG.md
CHANGED
|
@@ -5,10 +5,25 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 🔖 [3.0.4] (2025-12-07)
|
|
9
|
+
|
|
10
|
+
### 🏗️ Changed
|
|
11
|
+
|
|
12
|
+
- Updated dependencies: now requires `@aneuhold/be-ts-lib@^3.0.3`, `@aneuhold/core-ts-db-lib@^3.0.3`, `@aneuhold/core-ts-lib@^2.3.13`, and `@aneuhold/local-npm-registry@^0.2.20`.
|
|
13
|
+
|
|
14
|
+
## 🔖 [3.0.3] (2025-11-29)
|
|
15
|
+
|
|
16
|
+
### 🏗️ Changed
|
|
17
|
+
|
|
18
|
+
- Updated dependencies: now requires `@aneuhold/be-ts-lib@^3.0.2`, `@aneuhold/core-ts-db-lib@^3.0.2`, `@aneuhold/core-ts-lib@^2.3.12`, and `@aneuhold/local-npm-registry@^0.2.19`.
|
|
19
|
+
- Development dependencies updated for compatibility: `@types/node`, `prettier`, `rimraf`, and `vitest`.
|
|
20
|
+
- Migration logic in `MigrationService` refactored to delete legacy documents (ObjectId) instead of migrated documents (string IDs).
|
|
21
|
+
- Improved migration mapping and document creation for user-related entities.
|
|
8
22
|
|
|
9
23
|
## 🔖 [3.0.2] (2025-11-26)
|
|
10
24
|
|
|
11
25
|
### 🏗️ Changed
|
|
26
|
+
|
|
12
27
|
- Updated all type signatures and internal logic to use `UUID` instead of `string` for document IDs in repository and migration services.
|
|
13
28
|
- Updated dependency: now requires `@aneuhold/core-ts-db-lib@^3.0.1` and `@aneuhold/local-npm-registry@^0.2.18`.
|
|
14
29
|
|
|
@@ -110,6 +125,9 @@ Updated dependencies: now requires `@aneuhold/core-ts-db-lib@^3.0.0`, `@aneuhold
|
|
|
110
125
|
- Updated workflow permissions to allow repository write access
|
|
111
126
|
|
|
112
127
|
<!-- Link References -->
|
|
128
|
+
|
|
129
|
+
[3.0.4]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v3.0.3...be-ts-db-lib-v3.0.4
|
|
130
|
+
[3.0.3]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v3.0.2...be-ts-db-lib-v3.0.3
|
|
113
131
|
[3.0.2]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v3.0.1...be-ts-db-lib-v3.0.2
|
|
114
132
|
[3.0.1]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v3.0.0...be-ts-db-lib-v3.0.1
|
|
115
133
|
[3.0.0]: https://github.com/aneuhold/ts-libs/compare/be-ts-db-lib-v2.0.85...be-ts-db-lib-v3.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationService.d.ts","sourceRoot":"","sources":["../../src/services/MigrationService.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC;;;;;;;;OAQG;WACU,SAAS,CAAC,MAAM,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"MigrationService.d.ts","sourceRoot":"","sources":["../../src/services/MigrationService.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC;;;;;;;;OAQG;WACU,SAAS,CAAC,MAAM,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAkHtD"}
|
|
@@ -60,304 +60,326 @@ export default class MigrationService {
|
|
|
60
60
|
const legacyDocs = allDocs.filter((doc) => typeof doc._id === 'object');
|
|
61
61
|
const newDocs = allDocs.filter((doc) => typeof doc._id === 'string');
|
|
62
62
|
DR.logger.info(`Found ${legacyDocs.length} documents with legacy ObjectId IDs and ${newDocs.length} documents with string IDs.`);
|
|
63
|
-
// Delete all existing
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const nonogramUpgradeIdsToDelete = nonogramUpgrades
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
63
|
+
// Delete all existing legacy docs (with object IDs)
|
|
64
|
+
if (legacyDocs.length > 0) {
|
|
65
|
+
const userIdsToDelete = users.filter((u) => typeof u._id === 'object').map((u) => u._id);
|
|
66
|
+
const apiKeyIdsToDelete = apiKeys.filter((k) => typeof k._id === 'object').map((k) => k._id);
|
|
67
|
+
const taskIdsToDelete = tasks.filter((t) => typeof t._id === 'object').map((t) => t._id);
|
|
68
|
+
const configIdsToDelete = configs.filter((c) => typeof c._id === 'object').map((c) => c._id);
|
|
69
|
+
const nonogramItemIdsToDelete = nonogramItems
|
|
70
|
+
.filter((i) => typeof i._id === 'object')
|
|
71
|
+
.map((i) => i._id);
|
|
72
|
+
const nonogramUpgradeIdsToDelete = nonogramUpgrades
|
|
73
|
+
.filter((u) => typeof u._id === 'object')
|
|
74
|
+
.map((u) => u._id);
|
|
75
|
+
if (!dryRun) {
|
|
76
|
+
DR.logger.info(`Deleting ${legacyDocs.length} legacy documents...`);
|
|
77
|
+
if (userIdsToDelete.length > 0) {
|
|
78
|
+
const result = await (await userRepo.getCollection()).deleteMany({ _id: { $in: userIdsToDelete } });
|
|
79
|
+
DR.logger.info(`Deleted ${result.deletedCount} users.`);
|
|
80
|
+
}
|
|
81
|
+
if (apiKeyIdsToDelete.length > 0) {
|
|
82
|
+
const result = await (await apiKeyRepo.getCollection()).deleteMany({ _id: { $in: apiKeyIdsToDelete } });
|
|
83
|
+
DR.logger.info(`Deleted ${result.deletedCount} API keys.`);
|
|
84
|
+
}
|
|
85
|
+
if (taskIdsToDelete.length > 0) {
|
|
86
|
+
const result = await (await taskRepo.getCollection()).deleteMany({ _id: { $in: taskIdsToDelete } });
|
|
87
|
+
DR.logger.info(`Deleted ${result.deletedCount} tasks.`);
|
|
88
|
+
}
|
|
89
|
+
if (configIdsToDelete.length > 0) {
|
|
90
|
+
const result = await (await configRepo.getCollection()).deleteMany({ _id: { $in: configIdsToDelete } });
|
|
91
|
+
DR.logger.info(`Deleted ${result.deletedCount} configs.`);
|
|
92
|
+
}
|
|
93
|
+
if (nonogramItemIdsToDelete.length > 0) {
|
|
94
|
+
const result = await (await nonogramItemRepo.getCollection()).deleteMany({ _id: { $in: nonogramItemIdsToDelete } });
|
|
95
|
+
DR.logger.info(`Deleted ${result.deletedCount} nonogram items.`);
|
|
96
|
+
}
|
|
97
|
+
if (nonogramUpgradeIdsToDelete.length > 0) {
|
|
98
|
+
const result = await (await nonogramUpgradesRepo.getCollection()).deleteMany({ _id: { $in: nonogramUpgradeIdsToDelete } });
|
|
99
|
+
DR.logger.info(`Deleted ${result.deletedCount} nonogram upgrades.`);
|
|
100
|
+
}
|
|
101
|
+
DR.logger.info('Deletion complete.');
|
|
92
102
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
else {
|
|
104
|
+
DR.logger.info(`Dry run: Would delete ${legacyDocs.length} legacy documents.`);
|
|
105
|
+
if (userIdsToDelete.length > 0)
|
|
106
|
+
DR.logger.info(` - ${userIdsToDelete.length} users`);
|
|
107
|
+
if (apiKeyIdsToDelete.length > 0)
|
|
108
|
+
DR.logger.info(` - ${apiKeyIdsToDelete.length} API keys`);
|
|
109
|
+
if (taskIdsToDelete.length > 0)
|
|
110
|
+
DR.logger.info(` - ${taskIdsToDelete.length} tasks`);
|
|
111
|
+
if (configIdsToDelete.length > 0)
|
|
112
|
+
DR.logger.info(` - ${configIdsToDelete.length} configs`);
|
|
113
|
+
if (nonogramItemIdsToDelete.length > 0)
|
|
114
|
+
DR.logger.info(` - ${nonogramItemIdsToDelete.length} nonogram items`);
|
|
115
|
+
if (nonogramUpgradeIdsToDelete.length > 0)
|
|
116
|
+
DR.logger.info(` - ${nonogramUpgradeIdsToDelete.length} nonogram upgrades`);
|
|
96
117
|
}
|
|
97
|
-
DR.logger.info('Deletion complete. Starting fresh migration...');
|
|
98
118
|
}
|
|
99
|
-
|
|
100
|
-
|
|
119
|
+
// We started with 1204 docs
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function Migration2025UUID() {
|
|
123
|
+
// Now create the actual map
|
|
124
|
+
const mapFromObjectIdToUUID = new Map();
|
|
125
|
+
const newUsersToCreate = [];
|
|
126
|
+
const newApiKeysToCreate = [];
|
|
127
|
+
const newTasksToCreate = [];
|
|
128
|
+
const newConfigsToCreate = [];
|
|
129
|
+
const newNonogramItemsToCreate = [];
|
|
130
|
+
const newNonogramUpgradesToCreate = [];
|
|
131
|
+
/**
|
|
132
|
+
* Gets a UUID for a given legacy ObjectId. If one already exists in the map,
|
|
133
|
+
* it is returned. Otherwise, a new one is generated and added to the map.
|
|
134
|
+
*/
|
|
135
|
+
const getUUID = (oldId) => {
|
|
136
|
+
const oldIdStr = oldId.toString();
|
|
137
|
+
if (mapFromObjectIdToUUID.has(oldIdStr)) {
|
|
138
|
+
return mapFromObjectIdToUUID.get(oldIdStr);
|
|
101
139
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// Create a map of UUID to documents
|
|
124
|
-
const mapFromUUIDToDocument = new Map();
|
|
125
|
-
const verifyDoc = (oldDoc, newDoc) => {
|
|
126
|
-
const oldJson = JSON.stringify(oldDoc, null, 2);
|
|
127
|
-
const newJson = JSON.stringify(newDoc, null, 2);
|
|
128
|
-
const oldLines = oldJson.split('\n').length;
|
|
129
|
-
const newLines = newJson.split('\n').length;
|
|
130
|
-
if (newLines !== oldLines + 1) {
|
|
131
|
-
DR.logger.warn(`Line count mismatch for ${oldDoc.docType || 'doc'} ${oldDoc._id}: Old=${oldLines}, New=${newLines}.`);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
function createNewDoc(oldDoc) {
|
|
135
|
-
if (mapFromObjectIdToUUID.has(oldDoc._id.toString()) && mapFromUUIDToDocument.has(mapFromObjectIdToUUID.get(oldDoc._id.toString()))) {
|
|
136
|
-
console.warn(`Skipping document ${oldDoc._id} as it was already migrated.` +
|
|
137
|
-
` The created document is ${JSON.stringify(mapFromUUIDToDocument.get(mapFromObjectIdToUUID.get(oldDoc._id.toString())))}`);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const newDocId = getUUID(oldDoc._id);
|
|
141
|
-
const newDoc = DocumentService.deepCopy(oldDoc);
|
|
142
|
-
newDoc._id = newDocId;
|
|
143
|
-
newDoc.oldOId = oldDoc._id.toString();
|
|
144
|
-
mapFromUUIDToDocument.set(newDocId, newDoc);
|
|
145
|
-
return newDoc;
|
|
140
|
+
const newId = uuidv7();
|
|
141
|
+
mapFromObjectIdToUUID.set(oldIdStr, newId);
|
|
142
|
+
return newId;
|
|
143
|
+
};
|
|
144
|
+
// Create a map of UUID to documents
|
|
145
|
+
const mapFromUUIDToDocument = new Map();
|
|
146
|
+
const verifyDoc = (oldDoc, newDoc) => {
|
|
147
|
+
const oldJson = JSON.stringify(oldDoc, null, 2);
|
|
148
|
+
const newJson = JSON.stringify(newDoc, null, 2);
|
|
149
|
+
const oldLines = oldJson.split('\n').length;
|
|
150
|
+
const newLines = newJson.split('\n').length;
|
|
151
|
+
if (newLines !== oldLines + 1) {
|
|
152
|
+
DR.logger.warn(`Line count mismatch for ${oldDoc.docType || 'doc'} ${oldDoc._id}: Old=${oldLines}, New=${newLines}.`);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
function createNewDoc(oldDoc) {
|
|
156
|
+
if (mapFromObjectIdToUUID.has(oldDoc._id.toString()) &&
|
|
157
|
+
mapFromUUIDToDocument.has(mapFromObjectIdToUUID.get(oldDoc._id.toString()))) {
|
|
158
|
+
console.warn(`Skipping document ${oldDoc._id} as it was already migrated.` +
|
|
159
|
+
` The created document is ${JSON.stringify(mapFromUUIDToDocument.get(mapFromObjectIdToUUID.get(oldDoc._id.toString())))}`);
|
|
160
|
+
return;
|
|
146
161
|
}
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
162
|
+
const newDocId = getUUID(oldDoc._id);
|
|
163
|
+
const newDoc = DocumentService.deepCopy(oldDoc);
|
|
164
|
+
newDoc._id = newDocId;
|
|
165
|
+
newDoc.oldOId = oldDoc._id.toString();
|
|
166
|
+
mapFromUUIDToDocument.set(newDocId, newDoc);
|
|
167
|
+
return newDoc;
|
|
168
|
+
}
|
|
169
|
+
// Filter to only legacy users with the chosen usernames
|
|
170
|
+
// const userNames = ['demoUser1', 'demoUser2', "testUser", "testUser2"];
|
|
171
|
+
// const userNames = ["testUser"];
|
|
172
|
+
// const legacyUsers = users.filter((u) => userNames.includes(u.userName) && typeof u._id === 'object');
|
|
173
|
+
const legacyUsers = users.filter((u) => typeof u._id === 'object');
|
|
174
|
+
DR.logger.info(`Found ${legacyUsers.length} legacy users to migrate.`);
|
|
175
|
+
// First, create all user documents and generate their UUIDs that way relationships between
|
|
176
|
+
// users in the collaborators field can be mapped correctly.
|
|
177
|
+
legacyUsers.forEach((oldUserDoc) => {
|
|
178
|
+
const newUser = createNewDoc(oldUserDoc);
|
|
179
|
+
if (!newUser)
|
|
180
|
+
return;
|
|
181
|
+
verifyDoc(oldUserDoc, newUser);
|
|
182
|
+
newUsersToCreate.push(newUser);
|
|
183
|
+
});
|
|
184
|
+
// Create the function that will flesh out new documents for a given user document
|
|
185
|
+
function createNewDocsForUser(oldUserDoc) {
|
|
186
|
+
const oldUserIdStr = oldUserDoc._id.toString();
|
|
187
|
+
const newUserId = getUUID(oldUserDoc._id);
|
|
188
|
+
// 1. Create new API keys
|
|
189
|
+
const userApiKeys = apiKeys.filter((k) => k.userId.toString() === oldUserIdStr);
|
|
190
|
+
userApiKeys.forEach((oldKey) => {
|
|
191
|
+
const newKey = createNewDoc(oldKey);
|
|
192
|
+
if (!newKey)
|
|
157
193
|
return;
|
|
158
|
-
|
|
159
|
-
|
|
194
|
+
newKey.userId = newUserId;
|
|
195
|
+
verifyDoc(oldKey, newKey);
|
|
196
|
+
newApiKeysToCreate.push(newKey);
|
|
160
197
|
});
|
|
161
|
-
// Create
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (!
|
|
170
|
-
|
|
171
|
-
newKey.userId = newUserId;
|
|
172
|
-
verifyDoc(oldKey, newKey);
|
|
173
|
-
newApiKeysToCreate.push(newKey);
|
|
174
|
-
});
|
|
175
|
-
// 2. Create new Tasks
|
|
176
|
-
const userTasks = tasks.filter((t) => t.userId.toString() === oldUserIdStr);
|
|
177
|
-
const taskChildrenMap = new Map();
|
|
178
|
-
const rootTasks = [];
|
|
179
|
-
const userTaskIds = new Set(userTasks.map((t) => t._id.toString()));
|
|
180
|
-
userTasks.forEach((task) => {
|
|
181
|
-
const pId = task.parentTaskId?.toString();
|
|
182
|
-
if (pId && userTaskIds.has(pId)) {
|
|
183
|
-
if (!taskChildrenMap.has(pId)) {
|
|
184
|
-
taskChildrenMap.set(pId, []);
|
|
185
|
-
}
|
|
186
|
-
taskChildrenMap.get(pId).push(task);
|
|
198
|
+
// 2. Create new Tasks
|
|
199
|
+
const userTasks = tasks.filter((t) => t.userId.toString() === oldUserIdStr);
|
|
200
|
+
const taskChildrenMap = new Map();
|
|
201
|
+
const rootTasks = [];
|
|
202
|
+
const userTaskIds = new Set(userTasks.map((t) => t._id.toString()));
|
|
203
|
+
userTasks.forEach((task) => {
|
|
204
|
+
const pId = task.parentTaskId?.toString();
|
|
205
|
+
if (pId && userTaskIds.has(pId)) {
|
|
206
|
+
if (!taskChildrenMap.has(pId)) {
|
|
207
|
+
taskChildrenMap.set(pId, []);
|
|
187
208
|
}
|
|
188
|
-
|
|
189
|
-
|
|
209
|
+
taskChildrenMap.get(pId).push(task);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
rootTasks.push(task);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const queue = [...rootTasks];
|
|
216
|
+
while (queue.length > 0) {
|
|
217
|
+
const oldTask = queue.shift();
|
|
218
|
+
const newTask = createNewDoc(oldTask);
|
|
219
|
+
if (newTask) {
|
|
220
|
+
newTask.userId = newUserId;
|
|
221
|
+
// Map user IDs in tags keys
|
|
222
|
+
const newTags = {};
|
|
223
|
+
Object.keys(oldTask.tags).forEach((tagUserId) => {
|
|
224
|
+
const newTagUserId = getUUID(tagUserId);
|
|
225
|
+
newTags[newTagUserId] = oldTask.tags[tagUserId];
|
|
226
|
+
});
|
|
227
|
+
newTask.tags = newTags;
|
|
228
|
+
// Map user IDs in filterSettings keys
|
|
229
|
+
const newFilterSettings = {};
|
|
230
|
+
Object.keys(oldTask.filterSettings).forEach((fsUserId) => {
|
|
231
|
+
const newFsUserId = getUUID(fsUserId);
|
|
232
|
+
newFilterSettings[newFsUserId] = {
|
|
233
|
+
...oldTask.filterSettings[fsUserId],
|
|
234
|
+
userId: newFsUserId
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
newTask.filterSettings = newFilterSettings;
|
|
238
|
+
// Map user IDs in sortSettings keys
|
|
239
|
+
const newSortSettings = {};
|
|
240
|
+
Object.keys(oldTask.sortSettings).forEach((ssUserId) => {
|
|
241
|
+
const newSsUserId = getUUID(ssUserId);
|
|
242
|
+
newSortSettings[newSsUserId] = {
|
|
243
|
+
...oldTask.sortSettings[ssUserId],
|
|
244
|
+
userId: newSsUserId
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
newTask.sortSettings = newSortSettings;
|
|
248
|
+
newTask.sharedWith = oldTask.sharedWith.map((id) => getUUID(id));
|
|
249
|
+
if (oldTask.assignedTo) {
|
|
250
|
+
newTask.assignedTo = getUUID(oldTask.assignedTo);
|
|
190
251
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
while (queue.length > 0) {
|
|
194
|
-
const oldTask = queue.shift();
|
|
195
|
-
const newTask = createNewDoc(oldTask);
|
|
196
|
-
if (newTask) {
|
|
197
|
-
newTask.userId = newUserId;
|
|
198
|
-
// Map user IDs in tags keys
|
|
199
|
-
const newTags = {};
|
|
200
|
-
Object.keys(oldTask.tags).forEach((tagUserId) => {
|
|
201
|
-
const newTagUserId = getUUID(tagUserId);
|
|
202
|
-
newTags[newTagUserId] = oldTask.tags[tagUserId];
|
|
203
|
-
});
|
|
204
|
-
newTask.tags = newTags;
|
|
205
|
-
// Map user IDs in filterSettings keys
|
|
206
|
-
const newFilterSettings = {};
|
|
207
|
-
Object.keys(oldTask.filterSettings).forEach((fsUserId) => {
|
|
208
|
-
const newFsUserId = getUUID(fsUserId);
|
|
209
|
-
newFilterSettings[newFsUserId] = {
|
|
210
|
-
...oldTask.filterSettings[fsUserId],
|
|
211
|
-
userId: newFsUserId
|
|
212
|
-
};
|
|
213
|
-
});
|
|
214
|
-
newTask.filterSettings = newFilterSettings;
|
|
215
|
-
// Map user IDs in sortSettings keys
|
|
216
|
-
const newSortSettings = {};
|
|
217
|
-
Object.keys(oldTask.sortSettings).forEach((ssUserId) => {
|
|
218
|
-
const newSsUserId = getUUID(ssUserId);
|
|
219
|
-
newSortSettings[newSsUserId] = {
|
|
220
|
-
...oldTask.sortSettings[ssUserId],
|
|
221
|
-
userId: newSsUserId
|
|
222
|
-
};
|
|
223
|
-
});
|
|
224
|
-
newTask.sortSettings = newSortSettings;
|
|
225
|
-
newTask.sharedWith = oldTask.sharedWith.map((id) => getUUID(id));
|
|
226
|
-
if (oldTask.assignedTo) {
|
|
227
|
-
newTask.assignedTo = getUUID(oldTask.assignedTo);
|
|
228
|
-
}
|
|
229
|
-
if (oldTask.parentTaskId) {
|
|
230
|
-
newTask.parentTaskId = getUUID(oldTask.parentTaskId);
|
|
231
|
-
}
|
|
232
|
-
if (oldTask.parentRecurringTaskInfo) {
|
|
233
|
-
newTask.parentRecurringTaskInfo = {
|
|
234
|
-
...oldTask.parentRecurringTaskInfo,
|
|
235
|
-
taskId: getUUID(oldTask.parentRecurringTaskInfo.taskId)
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
verifyDoc(oldTask, newTask);
|
|
239
|
-
newTasksToCreate.push(newTask);
|
|
252
|
+
if (oldTask.parentTaskId) {
|
|
253
|
+
newTask.parentTaskId = getUUID(oldTask.parentTaskId);
|
|
240
254
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
255
|
+
if (oldTask.parentRecurringTaskInfo) {
|
|
256
|
+
newTask.parentRecurringTaskInfo = {
|
|
257
|
+
...oldTask.parentRecurringTaskInfo,
|
|
258
|
+
taskId: getUUID(oldTask.parentRecurringTaskInfo.taskId)
|
|
259
|
+
};
|
|
244
260
|
}
|
|
261
|
+
verifyDoc(oldTask, newTask);
|
|
262
|
+
newTasksToCreate.push(newTask);
|
|
263
|
+
}
|
|
264
|
+
const children = taskChildrenMap.get(oldTask._id.toString());
|
|
265
|
+
if (children) {
|
|
266
|
+
queue.push(...children);
|
|
245
267
|
}
|
|
246
|
-
// 3. Create new Configs
|
|
247
|
-
const userConfigs = configs.filter((c) => c.userId.toString() === oldUserIdStr);
|
|
248
|
-
userConfigs.forEach((oldConfig) => {
|
|
249
|
-
const newConfig = createNewDoc(oldConfig);
|
|
250
|
-
if (!newConfig)
|
|
251
|
-
return;
|
|
252
|
-
newConfig.userId = newUserId;
|
|
253
|
-
newConfig.collaborators = (oldConfig.collaborators || []).map((id) => getUUID(id));
|
|
254
|
-
if (newConfig.taskListSortSettings) {
|
|
255
|
-
Object.entries(newConfig.taskListSortSettings).forEach(([category, settings]) => {
|
|
256
|
-
const newSettings = {
|
|
257
|
-
userId: getUUID(settings.userId),
|
|
258
|
-
sortList: settings.sortList
|
|
259
|
-
};
|
|
260
|
-
newConfig.taskListSortSettings[category] = newSettings;
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
if (newConfig.taskListFilterSettings) {
|
|
264
|
-
Object.entries(newConfig.taskListFilterSettings).forEach(([category, settings]) => {
|
|
265
|
-
const newSettings = {
|
|
266
|
-
...settings,
|
|
267
|
-
userId: getUUID(settings.userId)
|
|
268
|
-
};
|
|
269
|
-
newConfig.taskListFilterSettings[category] = newSettings;
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
verifyDoc(oldConfig, newConfig);
|
|
273
|
-
newConfigsToCreate.push(newConfig);
|
|
274
|
-
});
|
|
275
|
-
// 4. Nonogram Items
|
|
276
|
-
const userNonogramItems = nonogramItems.filter((i) => i.userId.toString() === oldUserIdStr);
|
|
277
|
-
userNonogramItems.forEach((oldItem) => {
|
|
278
|
-
const newItem = createNewDoc(oldItem);
|
|
279
|
-
if (!newItem)
|
|
280
|
-
return;
|
|
281
|
-
newItem.userId = newUserId;
|
|
282
|
-
verifyDoc(oldItem, newItem);
|
|
283
|
-
newNonogramItemsToCreate.push(newItem);
|
|
284
|
-
});
|
|
285
|
-
// 5. Nonogram Upgrades
|
|
286
|
-
const userNonogramUpgrades = nonogramUpgrades.filter((u) => u.userId.toString() === oldUserIdStr);
|
|
287
|
-
userNonogramUpgrades.forEach((oldUpgrade) => {
|
|
288
|
-
const newUpgrade = createNewDoc(oldUpgrade);
|
|
289
|
-
if (!newUpgrade)
|
|
290
|
-
return;
|
|
291
|
-
newUpgrade.userId = newUserId;
|
|
292
|
-
verifyDoc(oldUpgrade, newUpgrade);
|
|
293
|
-
newNonogramUpgradesToCreate.push(newUpgrade);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
// Now create related documents for each user
|
|
297
|
-
legacyUsers.forEach((u) => createNewDocsForUser(u));
|
|
298
|
-
const legacyUserIds = new Set(legacyUsers.map((u) => u._id.toString()));
|
|
299
|
-
const expectedUsers = legacyUsers.length;
|
|
300
|
-
const expectedApiKeys = apiKeys.filter((k) => legacyUserIds.has(k.userId.toString())).length;
|
|
301
|
-
const expectedTasks = tasks.filter((t) => legacyUserIds.has(t.userId.toString())).length;
|
|
302
|
-
const expectedConfigs = configs.filter((c) => legacyUserIds.has(c.userId.toString())).length;
|
|
303
|
-
const expectedNonogramItems = nonogramItems.filter((i) => legacyUserIds.has(i.userId.toString())).length;
|
|
304
|
-
const expectedNonogramUpgrades = nonogramUpgrades.filter((u) => legacyUserIds.has(u.userId.toString())).length;
|
|
305
|
-
if (newUsersToCreate.length !== expectedUsers) {
|
|
306
|
-
DR.logger.error(`Expected ${expectedUsers} users, but prepped ${newUsersToCreate.length}.`);
|
|
307
|
-
}
|
|
308
|
-
if (newApiKeysToCreate.length !== expectedApiKeys) {
|
|
309
|
-
DR.logger.error(`Expected ${expectedApiKeys} API keys, but prepped ${newApiKeysToCreate.length}.`);
|
|
310
268
|
}
|
|
311
|
-
|
|
312
|
-
|
|
269
|
+
// 3. Create new Configs
|
|
270
|
+
const userConfigs = configs.filter((c) => c.userId.toString() === oldUserIdStr);
|
|
271
|
+
userConfigs.forEach((oldConfig) => {
|
|
272
|
+
const newConfig = createNewDoc(oldConfig);
|
|
273
|
+
if (!newConfig)
|
|
274
|
+
return;
|
|
275
|
+
newConfig.userId = newUserId;
|
|
276
|
+
newConfig.collaborators = (oldConfig.collaborators || []).map((id) => getUUID(id));
|
|
277
|
+
if (newConfig.taskListSortSettings) {
|
|
278
|
+
Object.entries(newConfig.taskListSortSettings).forEach(([category, settings]) => {
|
|
279
|
+
const newSettings = {
|
|
280
|
+
userId: getUUID(settings.userId),
|
|
281
|
+
sortList: settings.sortList
|
|
282
|
+
};
|
|
283
|
+
newConfig.taskListSortSettings[category] = newSettings;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
if (newConfig.taskListFilterSettings) {
|
|
287
|
+
Object.entries(newConfig.taskListFilterSettings).forEach(([category, settings]) => {
|
|
288
|
+
const newSettings = {
|
|
289
|
+
...settings,
|
|
290
|
+
userId: getUUID(settings.userId)
|
|
291
|
+
};
|
|
292
|
+
newConfig.taskListFilterSettings[category] = newSettings;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
verifyDoc(oldConfig, newConfig);
|
|
296
|
+
newConfigsToCreate.push(newConfig);
|
|
297
|
+
});
|
|
298
|
+
// 4. Nonogram Items
|
|
299
|
+
const userNonogramItems = nonogramItems.filter((i) => i.userId.toString() === oldUserIdStr);
|
|
300
|
+
userNonogramItems.forEach((oldItem) => {
|
|
301
|
+
const newItem = createNewDoc(oldItem);
|
|
302
|
+
if (!newItem)
|
|
303
|
+
return;
|
|
304
|
+
newItem.userId = newUserId;
|
|
305
|
+
verifyDoc(oldItem, newItem);
|
|
306
|
+
newNonogramItemsToCreate.push(newItem);
|
|
307
|
+
});
|
|
308
|
+
// 5. Nonogram Upgrades
|
|
309
|
+
const userNonogramUpgrades = nonogramUpgrades.filter((u) => u.userId.toString() === oldUserIdStr);
|
|
310
|
+
userNonogramUpgrades.forEach((oldUpgrade) => {
|
|
311
|
+
const newUpgrade = createNewDoc(oldUpgrade);
|
|
312
|
+
if (!newUpgrade)
|
|
313
|
+
return;
|
|
314
|
+
newUpgrade.userId = newUserId;
|
|
315
|
+
verifyDoc(oldUpgrade, newUpgrade);
|
|
316
|
+
newNonogramUpgradesToCreate.push(newUpgrade);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
// Now create related documents for each user
|
|
320
|
+
legacyUsers.forEach((u) => createNewDocsForUser(u));
|
|
321
|
+
const legacyUserIds = new Set(legacyUsers.map((u) => u._id.toString()));
|
|
322
|
+
const expectedUsers = legacyUsers.length;
|
|
323
|
+
const expectedApiKeys = apiKeys.filter((k) => legacyUserIds.has(k.userId.toString())).length;
|
|
324
|
+
const expectedTasks = tasks.filter((t) => legacyUserIds.has(t.userId.toString())).length;
|
|
325
|
+
const expectedConfigs = configs.filter((c) => legacyUserIds.has(c.userId.toString())).length;
|
|
326
|
+
const expectedNonogramItems = nonogramItems.filter((i) => legacyUserIds.has(i.userId.toString())).length;
|
|
327
|
+
const expectedNonogramUpgrades = nonogramUpgrades.filter((u) => legacyUserIds.has(u.userId.toString())).length;
|
|
328
|
+
if (newUsersToCreate.length !== expectedUsers) {
|
|
329
|
+
DR.logger.error(`Expected ${expectedUsers} users, but prepped ${newUsersToCreate.length}.`);
|
|
330
|
+
}
|
|
331
|
+
if (newApiKeysToCreate.length !== expectedApiKeys) {
|
|
332
|
+
DR.logger.error(`Expected ${expectedApiKeys} API keys, but prepped ${newApiKeysToCreate.length}.`);
|
|
333
|
+
}
|
|
334
|
+
if (newTasksToCreate.length !== expectedTasks) {
|
|
335
|
+
DR.logger.error(`Expected ${expectedTasks} tasks, but prepped ${newTasksToCreate.length}.`);
|
|
336
|
+
}
|
|
337
|
+
if (newConfigsToCreate.length !== expectedConfigs) {
|
|
338
|
+
DR.logger.error(`Expected ${expectedConfigs} configs, but prepped ${newConfigsToCreate.length}.`);
|
|
339
|
+
}
|
|
340
|
+
if (newNonogramItemsToCreate.length !== expectedNonogramItems) {
|
|
341
|
+
DR.logger.error(`Expected ${expectedNonogramItems} nonogram items, but prepped ${newNonogramItemsToCreate.length}.`);
|
|
342
|
+
}
|
|
343
|
+
if (newNonogramUpgradesToCreate.length !== expectedNonogramUpgrades) {
|
|
344
|
+
DR.logger.error(`Expected ${expectedNonogramUpgrades} nonogram upgrades, but prepped ${newNonogramUpgradesToCreate.length}.`);
|
|
345
|
+
}
|
|
346
|
+
DR.logger.info(`Prepped ${newUsersToCreate.length} new users.`);
|
|
347
|
+
DR.logger.info(`Prepped ${newApiKeysToCreate.length} new API keys.`);
|
|
348
|
+
DR.logger.info(`Prepped ${newTasksToCreate.length} new tasks.`);
|
|
349
|
+
DR.logger.info(`Prepped ${newConfigsToCreate.length} new configs.`);
|
|
350
|
+
DR.logger.info(`Prepped ${newNonogramItemsToCreate.length} new nonogram items.`);
|
|
351
|
+
DR.logger.info(`Prepped ${newNonogramUpgradesToCreate.length} new nonogram upgrades.`);
|
|
352
|
+
DR.logger.info(`In total, prepped ${newUsersToCreate.length +
|
|
353
|
+
newApiKeysToCreate.length +
|
|
354
|
+
newTasksToCreate.length +
|
|
355
|
+
newConfigsToCreate.length +
|
|
356
|
+
newNonogramItemsToCreate.length +
|
|
357
|
+
newNonogramUpgradesToCreate.length} documents for insertion.`);
|
|
358
|
+
if (!dryRun) {
|
|
359
|
+
DR.logger.info('Dry run is false. Inserting documents into DB...');
|
|
360
|
+
if (newUsersToCreate.length > 0) {
|
|
361
|
+
await (await userRepo.getCollection()).insertMany(newUsersToCreate);
|
|
313
362
|
}
|
|
314
|
-
if (
|
|
315
|
-
|
|
363
|
+
if (newApiKeysToCreate.length > 0) {
|
|
364
|
+
await (await apiKeyRepo.getCollection()).insertMany(newApiKeysToCreate);
|
|
316
365
|
}
|
|
317
|
-
if (
|
|
318
|
-
|
|
366
|
+
if (newTasksToCreate.length > 0) {
|
|
367
|
+
await (await taskRepo.getCollection()).insertMany(newTasksToCreate);
|
|
319
368
|
}
|
|
320
|
-
if (
|
|
321
|
-
|
|
369
|
+
if (newConfigsToCreate.length > 0) {
|
|
370
|
+
await (await configRepo.getCollection()).insertMany(newConfigsToCreate);
|
|
322
371
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
DR.logger.info(`Prepped ${newTasksToCreate.length} new tasks.`);
|
|
326
|
-
DR.logger.info(`Prepped ${newConfigsToCreate.length} new configs.`);
|
|
327
|
-
DR.logger.info(`Prepped ${newNonogramItemsToCreate.length} new nonogram items.`);
|
|
328
|
-
DR.logger.info(`Prepped ${newNonogramUpgradesToCreate.length} new nonogram upgrades.`);
|
|
329
|
-
DR.logger.info(`In total, prepped ${newUsersToCreate.length +
|
|
330
|
-
newApiKeysToCreate.length +
|
|
331
|
-
newTasksToCreate.length +
|
|
332
|
-
newConfigsToCreate.length +
|
|
333
|
-
newNonogramItemsToCreate.length +
|
|
334
|
-
newNonogramUpgradesToCreate.length} documents for insertion.`);
|
|
335
|
-
if (!dryRun) {
|
|
336
|
-
DR.logger.info('Dry run is false. Inserting documents into DB...');
|
|
337
|
-
if (newUsersToCreate.length > 0) {
|
|
338
|
-
await (await userRepo.getCollection()).insertMany(newUsersToCreate);
|
|
339
|
-
}
|
|
340
|
-
if (newApiKeysToCreate.length > 0) {
|
|
341
|
-
await (await apiKeyRepo.getCollection()).insertMany(newApiKeysToCreate);
|
|
342
|
-
}
|
|
343
|
-
if (newTasksToCreate.length > 0) {
|
|
344
|
-
await (await taskRepo.getCollection()).insertMany(newTasksToCreate);
|
|
345
|
-
}
|
|
346
|
-
if (newConfigsToCreate.length > 0) {
|
|
347
|
-
await (await configRepo.getCollection()).insertMany(newConfigsToCreate);
|
|
348
|
-
}
|
|
349
|
-
if (newNonogramItemsToCreate.length > 0) {
|
|
350
|
-
await (await nonogramItemRepo.getCollection()).insertMany(newNonogramItemsToCreate);
|
|
351
|
-
}
|
|
352
|
-
if (newNonogramUpgradesToCreate.length > 0) {
|
|
353
|
-
await (await nonogramUpgradesRepo.getCollection()).insertMany(newNonogramUpgradesToCreate);
|
|
354
|
-
}
|
|
355
|
-
DR.logger.info('Insertion complete.');
|
|
372
|
+
if (newNonogramItemsToCreate.length > 0) {
|
|
373
|
+
await (await nonogramItemRepo.getCollection()).insertMany(newNonogramItemsToCreate);
|
|
356
374
|
}
|
|
357
|
-
|
|
358
|
-
|
|
375
|
+
if (newNonogramUpgradesToCreate.length > 0) {
|
|
376
|
+
await (await nonogramUpgradesRepo.getCollection()).insertMany(newNonogramUpgradesToCreate);
|
|
359
377
|
}
|
|
360
|
-
|
|
378
|
+
DR.logger.info('Insertion complete.');
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
DR.logger.info('Dry run is true. Skipping DB insertion.');
|
|
361
382
|
}
|
|
383
|
+
return;
|
|
362
384
|
}
|
|
363
385
|
//# sourceMappingURL=MigrationService.js.map
|