move DB initialization

This commit is contained in:
martin-mfg
2025-06-21 13:33:38 +00:00
parent f979145768
commit 9fc5b57c2c
2 changed files with 5 additions and 18 deletions
-2
View File
@@ -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);
+5 -16
View File
@@ -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)