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)
|
||||||
files: 'id, name, origin_name, path, size, ext, type, created_at, count',
|
.stores({
|
||||||
topics: '&id, messages',
|
files: 'id, name, origin_name, path, size, ext, type, created_at, count',
|
||||||
settings: '&id, value'
|
topics: '&id, messages',
|
||||||
})
|
settings: '&id, value'
|
||||||
|
})
|
||||||
|
.upgrade(populateTopics)
|
||||||
|
|
||||||
db.on('populate', async (trans) => {
|
db.on('populate', populateTopics)
|
||||||
populateTopics(trans)
|
|
||||||
})
|
|
||||||
|
|
||||||
export default db
|
export default db
|
||||||
|
|||||||
@ -5,25 +5,23 @@ 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) {
|
||||||
}
|
const value: any = await localforage.getItem(key)
|
||||||
|
if (key.startsWith('topic:')) {
|
||||||
for (const key of indexedKeys) {
|
await trans.db.table('topics').add({ id: value.id, messages: value.messages })
|
||||||
const value: any = await localforage.getItem(key)
|
}
|
||||||
if (key.startsWith('topic:')) {
|
if (key === 'image://avatar') {
|
||||||
await trans.db.table('topics').add({ id: value.id, messages: value.messages })
|
await trans.db.table('settings').add({ id: key, value: await localforage.getItem(key) })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (key === 'image://avatar') {
|
|
||||||
await trans.db.table('settings').add({ id: key, value: await localforage.getItem(key) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.modal.success({
|
window.modal.success({
|
||||||
title: i18n.t('message.upgrade.success.title'),
|
title: i18n.t('message.upgrade.success.title'),
|
||||||
content: i18n.t('message.upgrade.success.content'),
|
content: i18n.t('message.upgrade.success.content'),
|
||||||
okText: i18n.t('message.upgrade.success.button'),
|
okText: i18n.t('message.upgrade.success.button'),
|
||||||
centered: true,
|
centered: true,
|
||||||
onOk: () => window.api.reload()
|
onOk: () => window.api.reload()
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user