From 98aaab8e51d95eabbc7ba299d0df87fa12298024 Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Mon, 1 Jul 2024 21:42:50 +0530 Subject: [PATCH] switch to deno.land/postgresjs for free 4x speed increase --- deno.json | 2 +- scripts/db-migrate.ts | 6 ++++++ src/db/adapters/DittoPostgres.ts | 2 +- src/test.ts | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/deno.json b/deno.json index 190e76fb..5d7e9cf8 100644 --- a/deno.json +++ b/deno.json @@ -50,8 +50,8 @@ "iso-639-1": "npm:iso-639-1@2.1.15", "isomorphic-dompurify": "npm:isomorphic-dompurify@^2.11.0", "kysely": "npm:kysely@^0.27.3", + "postgres": "https://deno.land/x/postgresjs@v3.4.3/mod.js", "kysely-postgres-js": "npm:kysely-postgres-js@2.0.0", - "postgres": "npm:postgres@3.4.4", "light-bolt11-decoder": "npm:light-bolt11-decoder", "linkify-plugin-hashtag": "npm:linkify-plugin-hashtag@^4.1.1", "linkify-string": "npm:linkify-string@^4.1.1", diff --git a/scripts/db-migrate.ts b/scripts/db-migrate.ts index b9f63bfe..36602aef 100644 --- a/scripts/db-migrate.ts +++ b/scripts/db-migrate.ts @@ -1,4 +1,10 @@ import { DittoDB } from '@/db/DittoDB.ts'; +import { delay } from '@/test.ts'; + +if (Deno.env.get('CI') && Deno.env.get('DATABASE_URL')?.startsWith('postgres')) { + console.info('Waiting 15 seconds for postgres to start...'); + await delay(15000); +} const kysely = await DittoDB.getInstance(); await kysely.destroy(); diff --git a/src/db/adapters/DittoPostgres.ts b/src/db/adapters/DittoPostgres.ts index cbb26aeb..c7974a5c 100644 --- a/src/db/adapters/DittoPostgres.ts +++ b/src/db/adapters/DittoPostgres.ts @@ -14,7 +14,7 @@ export class DittoPostgres { if (!this.db) { this.db = new Kysely({ dialect: new PostgresJSDialect({ - postgres: postgres(Conf.databaseUrl) + postgres: postgres(Conf.databaseUrl) as any }), log: KyselyLogger }); diff --git a/src/test.ts b/src/test.ts index b0172063..17dbb4bb 100644 --- a/src/test.ts +++ b/src/test.ts @@ -62,3 +62,5 @@ export async function getTestDB() { [Symbol.asyncDispose]: () => kysely.destroy(), }; } + +export const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); \ No newline at end of file