Use TenantMigrationTask super class for tenant related migration's tasks
MODIFY
src/migration/tasks/AddCompanyIDToChargingStationsTask.ts
src/migration/tasks/AddCompanyIDToChargingStationsTask.ts
import Constants from '../../utils/Constants';
import DatabaseUtils from '../../storage/mongodb/DatabaseUtils';
import Logging from '../../utils/Logging';
-import MigrationTask from '../MigrationTask';
import { ServerAction } from '../../types/Server';
import SiteStorage from '../../storage/mongodb/SiteStorage';
import Tenant from '../../types/Tenant';
-import TenantStorage from '../../storage/mongodb/TenantStorage';
+import TenantMigrationTask from '../TenantMigrationTask';
import Utils from '../../utils/Utils';
import global from '../../types/GlobalType';
const MODULE_NAME = 'AddCompanyIDPropertToChargingStationsTask';
-export default class AddCompanyIDToChargingStationsTask extends MigrationTask {
- async migrate(): Promise<void> {
- const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
- for (const tenant of tenants.result) {
- await this.migrateTenant(tenant);
- }
- }
-
- async migrateTenant(tenant: Tenant): Promise<void> {
+export default class AddCompanyIDToChargingStationsTask extends TenantMigrationTask {
+ public async migrateTenant(tenant: Tenant): Promise<void> {
let updated = 0;
// Get all the Sites
const sites = (await SiteStorage.getSites(tenant, {}, Constants.DB_PARAMS_MAX_LIMIT, ['id', 'companyID'])).result;
@@ -66,15 +58,15 @@ export default class AddCompanyIDToChargingStationsTask extends MigrationTask {
}
}
- getVersion(): string {
+ public getVersion(): string {
return '1.0';
}
- getName(): string {
+ public getName(): string {
return 'AddCompanyIDToChargingStationsTask';
}
- isAsynchronous(): boolean {
+ public isAsynchronous(): boolean {
return true;
}
}

MODIFY
src/migration/tasks/AddCompanyIDToTransactionsTask.ts
src/migration/tasks/AddCompanyIDToTransactionsTask.ts
import Constants from '../../utils/Constants';
import DatabaseUtils from '../../storage/mongodb/DatabaseUtils';
import Logging from '../../utils/Logging';
-import MigrationTask from '../MigrationTask';
import { ServerAction } from '../../types/Server';
import SiteStorage from '../../storage/mongodb/SiteStorage';
import Tenant from '../../types/Tenant';
-import TenantStorage from '../../storage/mongodb/TenantStorage';
+import TenantMigrationTask from '../TenantMigrationTask';
import Utils from '../../utils/Utils';
import global from '../../types/GlobalType';
const MODULE_NAME = 'AddCompanyIDPropertToChargingStationsTask';
-export default class AddCompanyIDToTransactionsTask extends MigrationTask {
- async migrate(): Promise<void> {
- const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
- for (const tenant of tenants.result) {
- await this.migrateTenant(tenant);
- }
- }
-
- async migrateTenant(tenant: Tenant): Promise<void> {
+export default class AddCompanyIDToTransactionsTask extends TenantMigrationTask {
+ public async migrateTenant(tenant: Tenant): Promise<void> {
let updated = 0;
// Get all the Sites
const sites = (await SiteStorage.getSites(tenant, {}, Constants.DB_PARAMS_MAX_LIMIT, ['id', 'companyID'])).result;
@@ -66,15 +58,15 @@ export default class AddCompanyIDToTransactionsTask extends MigrationTask {
}
}
- getVersion(): string {
+ public getVersion(): string {
return '1.0';
}
- getName(): string {
+ public getName(): string {
return 'AddCompanyIDToTransactionsTask';
}
- isAsynchronous(): boolean {
+ public isAsynchronous(): boolean {
return true;
}
}

MODIFY
src/migration/tasks/AddUserIDToCarsTask.ts
src/migration/tasks/AddUserIDToCarsTask.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 TenantMigrationTask from '../TenantMigrationTask';
import Utils from '../../utils/Utils';
import global from '../../types/GlobalType';
const MODULE_NAME = 'AddCompanyIDPropertToChargingStationsTask';
-export default class AddUserIDToCarsTask extends MigrationTask {
- async migrate(): Promise<void> {
- const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
- for (const tenant of tenants.result) {
- await this.migrateTenant(tenant);
- }
- }
-
- async migrateTenant(tenant: Tenant): Promise<void> {
+export default class AddUserIDToCarsTask extends TenantMigrationTask {
+ public async migrateTenant(tenant: Tenant): Promise<void> {
let updated = 0;
// Get all the Car Users
const carUsers = await global.database.getCollection<any>(tenant.id, 'carusers').find({})
@@ -52,15 +44,15 @@ export default class AddUserIDToCarsTask extends MigrationTask {
}
}
- getVersion(): string {
+ public getVersion(): string {
return '1.0';
}
- getName(): string {
+ public getName(): string {
return 'AddUserIDToCarsTask';
}
- isAsynchronous(): boolean {
+ public isAsynchronous(): boolean {
return true;
}
}

MODIFY
src/migration/tasks/MigrateSimplePricing.ts
src/migration/tasks/MigrateSimplePricing.ts
@@ -4,24 +4,16 @@ import Tenant, { TenantComponents } from '../../types/Tenant';
import Constants from '../../utils/Constants';
import Logging from '../../utils/Logging';
-import MigrationTask from '../MigrationTask';
import PricingStorage from '../../storage/mongodb/PricingStorage';
import { ServerAction } from '../../types/Server';
import SettingStorage from '../../storage/mongodb/SettingStorage';
-import TenantStorage from '../../storage/mongodb/TenantStorage';
+import TenantMigrationTask from '../TenantMigrationTask';
import Utils from '../../utils/Utils';
const MODULE_NAME = 'MigrateSimplePricing';
-export default class SimplePricingMigrationTask extends MigrationTask {
- async migrate(): Promise<void> {
- const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
- for (const tenant of tenants.result) {
- await this.migrateTenant(tenant);
- }
- }
-
- async migrateTenant(tenant: Tenant): Promise<void> {
+export default class SimplePricingMigrationTask extends TenantMigrationTask {
+ public async migrateTenant(tenant: Tenant): Promise<void> {
const pricingSetting = await SettingStorage.getSettingByIdentifier(tenant, TenantComponents.PRICING);
if (pricingSetting?.content?.type === PricingSettingsType.SIMPLE) {
await this.createDefaultPricingDefinition(tenant, pricingSetting.content.simple);
@@ -34,20 +26,19 @@ export default class SimplePricingMigrationTask extends MigrationTask {
}
}
- getVersion(): string {
+ public getVersion(): string {
return '1.0';
}
- getName(): string {
+ public getName(): string {
return 'SimplePricingMigrationTask';
}
- isAsynchronous(): boolean {
+ public isAsynchronous(): boolean {
return true;
}
private async createDefaultPricingDefinition(tenant: Tenant, pricingSettings: SimplePricingSetting) {
-
const pricingDefinition: PricingDefinition = {
entityType: PricingEntity.TENANT,
entityID: tenant.id,

MODIFY
src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts
src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts
import Constants from '../../utils/Constants';
import DatabaseUtils from '../../storage/mongodb/DatabaseUtils';
import Logging from '../../utils/Logging';
-import MigrationTask from '../MigrationTask';
import { ObjectId } from 'mongodb';
import { ServerAction } from '../../types/Server';
import TagStorage from '../../storage/mongodb/TagStorage';
import Tenant from '../../types/Tenant';
-import TenantStorage from '../../storage/mongodb/TenantStorage';
+import TenantMigrationTask from '../TenantMigrationTask';
import Utils from '../../utils/Utils';
import global from '../../types/GlobalType';
const MODULE_NAME = 'AddVisualIDPropertyToTagsTask';
-export default class RemoveDuplicateTagVisualIDsTask extends MigrationTask {
- async migrate(): Promise<void> {
- const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
- for (const tenant of tenants.result) {
- await this.migrateTenant(tenant);
- }
- }
-
- async migrateTenant(tenant: Tenant): Promise<void> {
+export default class RemoveDuplicateTagVisualIDsTask extends TenantMigrationTask {
+ public async migrateTenant(tenant: Tenant): Promise<void> {
let updated = 0;
// Get the dup Tags with same Visual IDs
const tags = await global.database.getCollection<any>(tenant.id, 'tags')
@@ -66,15 +58,15 @@ export default class RemoveDuplicateTagVisualIDsTask extends MigrationTask {
}
}
- getVersion(): string {
+ public getVersion(): string {
return '1.0';
}
- getName(): string {
+ public getName(): string {
return 'RemoveDuplicateTagVisualIDsTask';
}
- isAsynchronous(): boolean {
+ public isAsynchronous(): boolean {
return true;
}
}

MODIFY
src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts
src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts
import Constants from '../../utils/Constants';
import Logging from '../../utils/Logging';
-import MigrationTask from '../MigrationTask';
import { ServerAction } from '../../types/Server';
import SiteStorage from '../../storage/mongodb/SiteStorage';
import Tenant from '../../types/Tenant';
-import TenantStorage from '../../storage/mongodb/TenantStorage';
+import TenantMigrationTask from '../TenantMigrationTask';
import UserStorage from '../../storage/mongodb/UserStorage';
import Utils from '../../utils/Utils';
import global from '../../types/GlobalType';
const MODULE_NAME = 'AddCompanyIDPropertToChargingStationsTask';
-export default class RestoreDataIntegrityInSiteUsersTask extends MigrationTask {
- async migrate(): Promise<void> {
- const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
- for (const tenant of tenants.result) {
- await this.migrateTenant(tenant);
- }
- }
-
- async migrateTenant(tenant: Tenant): Promise<void> {
+export default class RestoreDataIntegrityInSiteUsersTask extends TenantMigrationTask {
+ public async migrateTenant(tenant: Tenant): Promise<void> {
let deleted = 0;
// Get all the Site Users
const siteUsers = await global.database.getCollection<any>(tenant.id, 'siteusers')
@@ -64,15 +56,15 @@ export default class RestoreDataIntegrityInSiteUsersTask extends MigrationTask {
}
}
- getVersion(): string {
+ public getVersion(): string {
return '1.0';
}
- getName(): string {
+ public getName(): string {
return 'RestoreDataIntegrityInSiteUsersTask';
}
- isAsynchronous(): boolean {
+ public isAsynchronous(): boolean {
return true;
}
}

Use TenantMigrationTask super class for tenant related migration's tasks