pass logger to migrations, include version numbers in migration name
This commit is contained in:
parent
5680dd704e
commit
eefe9fe22e
|
@ -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) {
|
||||
|
|
|
@ -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<T extends BaseImgParams> = Omit<T, AddedKeysV11> & {
|
||||
overlap: number;
|
||||
|
@ -25,23 +22,37 @@ export type OnnxStateV7 = Omit<OnnxState, 'img2img' | 'txt2img'> & {
|
|||
txt2img: BaseImgParamsV7<Txt2ImgSlice['txt2img']>;
|
||||
upscale: BaseImgParamsV7<UpscaleSlice['upscale']>;
|
||||
};
|
||||
// #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,
|
||||
|
|
Loading…
Reference in New Issue