diff --git a/src/db/index.ts b/src/db/index.ts index 02a41ba..db06ca0 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -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, }, ]) } diff --git a/src/stores/appStore.ts b/src/stores/appStore.ts index 152a087..44f82f7 100644 --- a/src/stores/appStore.ts +++ b/src/stores/appStore.ts @@ -82,6 +82,7 @@ export const useAppStore = create((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 }))