summaryrefslogtreecommitdiff
path: root/ext/bg/js/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r--ext/bg/js/database.js29
1 files changed, 21 insertions, 8 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index a21708f5..9fb45794 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -20,23 +20,36 @@
class Database {
constructor() {
this.db = null;
+ this.dbVersion = 1;
this.tagMetaCache = {};
}
+ sanitize() {
+ const db = new Dexie('dict');
+ return db.open().then(() => {
+ db.close();
+ if (db.verno !== this.dbVersion) {
+ return db.delete();
+ }
+ }).catch(() => {});
+ }
+
prepare() {
if (this.db !== null) {
return Promise.reject('database already initialized');
}
- this.db = new Dexie('dict');
- this.db.version(1).stores({
- terms: '++id,dictionary,expression,reading',
- kanji: '++,dictionary,character',
- tagMeta: '++,dictionary',
- dictionaries: '++,title,version',
- });
+ return this.sanitize().then(() => {
+ this.db = new Dexie('dict');
+ this.db.version(this.dbVersion).stores({
+ terms: '++id,dictionary,expression,reading',
+ kanji: '++,dictionary,character',
+ tagMeta: '++,dictionary',
+ dictionaries: '++,title,version',
+ });
- return this.db.open();
+ return this.db.open();
+ });
}
purge() {