forked from trent_larson/crowd-funder-for-time-pwa
Compare commits
2 Commits
035f2a5b04
...
why-migrat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa6cf0c9f6 | ||
| 99db5deb77 |
@@ -6,6 +6,7 @@ import {
|
|||||||
MASTER_SETTINGS_KEY,
|
MASTER_SETTINGS_KEY,
|
||||||
Settings,
|
Settings,
|
||||||
SettingsSchema,
|
SettingsSchema,
|
||||||
|
SettingsSchemaV1,
|
||||||
} from "./tables/settings";
|
} from "./tables/settings";
|
||||||
import { AppString } from "@/constants/app";
|
import { AppString } from "@/constants/app";
|
||||||
|
|
||||||
@@ -34,6 +35,8 @@ const SensitiveSchemas = Object.assign({}, AccountsSchema);
|
|||||||
export type NonsensitiveDexie<T extends unknown = NonsensitiveTables> =
|
export type NonsensitiveDexie<T extends unknown = NonsensitiveTables> =
|
||||||
BaseDexie & T;
|
BaseDexie & T;
|
||||||
export const db = new BaseDexie("TimeSafari") as NonsensitiveDexie;
|
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);
|
const NonsensitiveSchemas = Object.assign({}, ContactsSchema, SettingsSchema);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +60,29 @@ if (localStorage.getItem("secret") == null) {
|
|||||||
encrypted(accountsDB, { secretKey: secret });
|
encrypted(accountsDB, { secretKey: secret });
|
||||||
accountsDB.version(1).stores(SensitiveSchemas);
|
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
|
// initialize, a la https://dexie.org/docs/Tutorial/Design#the-populate-event
|
||||||
db.on("populate", function () {
|
db.on("populate", function () {
|
||||||
|
|||||||
@@ -22,8 +22,13 @@ export type Settings = {
|
|||||||
showContactGivesInline?: boolean;
|
showContactGivesInline?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SettingsSchema = {
|
export const SettingsSchemaV1 = {
|
||||||
settings: "id",
|
settings: "id",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const SettingsSchema = {
|
||||||
|
settings:
|
||||||
|
"id, activeDid, apiServer, firstName, lastname, lastViewedClaimId, searchBoxes, showContactGivesInline",
|
||||||
|
};
|
||||||
|
|
||||||
export const MASTER_SETTINGS_KEY = 1;
|
export const MASTER_SETTINGS_KEY = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user