refactor(cli, ups-handler, daemon, migrations): remove thresholds handling and update migration order logic
This commit is contained in:
@@ -5,16 +5,14 @@
|
||||
* Migrations run in order based on the `order` field, allowing users to jump
|
||||
* multiple versions (e.g., v1 → v4 runs migrations 2, 3, and 4).
|
||||
*/
|
||||
/**
|
||||
* Abstract base class for configuration migrations
|
||||
*
|
||||
* Each migration represents an upgrade from one config version to another.
|
||||
* Migrations run in order based on the `toVersion` field, allowing users to jump
|
||||
* multiple versions (e.g., v1 → v4 runs migrations 2, 3, and 4).
|
||||
*/
|
||||
export abstract class BaseMigration {
|
||||
/**
|
||||
* Migration order number
|
||||
* - Order 2: v1 → v2
|
||||
* - Order 3: v2 → v3
|
||||
* - Order 4: v3 → v4
|
||||
* etc.
|
||||
*/
|
||||
abstract readonly order: number;
|
||||
|
||||
/**
|
||||
* Source version this migration upgrades from
|
||||
* e.g., "1.x", "3.x"
|
||||
@@ -23,7 +21,7 @@ export abstract class BaseMigration {
|
||||
|
||||
/**
|
||||
* Target version this migration upgrades to
|
||||
* e.g., "2.0", "4.0"
|
||||
* e.g., "2.0", "4.0", "4.1"
|
||||
*/
|
||||
abstract readonly toVersion: string;
|
||||
|
||||
@@ -51,4 +49,19 @@ export abstract class BaseMigration {
|
||||
getName(): string {
|
||||
return `Migration ${this.fromVersion} → ${this.toVersion}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse version string into a comparable number
|
||||
* Supports formats like "2.0", "4.1", etc.
|
||||
* Returns a number like 2.0, 4.1 for sorting
|
||||
*
|
||||
* @returns Parsed version number for ordering
|
||||
*/
|
||||
getVersionOrder(): number {
|
||||
const parsed = parseFloat(this.toVersion);
|
||||
if (isNaN(parsed)) {
|
||||
throw new Error(`Invalid version format: ${this.toVersion}`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
|
@@ -22,8 +22,8 @@ export class MigrationRunner {
|
||||
// Add future migrations here (v4.2, v4.3, etc.)
|
||||
];
|
||||
|
||||
// Sort by order to ensure they run in sequence
|
||||
this.migrations.sort((a, b) => a.order - b.order);
|
||||
// Sort by version order to ensure they run in sequence
|
||||
this.migrations.sort((a, b) => a.getVersionOrder() - b.getVersionOrder());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -20,7 +20,6 @@ import { logger } from '../logger.ts';
|
||||
* }
|
||||
*/
|
||||
export class MigrationV1ToV2 extends BaseMigration {
|
||||
readonly order = 2;
|
||||
readonly fromVersion = '1.x';
|
||||
readonly toVersion = '2.0';
|
||||
|
||||
|
@@ -39,7 +39,6 @@ import { logger } from '../logger.ts';
|
||||
* }
|
||||
*/
|
||||
export class MigrationV3ToV4 extends BaseMigration {
|
||||
readonly order = 4;
|
||||
readonly fromVersion = '3.x';
|
||||
readonly toVersion = '4.0';
|
||||
|
||||
|
@@ -46,7 +46,6 @@ import { logger } from '../logger.ts';
|
||||
* }
|
||||
*/
|
||||
export class MigrationV4_0ToV4_1 extends BaseMigration {
|
||||
readonly order = 5;
|
||||
readonly fromVersion = '4.0';
|
||||
readonly toVersion = '4.1';
|
||||
|
||||
|
Reference in New Issue
Block a user