import { BaseMigration } from './base-migration.ts'; import { logger } from '../logger.ts'; /** * Migration from v1 (single SNMP config) to v2 (upsDevices array) * * Detects old format: * { * snmp: { ... }, * thresholds: { ... }, * checkInterval: 30000 * } * * Converts to: * { * version: "2.0", * upsDevices: [{ id: "default", name: "Default UPS", snmp: ..., thresholds: ... }], * groups: [], * checkInterval: 30000 * } */ export class MigrationV1ToV2 extends BaseMigration { readonly fromVersion = '1.x'; readonly toVersion = '2.0'; async shouldRun(config: any): Promise { // V1 format has snmp field directly at root, no upsDevices or upsList return !!config.snmp && !config.upsDevices && !config.upsList; } async migrate(config: any): Promise { logger.info(`${this.getName()}: Converting single SNMP config to multi-UPS format...`); const migrated = { version: this.toVersion, upsDevices: [ { id: 'default', name: 'Default UPS', snmp: config.snmp, thresholds: config.thresholds || { battery: 60, runtime: 20, }, groups: [], }, ], groups: [], checkInterval: config.checkInterval || 30000, }; logger.success(`${this.getName()}: Migration complete`); return migrated; } }