Soft-delete events

This commit is contained in:
Alex Gleason 2024-03-02 21:11:45 -06:00
parent 96b5ecc435
commit e4f53b3936
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 13 additions and 5 deletions

View File

@ -38,6 +38,7 @@ interface EventRow {
created_at: number;
tags: string;
sig: string;
deleted_at: number | null;
}
interface EventFTSRow {

View File

@ -0,0 +1,9 @@
import { Kysely } from '@/deps.ts';
export async function up(db: Kysely<any>): Promise<void> {
await db.schema.alterTable('events').addColumn('deleted_at', 'integer').execute();
}
export async function down(db: Kysely<any>): Promise<void> {
await db.schema.alterTable('events').dropColumn('deleted_at').execute();
}

View File

@ -155,6 +155,7 @@ class EventsDB implements NStore {
'events.created_at',
'events.sig',
])
.where('events.deleted_at', 'is', null)
.orderBy('events.created_at', 'desc');
for (const [key, value] of Object.entries(filter)) {
@ -329,12 +330,9 @@ class EventsDB implements NStore {
const query = this.getEventsQuery(filters).clearSelect().select('id');
await db.deleteFrom('events_fts')
.where('id', 'in', () => query)
.execute();
return db.deleteFrom('events')
return await db.updateTable('events')
.where('id', 'in', () => query)
.set({ deleted_at: Math.floor(Date.now() / 1000) })
.execute();
}