From 9fc5b57c2c061bb053321717ad8625be549f1134 Mon Sep 17 00:00:00 2001 From: martin-mfg <2026226+martin-mfg@users.noreply.github.com> Date: Sat, 21 Jun 2025 13:33:38 +0000 Subject: [PATCH] move DB initialization --- express.js | 2 -- src/common/utils.js | 21 +++++---------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/express.js b/express.js index 8fd9b3c4..ddc69ba7 100644 --- a/express.js +++ b/express.js @@ -5,9 +5,7 @@ import langCard from "./api/top-langs.js"; import wakatimeCard from "./api/wakatime.js"; import gistCard from "./api/gist.js"; import express from "express"; -import ensureDbSchema from "./src/common/utils.js"; -ensureDbSchema(); const app = express(); app.listen(process.env.port || 9000); diff --git a/src/common/utils.js b/src/common/utils.js index 2cf89cca..4bcb6efd 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -257,22 +257,6 @@ const request = (data, headers) => { }); }; -/** - * Creates the database table "requests" if it does not exist. - */ -export async function ensureDbSchema() { - if (!pool) { - return; - } - const createTableSQL = ` - CREATE TABLE IF NOT EXISTS requests ( - request TEXT PRIMARY KEY, - requested_at TIMESTAMP NOT NULL DEFAULT now() - ); - `; - await pool.query(createTableSQL); -} - /** * Stores or updates the request in the database. */ @@ -281,6 +265,11 @@ export async function storeRequest(req) { return; } const query = ` + CREATE TABLE IF NOT EXISTS requests ( + request TEXT PRIMARY KEY, + requested_at TIMESTAMP NOT NULL DEFAULT now() + ); + INSERT INTO requests (request, requested_at) VALUES ($1, NOW()) ON CONFLICT (request)