Creating a mechanism to store settings both in the database and in redux.
This commit is contained in:
1 parent
07edc22d31
commit
c0015a7cfa
10 files changed
+272
-18
No files matched your search
+18
-8
@@ -1,17 +1,22 @@
|
||||
import _ from 'lodash';
|
||||
import _, { constant } from 'lodash';
|
||||
import uri from '../lib/ids';
|
||||
|
||||
const DBDEFINITION = '--db-definition--';
|
||||
const dbDefinitionId = uri('dbdef', {});
|
||||
|
||||
const dbDefinition = {
|
||||
_id: DBDEFINITION,
|
||||
type: DBDEFINITION,
|
||||
version: '0.000001',
|
||||
const currentDbDefinition = {
|
||||
_id: dbDefinitionId,
|
||||
type: dbDefinitionId,
|
||||
def: { version: '0.000001' },
|
||||
};
|
||||
|
||||
export const initDb = async (db: any, setDbReady: any) => {
|
||||
var previousDbDefinition = {
|
||||
_id: dbDefinitionId,
|
||||
type: dbDefinitionId,
|
||||
def: { version: '0' },
|
||||
};
|
||||
try {
|
||||
await db.get(DBDEFINITION);
|
||||
// TODO: support migrations
|
||||
previousDbDefinition = await db.get(dbDefinitionId);
|
||||
} catch (error: any) {
|
||||
if (error.status !== 404) {
|
||||
console.log(
|
||||
@@ -21,6 +26,11 @@ export const initDb = async (db: any, setDbReady: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (previousDbDefinition.def.version < currentDbDefinition.def.version) {
|
||||
previousDbDefinition.def = currentDbDefinition.def;
|
||||
db.put(previousDbDefinition);
|
||||
// TODO: support migrations
|
||||
}
|
||||
await await db.compact();
|
||||
await db.viewCleanup();
|
||||
|
||||
|
||||
Reference in new issue
Block a user