44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
|
|
import { BaseMigration } from './base-migration.ts';
|
||
|
|
import { logger } from '../logger.ts';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Migration from v4.1 to v4.2
|
||
|
|
*
|
||
|
|
* Changes:
|
||
|
|
* 1. Adds `protocol: 'snmp'` to all existing UPS devices (explicit default)
|
||
|
|
* 2. Bumps version from '4.1' to '4.2'
|
||
|
|
*/
|
||
|
|
export class MigrationV4_1ToV4_2 extends BaseMigration {
|
||
|
|
readonly fromVersion = '4.1';
|
||
|
|
readonly toVersion = '4.2';
|
||
|
|
|
||
|
|
shouldRun(config: Record<string, unknown>): boolean {
|
||
|
|
return config.version === '4.1';
|
||
|
|
}
|
||
|
|
|
||
|
|
migrate(config: Record<string, unknown>): Record<string, unknown> {
|
||
|
|
logger.info(`${this.getName()}: Adding protocol field to UPS devices...`);
|
||
|
|
|
||
|
|
const devices = (config.upsDevices as Array<Record<string, unknown>>) || [];
|
||
|
|
const migratedDevices = devices.map((device) => {
|
||
|
|
// Add protocol: 'snmp' if not already present
|
||
|
|
if (!device.protocol) {
|
||
|
|
device.protocol = 'snmp';
|
||
|
|
logger.dim(` → ${device.name}: Set protocol to 'snmp'`);
|
||
|
|
}
|
||
|
|
return device;
|
||
|
|
});
|
||
|
|
|
||
|
|
const result = {
|
||
|
|
...config,
|
||
|
|
version: this.toVersion,
|
||
|
|
upsDevices: migratedDevices,
|
||
|
|
};
|
||
|
|
|
||
|
|
logger.success(
|
||
|
|
`${this.getName()}: Migration complete (${migratedDevices.length} devices updated)`,
|
||
|
|
);
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|