From 4c87679fbe087352486025e7fc339d79e69f59c7 Mon Sep 17 00:00:00 2001 From: Hare Date: Tue, 3 Sep 2024 09:06:51 +0900 Subject: [PATCH] feat: move database initialization to get_connection.ts --- src/lib/server/database.ts | 5 ----- src/lib/server/database/get_connection.ts | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib/server/database.ts b/src/lib/server/database.ts index 189b72f..cc4d196 100644 --- a/src/lib/server/database.ts +++ b/src/lib/server/database.ts @@ -1,5 +1,4 @@ import pg from 'pg'; -import { getConnection } from './database/get_connection'; export class Postgres { client: pg.PoolClient | null = null; @@ -33,7 +32,3 @@ export class Postgres { export default async ( pool: pg.Pool ) => { return await Postgres.new(pool); }; - -import { building } from '$app/environment'; -import init from '$lib/server/database/init_db'; -if (!building) await init(await Postgres.new(getConnection())); diff --git a/src/lib/server/database/get_connection.ts b/src/lib/server/database/get_connection.ts index 8e65981..b8eee44 100644 --- a/src/lib/server/database/get_connection.ts +++ b/src/lib/server/database/get_connection.ts @@ -13,3 +13,7 @@ const connectionString = `postgres://${PG_USER}:${PG_PASS}@${PG_HOST}:${PG_PORT} const pool = new Pool({ connectionString }); export const getConnection = () => pool; + +import init from '$lib/server/database/init_db'; +import PG from '$lib/server/database'; +await init(await PG(pool)); \ No newline at end of file