diff --git a/gui/src/main.tsx b/gui/src/main.tsx index edfc2150..81aeecf0 100644 --- a/gui/src/main.tsx +++ b/gui/src/main.tsx @@ -72,7 +72,7 @@ export async function renderApp(config: Config, params: ServerParams, logger: Lo ...createProfileSlice(...slice), }), { migrate(persistedState, version) { - return applyStateMigrations(params, persistedState as UnknownState, version); + return applyStateMigrations(params, persistedState as UnknownState, version, logger); }, name: STATE_KEY, partialize(s) { diff --git a/gui/src/state/migration/default.ts b/gui/src/state/migration/default.ts index 425a18fb..65a4353b 100644 --- a/gui/src/state/migration/default.ts +++ b/gui/src/state/migration/default.ts @@ -1,4 +1,5 @@ /* eslint-disable camelcase */ +import { Logger } from 'browser-bunyan'; import { ServerParams } from '../../config.js'; import { BaseImgParams } from '../../types/params.js'; import { OnnxState, STATE_VERSION } from '../full.js'; @@ -7,12 +8,8 @@ import { InpaintSlice } from '../inpaint.js'; import { Txt2ImgSlice } from '../txt2img.js'; import { UpscaleSlice } from '../upscale.js'; -export const REMOVE_KEYS = ['tile', 'overlap'] as const; - -export type RemovedKeys = typeof REMOVE_KEYS[number]; - -// TODO: can the compiler calculate this? -export type AddedKeysV11 = 'unet_tile' | 'unet_overlap' | 'vae_tile' | 'vae_overlap'; +// #region V7 +export const V7 = 7; export type BaseImgParamsV7 = Omit & { overlap: number; @@ -25,23 +22,37 @@ export type OnnxStateV7 = Omit & { txt2img: BaseImgParamsV7; upscale: BaseImgParamsV7; }; +// #endregion +// #region V11 +export const REMOVED_KEYS_V11 = ['tile', 'overlap'] as const; + +export type RemovedKeysV11 = typeof REMOVED_KEYS_V11[number]; + +// TODO: can the compiler calculate this? +export type AddedKeysV11 = 'unet_tile' | 'unet_overlap' | 'vae_tile' | 'vae_overlap'; +// #endregion + +// add versions to this list as they are replaced export type PreviousState = OnnxStateV7; + +// always the latest version export type CurrentState = OnnxState; + +// any version of state export type UnknownState = PreviousState | CurrentState; -export function applyStateMigrations(params: ServerParams, previousState: UnknownState, version: number): OnnxState { - // eslint-disable-next-line no-console - console.log('applying migrations from %s to %s', version, STATE_VERSION); +export function applyStateMigrations(params: ServerParams, previousState: UnknownState, version: number, logger: Logger): OnnxState { + logger.info('applying state migrations from version %s to version %s', version, STATE_VERSION); - if (version < STATE_VERSION) { - return migrateDefaults(params, previousState as PreviousState); + if (version <= V7) { + return migrateV7ToV11(params, previousState as PreviousState); } return previousState as CurrentState; } -export function migrateDefaults(params: ServerParams, previousState: PreviousState): CurrentState { +export function migrateV7ToV11(params: ServerParams, previousState: PreviousState): CurrentState { // add any missing keys const result: CurrentState = { ...params,