fix(migrations): revert to correct migration v4.0-to-v4.1

The migration was correct as v4.0→v4.1. Config version goes from 4.0 to 4.1
when thresholds are moved to actions. The original error was not the migration
but the ups-handler.ts bug (already fixed in v4.2.1).

User's config shows version "4.1" with actions already present, confirming
the migration ran successfully.
This commit is contained in:
2025-10-20 12:17:03 +00:00
parent f2ce0180d3
commit 7bf65d8495
3 changed files with 17 additions and 18 deletions

View File

@@ -8,4 +8,4 @@ export { BaseMigration } from './base-migration.ts';
export { MigrationRunner } from './migration-runner.ts'; export { MigrationRunner } from './migration-runner.ts';
export { MigrationV1ToV2 } from './migration-v1-to-v2.ts'; export { MigrationV1ToV2 } from './migration-v1-to-v2.ts';
export { MigrationV3ToV4 } from './migration-v3-to-v4.ts'; export { MigrationV3ToV4 } from './migration-v3-to-v4.ts';
export { MigrationV4_1ToV4_2 } from './migration-v4.1-to-v4.2.ts'; export { MigrationV4_0ToV4_1 } from './migration-v4.0-to-v4.1.ts';

View File

@@ -1,7 +1,7 @@
import { BaseMigration } from './base-migration.ts'; import { BaseMigration } from './base-migration.ts';
import { MigrationV1ToV2 } from './migration-v1-to-v2.ts'; import { MigrationV1ToV2 } from './migration-v1-to-v2.ts';
import { MigrationV3ToV4 } from './migration-v3-to-v4.ts'; import { MigrationV3ToV4 } from './migration-v3-to-v4.ts';
import { MigrationV4_1ToV4_2 } from './migration-v4.1-to-v4.2.ts'; import { MigrationV4_0ToV4_1 } from './migration-v4.0-to-v4.1.ts';
import { logger } from '../logger.ts'; import { logger } from '../logger.ts';
/** /**
@@ -18,7 +18,7 @@ export class MigrationRunner {
this.migrations = [ this.migrations = [
new MigrationV1ToV2(), new MigrationV1ToV2(),
new MigrationV3ToV4(), new MigrationV3ToV4(),
new MigrationV4_1ToV4_2(), new MigrationV4_0ToV4_1(),
// Add future migrations here (v4.3, v4.4, etc.) // Add future migrations here (v4.3, v4.4, etc.)
]; ];

View File

@@ -2,7 +2,7 @@ import { BaseMigration } from './base-migration.ts';
import { logger } from '../logger.ts'; import { logger } from '../logger.ts';
/** /**
* Migration from v4.1 to v4.2 * Migration from v4.0 to v4.1
* *
* Major changes: * Major changes:
* 1. Moves thresholds from UPS level to action level * 1. Moves thresholds from UPS level to action level
@@ -10,24 +10,23 @@ import { logger } from '../logger.ts';
* 3. Adds empty actions array to UPS devices without actions * 3. Adds empty actions array to UPS devices without actions
* 4. Adds empty actions array to groups * 4. Adds empty actions array to groups
* *
* Transforms v4.1 format (with UPS-level thresholds): * Transforms v4.0 format (with UPS-level thresholds):
* { * {
* version: "4.1", * version: "4.0",
* upsDevices: [ * upsDevices: [
* { * {
* id: "ups-1", * id: "ups-1",
* name: "UPS 1", * name: "UPS 1",
* snmp: {...}, * snmp: {...},
* thresholds: { battery: 60, runtime: 20 }, // UPS-level * thresholds: { battery: 60, runtime: 20 }, // UPS-level
* groups: [], * groups: []
* actions: []
* } * }
* ] * ]
* } * }
* *
* To v4.2 format (with action-level thresholds): * To v4.1 format (with action-level thresholds):
* { * {
* version: "4.2", * version: "4.1",
* upsDevices: [ * upsDevices: [
* { * {
* id: "ups-1", * id: "ups-1",
@@ -46,20 +45,20 @@ import { logger } from '../logger.ts';
* ] * ]
* } * }
*/ */
export class MigrationV4_1ToV4_2 extends BaseMigration { export class MigrationV4_0ToV4_1 extends BaseMigration {
readonly fromVersion = '4.1'; readonly fromVersion = '4.0';
readonly toVersion = '4.2'; readonly toVersion = '4.1';
async shouldRun(config: any): Promise<boolean> { async shouldRun(config: any): Promise<boolean> {
// Run if config is version 4.1 // Run if config is version 4.0
if (config.version === '4.1') { if (config.version === '4.0') {
return true; return true;
} }
// Also run if config has upsDevices with thresholds at UPS level (v4.1 format) // Also run if config has upsDevices with thresholds at UPS level (v4.0 format)
if (config.upsDevices && config.upsDevices.length > 0) { if (config.upsDevices && config.upsDevices.length > 0) {
const firstDevice = config.upsDevices[0]; const firstDevice = config.upsDevices[0];
// v4.1 has thresholds at UPS level, v4.2 has them in actions // v4.0 has thresholds at UPS level, v4.1 has them in actions
return firstDevice.thresholds !== undefined; return firstDevice.thresholds !== undefined;
} }
@@ -67,7 +66,7 @@ export class MigrationV4_1ToV4_2 extends BaseMigration {
} }
async migrate(config: any): Promise<any> { async migrate(config: any): Promise<any> {
logger.info(`${this.getName()}: Migrating v4.1 config to v4.2 format...`); logger.info(`${this.getName()}: Migrating v4.0 config to v4.1 format...`);
logger.dim(` - Moving thresholds from UPS level to action level`); logger.dim(` - Moving thresholds from UPS level to action level`);
logger.dim(` - Creating default shutdown actions from existing thresholds`); logger.dim(` - Creating default shutdown actions from existing thresholds`);