|
@@ -14,40 +14,27 @@ export interface NovelDb extends DBSchema {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default function getDb() {
|
|
export default function getDb() {
|
|
|
- return openDB<NovelDb>("NovelDit", 2, {
|
|
|
|
|
|
|
+ return openDB<NovelDb>("NovelDit", 3, {
|
|
|
upgrade(db, oldVersion, newVersion) {
|
|
upgrade(db, oldVersion, newVersion) {
|
|
|
- console.log(oldVersion, newVersion);
|
|
|
|
|
- if (oldVersion === 0) {
|
|
|
|
|
- const historyStore = db.createObjectStore("history", {
|
|
|
|
|
- keyPath: "uri",
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- historyStore.createIndex("historyUpdateTime", "readTime", {
|
|
|
|
|
- unique: false,
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- historyStore.createIndex(
|
|
|
|
|
- "historyIsReading",
|
|
|
|
|
- ["isReading", "readTime"],
|
|
|
|
|
- {
|
|
|
|
|
- unique: false,
|
|
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ if (newVersion && newVersion > oldVersion) {
|
|
|
|
|
+ db.deleteObjectStore("history");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- historyStore.createIndex("historyIsFavorite", "isFavorite", {
|
|
|
|
|
- unique: false,
|
|
|
|
|
- });
|
|
|
|
|
- } else if (oldVersion === 1) {
|
|
|
|
|
- const historyStore = db.transaction("history", "versionchange");
|
|
|
|
|
|
|
+ const historyStore = db.createObjectStore("history", {
|
|
|
|
|
+ keyPath: "uri",
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- const store = historyStore.store;
|
|
|
|
|
|
|
+ historyStore.createIndex("historyUpdateTime", "readTime", {
|
|
|
|
|
+ unique: false,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- store.deleteIndex("historyIsFavorite");
|
|
|
|
|
|
|
+ historyStore.createIndex("historyIsReading", ["isReading", "readTime"], {
|
|
|
|
|
+ unique: false,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- store.createIndex("historyIsFavorite", "isFavorite", {
|
|
|
|
|
- unique: false,
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ historyStore.createIndex("historyIsFavorite", "isFavorite", {
|
|
|
|
|
+ unique: false,
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|