Add config migration process

This commit is contained in:
ajnart
2022-12-22 11:29:51 +09:00
parent 5f8a420c83
commit ecc61d5970
11 changed files with 147 additions and 55 deletions

View File

@@ -1,9 +1,18 @@
import { BackendConfigType, ConfigType } from '../../types/config';
import { BackendConfigType } from '../../types/config';
import { configExists } from './configExists';
import { getFallbackConfig } from './getFallbackConfig';
import { migrateConfig } from './migrateConfig';
import { readConfig } from './readConfig';
export const getConfig = (name: string): BackendConfigType => {
if (!configExists(name)) return getFallbackConfig();
return readConfig(name);
// Else if config exists but contains no "schema_version" property
// then it is an old config file and we should try to migrate it
// to the new format.
let config = readConfig(name);
if (!config.schemaVersion) {
// TODO: Migrate config to new format
config = migrateConfig(config);
}
return config;
};