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