From 0141a732c3f7d137fd55dce4df60a0f2ef6ffeef Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 26 May 2024 19:21:15 -0500 Subject: [PATCH] Add connections table --- src/db/DittoTables.ts | 10 ++++++++++ src/db/migrations/023_add_connections.ts | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/db/migrations/023_add_connections.ts diff --git a/src/db/DittoTables.ts b/src/db/DittoTables.ts index c2d1f861..31d85425 100644 --- a/src/db/DittoTables.ts +++ b/src/db/DittoTables.ts @@ -2,6 +2,7 @@ export interface DittoTables { nostr_events: EventRow; nostr_tags: TagRow; nostr_fts5: EventFTSRow; + connections: ConnectionRow; unattached_media: UnattachedMediaRow; author_stats: AuthorStatsRow; event_stats: EventStatsRow; @@ -44,6 +45,15 @@ interface TagRow { value: string; } +interface ConnectionRow { + api_token: string; + user_pubkey: string; + server_seckey: Uint8Array; + server_pubkey: string; + relays: string; + connected_at: Date; +} + interface UnattachedMediaRow { id: string; pubkey: string; diff --git a/src/db/migrations/023_add_connections.ts b/src/db/migrations/023_add_connections.ts new file mode 100644 index 00000000..6568c50c --- /dev/null +++ b/src/db/migrations/023_add_connections.ts @@ -0,0 +1,17 @@ +import { Kysely, sql } from 'kysely'; + +export async function up(db: Kysely): Promise { + await db.schema + .createTable('connections') + .addColumn('api_token', 'text', (col) => col.primaryKey().unique().notNull()) + .addColumn('user_pubkey', 'text', (col) => col.notNull()) + .addColumn('server_seckey', 'blob', (col) => col.notNull()) + .addColumn('server_pubkey', 'text', (col) => col.notNull()) + .addColumn('relays', 'text', (col) => col.defaultTo('[]')) + .addColumn('connected_at', 'timestamp', (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)) + .execute(); +} + +export async function down(db: Kysely): Promise { + await db.schema.dropTable('connections').execute(); +}