Skip to content

Commit

Permalink
Merge pull request #161 from ator-dev/storage-migration-version-fix
Browse files Browse the repository at this point in the history
Fix schema version detection in migration
  • Loading branch information
ator-dev authored May 21, 2024
2 parents 481b12d + 255d680 commit 68f6537
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/include/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,8 @@ const storageMigrateArea = async (areaName: StorageAreaName, schemaVersion: numb
const storageInitializeArea = async (areaName: StorageAreaName) => {
const storageArea: chrome.storage.StorageArea = chrome.storage[areaName];
const version1Key = KEYS.reservedFor[areaName].schemaVersion1;
const keyValues = await storageArea.get([ "schemaVersion", version1Key ]);
const versionValue = keyValues.version ?? (keyValues[version1Key] ? 1 : undefined);
const storageSpecial = await storageArea.get([ "schemaVersion", KEYS.special.schemaVersion ]);
const versionValue = storageSpecial[KEYS.special.schemaVersion] ?? (storageSpecial[version1Key] ? 1 : undefined);
const schemaVersion = (typeof versionValue === "number") ? versionValue : 0;
if (schemaVersion === SCHEMA_VERSION) {
log("storage-initialize (single-area) complete with no changes", "schema version matches", { areaName, schemaVersion });
Expand All @@ -803,8 +803,9 @@ const storageInitializeArea = async (areaName: StorageAreaName) => {
await storageMigrateArea(areaName, schemaVersion);
} else {
const storage = await storageResetArea(areaName, "no appropriate migration found", true);
await storageCleanAreaOf(areaName, Object.keys(storage));
storageCleanAreaOf(areaName, Object.keys(storage));
}
log("storage-initialize (single-area) complete", "", { areaName });
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down

0 comments on commit 68f6537

Please sign in to comment.