From a1168483e6580d4f363ffc163f39e7b4bda1b9a8 Mon Sep 17 00:00:00 2001 From: Khinenw Date: Sun, 1 Dec 2024 22:07:15 +0900 Subject: [PATCH] fix: migration always fails on new config (#1305) --- common/constants.ts | 6 ++++++ src/config/index.ts | 5 ++--- src/config/migration/runner.ts | 5 ++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/common/constants.ts b/common/constants.ts index c226ab5f..fca8f8af 100644 --- a/common/constants.ts +++ b/common/constants.ts @@ -1,3 +1,6 @@ +import packageJson from '../package.json'; + +export const VERSION = packageJson.version; export const DEFAULT_STYLE = { font: 'Pretendard JP Variable', fontWeight: '400', @@ -105,6 +108,9 @@ export const DEFAULT_CONFIG = { config: {}, }, + __internal__: { + version: VERSION, + }, }; export const PRESET_PREFIX = '__preset__'; diff --git a/src/config/index.ts b/src/config/index.ts index 476eff69..e75021f0 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -9,10 +9,9 @@ import { createMigrator, migrateTable } from './migration'; import { State } from './state'; +import { VERSION } from '../../common/constants'; import { ConfigSchema, GameListSchema, LyricMapperSchema, ThemeListSchema } from '../../common/schema'; -import packageJson from '../../package.json'; - let resolver: () => void = () => null; const init = { config: 0, @@ -52,7 +51,7 @@ const tryMigration = () => { if (isLoaded) { const internalConfig = config.get()['__internal__']; const prevVersion = typeof internalConfig?.version === 'string' ? internalConfig.version : '0.0.0'; - const nowVersion = packageJson.version; + const nowVersion = VERSION; console.log('[Alspotron] prepare for migration', prevVersion, '->', nowVersion); const migrator = createMigrator(migrateTable, prevVersion); diff --git a/src/config/migration/runner.ts b/src/config/migration/runner.ts index 6c679e4f..54d5c909 100644 --- a/src/config/migration/runner.ts +++ b/src/config/migration/runner.ts @@ -19,7 +19,7 @@ export const createMigrator = (table: MigrateTable, prevVersion: string) => { const bMin = minVersion(b); if (!aMin || !bMin) return 0; - return lt(aMin, bMin) ? 1 : -1; + return lt(aMin, bMin) ? -1 : 1; }) .map(([matcher, migrator]) => { if (clean(matcher) !== null) { @@ -31,8 +31,7 @@ export const createMigrator = (table: MigrateTable, prevVersion: string) => { return migrator; } }) - .filter(Boolean) - .reverse(); + .filter(Boolean); return (initData: MigratorData) => { const result = { ...initData };