diff --git a/src/db/DittoTables.ts b/src/db/DittoTables.ts index 26b2e6f..b4950af 100644 --- a/src/db/DittoTables.ts +++ b/src/db/DittoTables.ts @@ -1,4 +1,4 @@ -import { Nullable } from 'kysely'; +import { Generated, Nullable } from 'kysely'; import { NPostgresSchema } from '@nostrify/db'; @@ -58,11 +58,11 @@ interface EventZapRow { } interface PushSubscriptionRow { - id: bigint; + id: Generated; pubkey: string; endpoint: string; - key_p256dh: string; - key_auth: string; + p256dh: string; + auth: string; data: { alerts?: { mention?: boolean; @@ -78,6 +78,6 @@ interface PushSubscriptionRow { }; policy?: 'all' | 'followed' | 'follower' | 'none'; } | null; - created_at: Date; - updated_at: Date; + created_at: Generated; + updated_at: Generated; } diff --git a/src/db/migrations/023_add_nip46_tokens.ts b/src/db/migrations/023_add_nip46_tokens.ts index 144bd1e..01d7164 100644 --- a/src/db/migrations/023_add_nip46_tokens.ts +++ b/src/db/migrations/023_add_nip46_tokens.ts @@ -3,7 +3,7 @@ import { Kysely, sql } from 'kysely'; export async function up(db: Kysely): Promise { await db.schema .createTable('nip46_tokens') - .addColumn('api_token', 'text', (col) => col.primaryKey().unique().notNull()) + .addColumn('api_token', 'text', (col) => col.primaryKey().notNull()) .addColumn('user_pubkey', 'text', (col) => col.notNull()) .addColumn('server_seckey', 'bytea', (col) => col.notNull()) .addColumn('server_pubkey', 'text', (col) => col.notNull()) diff --git a/src/db/migrations/038_push_subscriptions.ts b/src/db/migrations/038_push_subscriptions.ts new file mode 100644 index 0000000..5e80ddc --- /dev/null +++ b/src/db/migrations/038_push_subscriptions.ts @@ -0,0 +1,20 @@ +import { Kysely, sql } from 'kysely'; + +export async function up(db: Kysely): Promise { + await db.schema + .createTable('push_subscriptions') + .addColumn('id', 'bigint', (c) => c.primaryKey().autoIncrement()) + .addColumn('pubkey', 'char(64)', (c) => c.notNull()) + .addColumn('token', 'char(64)', (c) => c.notNull()) + .addColumn('endpoint', 'text', (c) => c.notNull()) + .addColumn('p256dh', 'text', (c) => c.notNull()) + .addColumn('auth', 'text', (c) => c.notNull()) + .addColumn('data', 'jsonb') + .addColumn('created_at', 'timestamp', (c) => c.notNull().defaultTo(sql`CURRENT_TIMESTAMP`)) + .addColumn('updated_at', 'timestamp', (c) => c.notNull().defaultTo(sql`CURRENT_TIMESTAMP`)) + .execute(); +} + +export async function down(db: Kysely): Promise { + await db.schema.dropTable('push_subscriptions').execute(); +} diff --git a/src/pipeline.ts b/src/pipeline.ts index a00456a..f854209 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -230,6 +230,8 @@ async function streamOut(event: NostrEvent): Promise { if (isFresh(event)) { const pubsub = await Storages.pubsub(); await pubsub.event(event); + + // TODO: Web Push } }