Browse Source

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
pull/77/head
Trent Larson 1 year ago
parent
commit
99db5deb77
  1. 27
      src/db/index.ts
  2. 7
      src/db/tables/settings.ts

27
src/db/index.ts

@ -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 () {

7
src/db/tables/settings.ts

@ -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;

Loading…
Cancel
Save