fix: dexie data upgrade
This commit is contained in:
parent
74b80b474e
commit
8350ac037e
@ -14,14 +14,14 @@ db.version(1).stores({
|
|||||||
files: 'id, name, origin_name, path, size, ext, type, created_at, count'
|
files: 'id, name, origin_name, path, size, ext, type, created_at, count'
|
||||||
})
|
})
|
||||||
|
|
||||||
db.version(2).stores({
|
db.version(2)
|
||||||
|
.stores({
|
||||||
files: 'id, name, origin_name, path, size, ext, type, created_at, count',
|
files: 'id, name, origin_name, path, size, ext, type, created_at, count',
|
||||||
topics: '&id, messages',
|
topics: '&id, messages',
|
||||||
settings: '&id, value'
|
settings: '&id, value'
|
||||||
})
|
})
|
||||||
|
.upgrade(populateTopics)
|
||||||
|
|
||||||
db.on('populate', async (trans) => {
|
db.on('populate', populateTopics)
|
||||||
populateTopics(trans)
|
|
||||||
})
|
|
||||||
|
|
||||||
export default db
|
export default db
|
||||||
|
|||||||
@ -5,10 +5,7 @@ import localforage from 'localforage'
|
|||||||
export async function populateTopics(trans: Transaction) {
|
export async function populateTopics(trans: Transaction) {
|
||||||
const indexedKeys = await localforage.keys()
|
const indexedKeys = await localforage.keys()
|
||||||
|
|
||||||
if (indexedKeys.length === 0) {
|
if (indexedKeys.length > 0) {
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const key of indexedKeys) {
|
for (const key of indexedKeys) {
|
||||||
const value: any = await localforage.getItem(key)
|
const value: any = await localforage.getItem(key)
|
||||||
if (key.startsWith('topic:')) {
|
if (key.startsWith('topic:')) {
|
||||||
@ -26,4 +23,5 @@ export async function populateTopics(trans: Transaction) {
|
|||||||
centered: true,
|
centered: true,
|
||||||
onOk: () => window.api.reload()
|
onOk: () => window.api.reload()
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user