attempt migration to consolidate name fields, but it fails with these errors:

- Transaction aborted
- Not yet support for changing primary key
- TypeError: WeakMap key must be an object, got pr
This commit is contained in:
2023-11-05 15:43:57 -07:00
parent 7450d8d1c3
commit 99db5deb77
2 changed files with 32 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import {
MASTER_SETTINGS_KEY,
Settings,
SettingsSchema,
SettingsSchemaV1,
} from "./tables/settings";
import { AppString } from "@/constants/app";
@@ -34,6 +35,8 @@ const SensitiveSchemas = Object.assign({}, AccountsSchema);
export type NonsensitiveDexie<T extends unknown = NonsensitiveTables> =
BaseDexie & T;
export const db = new BaseDexie("TimeSafari") as NonsensitiveDexie;
// eslint-disable-next-line prettier/prettier
const NonsensitiveSchemasV1 = Object.assign({}, ContactsSchema, SettingsSchemaV1);
const NonsensitiveSchemas = Object.assign({}, ContactsSchema, SettingsSchema);
/**
@@ -57,7 +60,29 @@ if (localStorage.getItem("secret") == null) {
encrypted(accountsDB, { secretKey: secret });
accountsDB.version(1).stores(SensitiveSchemas);
db.version(1).stores(NonsensitiveSchemas);
db.version(1).stores(NonsensitiveSchemasV1);
db.version(2)
.stores(NonsensitiveSchemas)
.upgrade((tx) => {
return tx
.table("settings")
.toCollection()
.modify((settings) => {
if (
typeof settings.firstName === "string" &&
typeof settings.lastName === "string"
) {
settings.firstName += " " + settings.lastName;
} else if (typeof settings.lastName === "string") {
settings.firstName = settings.lastName;
}
delete settings.lastName;
})
.catch((e) => {
console.log("caught modify exception", e);
});
});
// initialize, a la https://dexie.org/docs/Tutorial/Design#the-populate-event
db.on("populate", function () {

View File

@@ -21,8 +21,13 @@ export type Settings = {
showContactGivesInline?: boolean;
};
export const SettingsSchema = {
export const SettingsSchemaV1 = {
settings: "id",
};
export const SettingsSchema = {
settings:
"id, activeDid, apiServer, firstName, lastname, lastViewedClaimId, searchBoxes, showContactGivesInline",
};
export const MASTER_SETTINGS_KEY = 1;