Migration Amps to all phases
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -25,6 +25,7 @@ import RenameTagPropertiesTask from './tasks/RenameTagPropertiesTask';
import { ServerAction } from '../types/Server';
import SiteUsersHashIDsTask from './tasks/SiteUsersHashIDsTask';
import UpdateChargingStationTemplatesTask from './tasks/UpdateChargingStationTemplatesTask';
+import UpdateConsumptionsAmpsToAllPhases from './tasks/UpdateConsumptionAmpsToAllPhasesTask';
import UpdateConsumptionsToObjectIDs from './tasks/UpdateConsumptionsToObjectIDs';
import cluster from 'cluster';
import moment from 'moment';
@@ -73,6 +74,7 @@ export default class MigrationHandler {
currentMigrationTasks.push(new AddSiteAreaLimitToConsumptionsTask());
currentMigrationTasks.push(new AddInstantAmpsToConsumptionsTask());
currentMigrationTasks.push(new MigrateOcpiTransactionsTask());
+ currentMigrationTasks.push(new UpdateConsumptionsAmpsToAllPhases());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();
// Check

ADD
src/migration/tasks/UpdateConsumptionAmpsToAllPhasesTask.ts
+import Constants from '../../utils/Constants';
+import Logging from '../../utils/Logging';
+import MigrationTask from '../MigrationTask';
+import { ServerAction } from '../../types/Server';
+import Tenant from '../../types/Tenant';
+import TenantStorage from '../../storage/mongodb/TenantStorage';
+import global from '../../types/GlobalType';
+
+const MODULE_NAME = 'UpdateConsumptionsAmpsToAllPhases';
+
+export default class UpdateConsumptionsAmpsToAllPhases extends MigrationTask {
+ async migrate() {
+ const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
+ for (const tenant of tenants.result) {
+ await this.migrateTenant(tenant);
+ }
+ }
+
+ async migrateTenant(tenant: Tenant) {
+ let modifiedCount = 0;
+ const result = await global.database.getCollection(tenant.id, 'consumptions').updateMany(
+ {
+ limitWatts: { $exists: true },
+ limitAmps: { $ne: { $round: [{ $divide: ['$limitWatts', 230] }] } },
+ },
+ [
+ { '$set': { 'limitAmps': { '$round': [{ '$divide': ['$limitWatts', 230] }] } } }
+ ]
+ );
+ modifiedCount += result.modifiedCount;
+ // Log in the default tenant
+ if (modifiedCount > 0) {
+ Logging.logDebug({
+ tenantID: Constants.DEFAULT_TENANT,
+ action: ServerAction.MIGRATION,
+ module: MODULE_NAME, method: 'migrateTenant',
+ message: `${modifiedCount} Consumptions have been updated in Tenant '${tenant.name}'`
+ });
+ }
+ }
+
+ getVersion() {
+ return '1.2';
+ }
+
+ getName() {
+ return 'UpdateConsumptionsAmpsToAllPhases';
+ }
+
+ isAsynchronous() {
+ return true;
+ }
+}

Migration Amps to all phases