feat: Note 添加 deletedAt 软删除字段,Dexie 升级 v2
This commit is contained in:
parent
27ebe43e54
commit
e44af4b1cd
@ -10,6 +10,7 @@ export interface Note {
|
||||
createdAt: number
|
||||
updatedAt: number
|
||||
wordCount: number
|
||||
deletedAt: number | null
|
||||
}
|
||||
|
||||
export interface Folder {
|
||||
@ -38,6 +39,17 @@ class NotesDB extends Dexie {
|
||||
folders: 'id, parentId, order',
|
||||
tags: 'id, name',
|
||||
})
|
||||
this.version(2).stores({
|
||||
notes: 'id, folderId, starred, updatedAt, createdAt, deletedAt, *tags',
|
||||
folders: 'id, parentId, order',
|
||||
tags: 'id, name',
|
||||
}).upgrade(tx => {
|
||||
return tx.table('notes').toCollection().modify(note => {
|
||||
if (note.deletedAt === undefined) {
|
||||
note.deletedAt = null
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,6 +98,7 @@ async function _doSeed() {
|
||||
createdAt: now - 86400000,
|
||||
updatedAt: now - 3600000,
|
||||
wordCount: 30,
|
||||
deletedAt: null,
|
||||
},
|
||||
{
|
||||
id: crypto.randomUUID(),
|
||||
@ -104,6 +117,7 @@ async function _doSeed() {
|
||||
createdAt: now - 172800000,
|
||||
updatedAt: now - 172800000,
|
||||
wordCount: 45,
|
||||
deletedAt: null,
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
@ -82,6 +82,7 @@ export const useAppStore = create<AppState>((set, get) => ({
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
wordCount: 0,
|
||||
deletedAt: null,
|
||||
}
|
||||
await db.notes.add(note)
|
||||
set(s => ({ notes: [note, ...s.notes], activeNoteId: id, _notesVersion: s._notesVersion + 1, _filteredCache: null }))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user