auto add/drop db spaces
This commit is contained in:
parent
92ece197a1
commit
c4ca8cdd5e
3 changed files with 22 additions and 9 deletions
|
|
@ -176,14 +176,25 @@
|
|||
request = IDB.open(name, this.version);
|
||||
|
||||
request.onupgradeneeded = function(event) {
|
||||
if (options.delete === true) {
|
||||
storage.db.deleteObjectStore(name);
|
||||
return;
|
||||
}
|
||||
let db = storage.db = request.result;
|
||||
for (let store of storage.stores) {
|
||||
let current = [...db.objectStoreNames];
|
||||
let stores = storage.stores;
|
||||
// add missing stores
|
||||
for (let store of stores) {
|
||||
if (current.indexOf(store) >= 0) {
|
||||
continue;
|
||||
}
|
||||
storage.created[store] = db.createObjectStore(store);
|
||||
storage.current = store;
|
||||
current.push(store);
|
||||
console.log({index_added: store});
|
||||
}
|
||||
// remove obsolete stores
|
||||
for (let curr of current) {
|
||||
if (stores.indexOf(curr) < 0) {
|
||||
storage.db.deleteObjectStore(curr);
|
||||
console.log({index_dropped: curr});
|
||||
}
|
||||
}
|
||||
event.target.transaction.oncomplete = function(event) {
|
||||
storage.runQueue();
|
||||
|
|
@ -197,7 +208,7 @@
|
|||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
console.log({error:event});
|
||||
console.log({error: event});
|
||||
fallback();
|
||||
};
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@
|
|||
|
||||
let broker = gapp.broker;
|
||||
let call = broker.send;
|
||||
let dbindex = [ "admin", "space" ];
|
||||
|
||||
function init() {
|
||||
let stores = data.open('mesh', { stores:[ "admin", "cache", "space" ] }).init(),
|
||||
let stores = data.open('mesh', { stores: dbindex, version: 4 }).init(),
|
||||
moto = self.moto,
|
||||
api = mesh.api,
|
||||
dark = false,
|
||||
|
|
@ -19,8 +20,7 @@ function init() {
|
|||
platform = space.platform,
|
||||
db = mesh.db = {
|
||||
admin: stores.promise('admin'),
|
||||
space: stores.promise('space'),
|
||||
cache: stores.promise('cache')
|
||||
space: stores.promise('space')
|
||||
};
|
||||
|
||||
// mark init time and use count
|
||||
|
|
|
|||
|
|
@ -361,6 +361,7 @@ let tool = {
|
|||
api.log.emit('repairing mesh(es)...').pin();
|
||||
tool.heal(models, { merge: true }).then(() => {
|
||||
api.log.emit('repair commplete').pin();
|
||||
api.selection.update();
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -368,6 +369,7 @@ let tool = {
|
|||
api.log.emit('cleaning mesh(es)...').pin();
|
||||
tool.heal(models, { merge: false }).then(() => {
|
||||
api.log.emit('cleaning complete').pin();
|
||||
api.selection.update();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue