Soft-delete events
This commit is contained in:
parent
96b5ecc435
commit
e4f53b3936
|
@ -38,6 +38,7 @@ interface EventRow {
|
|||
created_at: number;
|
||||
tags: string;
|
||||
sig: string;
|
||||
deleted_at: number | null;
|
||||
}
|
||||
|
||||
interface EventFTSRow {
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue