51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { BaseMigration } from './base-migration.ts';
|
|
import { logger } from '../logger.ts';
|
|
|
|
/**
|
|
* Migration from v4.3 to v4.4
|
|
*
|
|
* Changes:
|
|
* 1. Corrects APC runtimeUnit defaults from minutes to ticks
|
|
* 2. Bumps version from '4.3' to '4.4'
|
|
*/
|
|
export class MigrationV4_3ToV4_4 extends BaseMigration {
|
|
readonly fromVersion = '4.3';
|
|
readonly toVersion = '4.4';
|
|
|
|
shouldRun(config: Record<string, unknown>): boolean {
|
|
return config.version === '4.3';
|
|
}
|
|
|
|
migrate(config: Record<string, unknown>): Record<string, unknown> {
|
|
logger.info(`${this.getName()}: Correcting APC runtimeUnit defaults...`);
|
|
|
|
let correctedDevices = 0;
|
|
const devices = (config.upsDevices as Array<Record<string, unknown>>) || [];
|
|
const migratedDevices = devices.map((device) => {
|
|
const snmp = device.snmp as Record<string, unknown> | undefined;
|
|
if (!snmp || snmp.upsModel !== 'apc') {
|
|
return device;
|
|
}
|
|
|
|
if (!snmp.runtimeUnit || snmp.runtimeUnit === 'minutes') {
|
|
snmp.runtimeUnit = 'ticks';
|
|
correctedDevices += 1;
|
|
logger.dim(` → ${device.name}: Set runtimeUnit to 'ticks'`);
|
|
}
|
|
|
|
return device;
|
|
});
|
|
|
|
const result = {
|
|
...config,
|
|
version: this.toVersion,
|
|
upsDevices: migratedDevices,
|
|
};
|
|
|
|
logger.success(
|
|
`${this.getName()}: Migration complete (${correctedDevices} APC device(s) corrected)`,
|
|
);
|
|
return result;
|
|
}
|
|
}
|