mrjvs c4c7816543 migrations but better
Co-authored-by: William Oldham <github@binaryoverload.co.uk>
2023-06-22 22:37:16 +02:00

38 lines
820 B
TypeScript

import { createVersionedStore } from "@/utils/storage";
import { OldData, migrateV2Videos } from "./migrations/v2";
import { migrateV3Videos } from "./migrations/v3";
import { WatchedStoreData } from "./types";
export const VideoProgressStore = createVersionedStore<WatchedStoreData>()
.setKey("video-progress")
.addVersion({
version: 0,
migrate() {
return {
items: [], // dont migrate from version 0 to version 1, unmigratable
};
},
})
.addVersion({
version: 1,
async migrate(old: OldData) {
return migrateV2Videos(old);
},
})
.addVersion({
version: 2,
migrate(old: WatchedStoreData) {
return migrateV3Videos(old);
},
})
.addVersion({
version: 3,
create() {
return {
items: [],
};
},
})
.build();