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),
|
...createProfileSlice(...slice),
|
||||||
}), {
|
}), {
|
||||||
migrate(persistedState, version) {
|
migrate(persistedState, version) {
|
||||||
return applyStateMigrations(params, persistedState as UnknownState, version);
|
return applyStateMigrations(params, persistedState as UnknownState, version, logger);
|
||||||
},
|
},
|
||||||
name: STATE_KEY,
|
name: STATE_KEY,
|
||||||
partialize(s) {
|
partialize(s) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
|
import { Logger } from 'browser-bunyan';
|
||||||
import { ServerParams } from '../../config.js';
|
import { ServerParams } from '../../config.js';
|
||||||
import { BaseImgParams } from '../../types/params.js';
|
import { BaseImgParams } from '../../types/params.js';
|
||||||
import { OnnxState, STATE_VERSION } from '../full.js';
|
import { OnnxState, STATE_VERSION } from '../full.js';
|
||||||
|
@ -7,12 +8,8 @@ import { InpaintSlice } from '../inpaint.js';
|
||||||
import { Txt2ImgSlice } from '../txt2img.js';
|
import { Txt2ImgSlice } from '../txt2img.js';
|
||||||
import { UpscaleSlice } from '../upscale.js';
|
import { UpscaleSlice } from '../upscale.js';
|
||||||
|
|
||||||
export const REMOVE_KEYS = ['tile', 'overlap'] as const;
|
// #region V7
|
||||||
|
export const V7 = 7;
|
||||||
export type RemovedKeys = typeof REMOVE_KEYS[number];
|
|
||||||
|
|
||||||
// TODO: can the compiler calculate this?
|
|
||||||
export type AddedKeysV11 = 'unet_tile' | 'unet_overlap' | 'vae_tile' | 'vae_overlap';
|
|
||||||
|
|
||||||
export type BaseImgParamsV7<T extends BaseImgParams> = Omit<T, AddedKeysV11> & {
|
export type BaseImgParamsV7<T extends BaseImgParams> = Omit<T, AddedKeysV11> & {
|
||||||
overlap: number;
|
overlap: number;
|
||||||
|
@ -25,23 +22,37 @@ export type OnnxStateV7 = Omit<OnnxState, 'img2img' | 'txt2img'> & {
|
||||||
txt2img: BaseImgParamsV7<Txt2ImgSlice['txt2img']>;
|
txt2img: BaseImgParamsV7<Txt2ImgSlice['txt2img']>;
|
||||||
upscale: BaseImgParamsV7<UpscaleSlice['upscale']>;
|
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;
|
export type PreviousState = OnnxStateV7;
|
||||||
|
|
||||||
|
// always the latest version
|
||||||
export type CurrentState = OnnxState;
|
export type CurrentState = OnnxState;
|
||||||
|
|
||||||
|
// any version of state
|
||||||
export type UnknownState = PreviousState | CurrentState;
|
export type UnknownState = PreviousState | CurrentState;
|
||||||
|
|
||||||
export function applyStateMigrations(params: ServerParams, previousState: UnknownState, version: number): OnnxState {
|
export function applyStateMigrations(params: ServerParams, previousState: UnknownState, version: number, logger: Logger): OnnxState {
|
||||||
// eslint-disable-next-line no-console
|
logger.info('applying state migrations from version %s to version %s', version, STATE_VERSION);
|
||||||
console.log('applying migrations from %s to %s', version, STATE_VERSION);
|
|
||||||
|
|
||||||
if (version < STATE_VERSION) {
|
if (version <= V7) {
|
||||||
return migrateDefaults(params, previousState as PreviousState);
|
return migrateV7ToV11(params, previousState as PreviousState);
|
||||||
}
|
}
|
||||||
|
|
||||||
return previousState as CurrentState;
|
return previousState as CurrentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function migrateDefaults(params: ServerParams, previousState: PreviousState): CurrentState {
|
export function migrateV7ToV11(params: ServerParams, previousState: PreviousState): CurrentState {
|
||||||
// add any missing keys
|
// add any missing keys
|
||||||
const result: CurrentState = {
|
const result: CurrentState = {
|
||||||
...params,
|
...params,
|
||||||
|
|
Loading…
Reference in New Issue