db: remove some external deps

This commit is contained in:
Alex Gleason 2025-02-16 11:42:48 -06:00
parent dbfd759fba
commit e1c1967a66
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 1 additions and 20 deletions

View file

@ -4,8 +4,6 @@ import path from 'node:path';
import { logi } from '@soapbox/logi';
import { FileMigrationProvider, type Kysely, Migrator } from 'kysely';
import { errorJson } from '@/utils/log.ts';
import { DittoPglite } from './adapters/DittoPglite.ts';
import { DittoPostgres } from './adapters/DittoPostgres.ts';
@ -51,7 +49,7 @@ export class DittoDB {
msg: 'Migration failed.',
state: 'failed',
results: results as unknown as JsonValue,
error: errorJson(error),
error: error instanceof Error ? error : null,
});
Deno.exit(1);
} else {

View file

@ -1,9 +1,5 @@
import { type Kysely, sql } from 'kysely';
import { Conf } from '@/config.ts';
import { aesEncrypt } from '@/utils/aes.ts';
import { getTokenHash } from '@/utils/auth.ts';
interface DB {
nip46_tokens: {
api_token: `token1${string}`;
@ -32,19 +28,6 @@ export async function up(db: Kysely<DB>): Promise<void> {
.addColumn('created_at', 'timestamp', (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`))
.execute();
// There are probably not that many tokens in the database yet, so this should be fine.
const tokens = await db.selectFrom('nip46_tokens').selectAll().execute();
for (const token of tokens) {
await db.insertInto('auth_tokens').values({
token_hash: await getTokenHash(token.api_token),
pubkey: token.user_pubkey,
nip46_sk_enc: await aesEncrypt(Conf.seckey, token.server_seckey),
nip46_relays: JSON.parse(token.relays),
created_at: token.connected_at,
}).execute();
}
await db.schema.dropTable('nip46_tokens').execute();
}