purge old database versions

This commit is contained in:
Alex Yatskov 2016-12-30 10:47:27 -08:00
parent 80225a00d3
commit 9dfafe9d26
2 changed files with 22 additions and 9 deletions

View File

@ -20,23 +20,36 @@
class Database { class Database {
constructor() { constructor() {
this.db = null; this.db = null;
this.dbVersion = 1;
this.tagMetaCache = {}; this.tagMetaCache = {};
} }
sanitize() {
const db = new Dexie('dict');
return db.open().then(() => {
db.close();
if (db.verno !== this.dbVersion) {
return db.delete();
}
}).catch(() => {});
}
prepare() { prepare() {
if (this.db !== null) { if (this.db !== null) {
return Promise.reject('database already initialized'); return Promise.reject('database already initialized');
} }
this.db = new Dexie('dict'); return this.sanitize().then(() => {
this.db.version(1).stores({ this.db = new Dexie('dict');
terms: '++id,dictionary,expression,reading', this.db.version(this.dbVersion).stores({
kanji: '++,dictionary,character', terms: '++id,dictionary,expression,reading',
tagMeta: '++,dictionary', kanji: '++,dictionary,character',
dictionaries: '++,title,version', tagMeta: '++,dictionary',
}); dictionaries: '++,title,version',
});
return this.db.open(); return this.db.open();
});
} }
purge() { purge() {

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Yomichan", "name": "Yomichan",
"version": "1.0.0", "version": "1.0.1",
"description": "Japanese dictionary with Anki integration", "description": "Japanese dictionary with Anki integration",
"icons": {"16": "img/icon16.png", "48": "img/icon48.png", "128": "img/icon128.png"}, "icons": {"16": "img/icon16.png", "48": "img/icon48.png", "128": "img/icon128.png"},