Skip to content

Commit

Permalink
fix: migration always fails on new config (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloWorld017 authored Dec 1, 2024
1 parent 24309c3 commit a116848
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import packageJson from '../package.json';

export const VERSION = packageJson.version;
export const DEFAULT_STYLE = {
font: 'Pretendard JP Variable',
fontWeight: '400',
Expand Down Expand Up @@ -105,6 +108,9 @@ export const DEFAULT_CONFIG = {
config: {},
},

__internal__: {
version: VERSION,
},
};

export const PRESET_PREFIX = '__preset__';
5 changes: 2 additions & 3 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/config/migration/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -31,8 +31,7 @@ export const createMigrator = (table: MigrateTable, prevVersion: string) => {
return migrator;
}
})
.filter(Boolean)
.reverse();
.filter(Boolean);

return (initData: MigratorData) => {
const result = { ...initData };
Expand Down

0 comments on commit a116848

Please sign in to comment.