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