Only users with issuer = true, Change order of migration Tag tasks
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -90,9 +90,9 @@ export default class MigrationHandler {
currentMigrationTasks.push(new RecomputeAllTransactionsConsumptionsTask());
currentMigrationTasks.push(new AddUserInTransactionsTask());
currentMigrationTasks.push(new DeleteTagsForDeletedUsersTask());
+ currentMigrationTasks.push(new AlignTagsWithUsersIssuerTask());
currentMigrationTasks.push(new AddCreatedPropertiesToBadgeTask());
currentMigrationTasks.push(new AddDescriptionToTagsTask());
- currentMigrationTasks.push(new AlignTagsWithUsersIssuerTask());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();
// Check

MODIFY
src/migration/tasks/AddCreatedPropertiesToBadgeTask.ts
src/migration/tasks/AddCreatedPropertiesToBadgeTask.ts
@@ -19,17 +19,22 @@ export default class AddCreatedPropertiesToBadgeTask extends MigrationTask {
}
async migrateTenant(tenant: Tenant): Promise<void> {
- const users = await UserStorage.getUsers(tenant.id, {}, Constants.DB_PARAMS_MAX_LIMIT);
+ const users = await UserStorage.getUsers(tenant.id, {
+ issuer: true
+ }, Constants.DB_PARAMS_MAX_LIMIT);
const tagCollection = global.database.getCollection<any>(tenant.id, 'tags');
let counter = 0;
for (const user of users.result) {
- const tags = await tagCollection.find({ userID: Utils.convertToObjectID(user.id), createdOn: null }).toArray();
- if (!Utils.isEmptyArray(tags) && user.createdOn) {
+ if (user.createdOn) {
+ // Get the User's Tags with no Created On date
+ const tags = await tagCollection.find({
+ userID: Utils.convertToObjectID(user.id),
+ createdOn: null
+ }).toArray();
+ if (!Utils.isEmptyArray(tags)) {
for (const tag of tags) {
await tagCollection.updateOne(
- {
- _id: tag._id
- },
+ { _id: tag._id },
{
$set: {
createdOn: user.createdOn,
@@ -42,13 +47,14 @@ export default class AddCreatedPropertiesToBadgeTask extends MigrationTask {
}
}
}
+ }
// Log in the default tenant
if (counter > 0) {
Logging.logDebug({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.MIGRATION,
module: MODULE_NAME, method: 'migrateTenant',
- message: `${counter} Tags(s) have been updated in Tenant '${tenant.name}'`
+ message: `${counter} Tags's created properties have been updated in Tenant '${tenant.name}'`
});
}
}

MODIFY
src/migration/tasks/AddDescriptionToTagsTask.ts
src/migration/tasks/AddDescriptionToTagsTask.ts
@@ -20,15 +20,18 @@ export default class AddDescriptionToTagsTask extends MigrationTask {
async migrateTenant(tenant: Tenant): Promise<void> {
// Add the active property to tags
let updated = 0;
- // Get users
+ // Get Tags with no Description
const tagsMDB = await global.database.getCollection<any>(tenant.id, 'tags')
- .find({ description: null }).toArray();
+ .find({
+ description: null,
+ issuer: true,
+ }).toArray();
if (!Utils.isEmptyArray(tagsMDB)) {
for (const tagMDB of tagsMDB) {
await global.database.getCollection<any>(tenant.id, 'tags').findOneAndUpdate(
{ _id: tagMDB._id },
{ $set: { description: `Tag ID '${tagMDB._id}'` } });
- updated++
+ updated++;
}
}
// Log in the default tenant
@@ -37,7 +40,7 @@ export default class AddDescriptionToTagsTask extends MigrationTask {
tenantID: Constants.DEFAULT_TENANT,
module: MODULE_NAME, method: 'migrateTenant',
action: ServerAction.MIGRATION,
- message: `${updated} Tag(s) have been updated in Tenant '${tenant.name}'`
+ message: `${updated} Tag(s) description have been updated in Tenant '${tenant.name}'`
});
}
}

MODIFY
src/migration/tasks/AddLastChangePropertiesToBadgeTask.ts
src/migration/tasks/AddLastChangePropertiesToBadgeTask.ts
@@ -19,7 +19,9 @@ export default class AddLastChangePropertiesToBadgeTask extends MigrationTask {
}
async migrateTenant(tenant: Tenant): Promise<void> {
- const users = await UserStorage.getUsers(tenant.id, {}, Constants.DB_PARAMS_MAX_LIMIT);
+ const users = await UserStorage.getUsers(tenant.id, {
+ issuer: true,
+ }, Constants.DB_PARAMS_MAX_LIMIT);
const tagCollection = global.database.getCollection<any>(tenant.id, 'tags');
let counter = 0;
for (const user of users.result) {
@@ -50,7 +52,7 @@ export default class AddLastChangePropertiesToBadgeTask extends MigrationTask {
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.MIGRATION,
module: MODULE_NAME, method: 'migrateTenant',
- message: `${counter} Tags(s) have been updated in Tenant '${tenant.name}'`
+ message: `${counter} Tags's last changed properties have been updated in Tenant '${tenant.name}'`
});
}
}

Only users with issuer = true, Change order of migration Tag tasks