Files
ditto/src/db/migrations/041_pg_notify_id_only.ts
P. Reis 6fd0c273cb fix: follow people
create a new migration that replaces the function to NOTIFY only the event id
2024-10-29 11:07:51 -03:00

28 lines
783 B
TypeScript

import { Kysely, sql } from 'kysely';
export async function up(db: Kysely<any>): Promise<void> {
await sql`DROP TRIGGER IF EXISTS nostr_event_trigger ON nostr_events`.execute(db);
await sql`
CREATE OR REPLACE FUNCTION notify_nostr_event()
RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('nostr_event', NEW.id::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
`.execute(db);
await sql`
CREATE TRIGGER nostr_event_trigger
AFTER INSERT OR UPDATE ON nostr_events
FOR EACH ROW EXECUTE FUNCTION notify_nostr_event()
`.execute(db);
}
export async function down(db: Kysely<any>): Promise<void> {
await sql`DROP TRIGGER nostr_event_trigger ON nostr_events`.execute(db);
await sql`DROP FUNCTION notify_nostr_event()`.execute(db);
}