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