|
@@ -1,6 +1,7 @@
|
|
import { haveWindow } from "@/next/env";
|
|
import { haveWindow } from "@/next/env";
|
|
import log from "@/next/log";
|
|
import log from "@/next/log";
|
|
import {
|
|
import {
|
|
|
|
+ DEFAULT_ML_SEARCH_CONFIG,
|
|
DEFAULT_ML_SYNC_CONFIG,
|
|
DEFAULT_ML_SYNC_CONFIG,
|
|
DEFAULT_ML_SYNC_JOB_CONFIG,
|
|
DEFAULT_ML_SYNC_JOB_CONFIG,
|
|
MAX_ML_SYNC_ERROR_COUNT,
|
|
MAX_ML_SYNC_ERROR_COUNT,
|
|
@@ -84,16 +85,21 @@ class MLIDbStorage {
|
|
async upgrade(db, oldVersion, newVersion, tx) {
|
|
async upgrade(db, oldVersion, newVersion, tx) {
|
|
let wasMLSearchEnabled = false;
|
|
let wasMLSearchEnabled = false;
|
|
try {
|
|
try {
|
|
- const searchConfig: unknown = await tx
|
|
|
|
|
|
+ const s: unknown = await tx
|
|
.objectStore("configs")
|
|
.objectStore("configs")
|
|
- .get(ML_SEARCH_CONFIG_NAME);
|
|
|
|
- if (
|
|
|
|
- searchConfig &&
|
|
|
|
- typeof searchConfig == "object" &&
|
|
|
|
- "enabled" in searchConfig &&
|
|
|
|
- typeof searchConfig.enabled == "boolean"
|
|
|
|
- ) {
|
|
|
|
- wasMLSearchEnabled = searchConfig.enabled;
|
|
|
|
|
|
+ .getKey(ML_SEARCH_CONFIG_NAME);
|
|
|
|
+ if (typeof s == "string") {
|
|
|
|
+ const json = JSON.parse(s);
|
|
|
|
+ if (
|
|
|
|
+ json &&
|
|
|
|
+ typeof json == "object" &&
|
|
|
|
+ "enabled" in json
|
|
|
|
+ ) {
|
|
|
|
+ const enabled = json.enabled;
|
|
|
|
+ if (typeof enabled == "boolean") {
|
|
|
|
+ wasMLSearchEnabled = enabled;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} catch (e) {
|
|
} catch (e) {
|
|
log.error(
|
|
log.error(
|
|
@@ -102,22 +108,10 @@ class MLIDbStorage {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
log.info(
|
|
log.info(
|
|
- `Previous ML database v${oldVersion} had ML search ${wasMLSearchEnabled ? "enabled" : "disabled"}`,
|
|
|
|
|
|
+ `Old database had wasMLSearchEnabled = ${wasMLSearchEnabled}`,
|
|
);
|
|
);
|
|
|
|
|
|
- // If the user is migrating from a pre-v4 version, delete
|
|
|
|
- // everything and recreate. The only thing that we migrate in
|
|
|
|
- // such cases is whether or not the ML search was enabled.
|
|
|
|
- if (oldVersion < 4) {
|
|
|
|
- // Delete everything in the IndexedDB
|
|
|
|
- db.deleteObjectStore("files");
|
|
|
|
- db.deleteObjectStore("people");
|
|
|
|
- db.deleteObjectStore("things");
|
|
|
|
- db.deleteObjectStore("versions");
|
|
|
|
- db.deleteObjectStore("library");
|
|
|
|
- db.deleteObjectStore("configs");
|
|
|
|
-
|
|
|
|
- // Recreate
|
|
|
|
|
|
+ if (oldVersion < 1) {
|
|
const filesStore = db.createObjectStore("files", {
|
|
const filesStore = db.createObjectStore("files", {
|
|
keyPath: "fileId",
|
|
keyPath: "fileId",
|
|
});
|
|
});
|
|
@@ -130,14 +124,16 @@ class MLIDbStorage {
|
|
keyPath: "id",
|
|
keyPath: "id",
|
|
});
|
|
});
|
|
|
|
|
|
- // db.createObjectStore("things", {
|
|
|
|
- // keyPath: "id",
|
|
|
|
- // });
|
|
|
|
|
|
+ db.createObjectStore("things", {
|
|
|
|
+ keyPath: "id",
|
|
|
|
+ });
|
|
|
|
|
|
db.createObjectStore("versions");
|
|
db.createObjectStore("versions");
|
|
|
|
|
|
db.createObjectStore("library");
|
|
db.createObjectStore("library");
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ if (oldVersion < 2) {
|
|
|
|
+ // TODO: update configs if version is updated in defaults
|
|
db.createObjectStore("configs");
|
|
db.createObjectStore("configs");
|
|
|
|
|
|
await tx
|
|
await tx
|
|
@@ -146,22 +142,26 @@ class MLIDbStorage {
|
|
DEFAULT_ML_SYNC_JOB_CONFIG,
|
|
DEFAULT_ML_SYNC_JOB_CONFIG,
|
|
ML_SYNC_JOB_CONFIG_NAME,
|
|
ML_SYNC_JOB_CONFIG_NAME,
|
|
);
|
|
);
|
|
-
|
|
|
|
await tx
|
|
await tx
|
|
.objectStore("configs")
|
|
.objectStore("configs")
|
|
.add(DEFAULT_ML_SYNC_CONFIG, ML_SYNC_CONFIG_NAME);
|
|
.add(DEFAULT_ML_SYNC_CONFIG, ML_SYNC_CONFIG_NAME);
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ if (oldVersion < 3) {
|
|
await tx
|
|
await tx
|
|
.objectStore("configs")
|
|
.objectStore("configs")
|
|
- .add(
|
|
|
|
- { enabled: wasMLSearchEnabled },
|
|
|
|
- ML_SEARCH_CONFIG_NAME,
|
|
|
|
- );
|
|
|
|
|
|
+ .add(DEFAULT_ML_SEARCH_CONFIG, ML_SEARCH_CONFIG_NAME);
|
|
|
|
+ }
|
|
|
|
+ if (oldVersion < 4) {
|
|
|
|
+ // TODO(MR): This loses the user's settings.
|
|
|
|
+ db.deleteObjectStore("configs");
|
|
|
|
+ db.createObjectStore("configs");
|
|
|
|
|
|
- log.info(
|
|
|
|
- `Ml DB upgraded to version: ${newVersion} from version: ${oldVersion}`,
|
|
|
|
- );
|
|
|
|
|
|
+ db.deleteObjectStore("things");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ log.info(
|
|
|
|
+ `Ml DB upgraded to version: ${newVersion} from version: ${oldVersion}`,
|
|
|
|
+ );
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}
|
|
}
|