add created timestamp to leaderboard

This commit is contained in:
CodedSakura 2024-11-16 20:38:30 +02:00
parent 9d1c43e593
commit 06a95f0f9d
1 changed files with 10 additions and 4 deletions

View File

@ -17,9 +17,15 @@ declare module "express-session" {
const dbVersion: { version: number } | undefined const dbVersion: { version: number } | undefined
= await dbGet("SELECT version FROM version;"); = await dbGet("SELECT version FROM version;");
if (dbVersion && dbVersion.version === 1) { if (dbVersion) {
if (dbVersion.version === 2) {
console.log("skip db setup") console.log("skip db setup")
return; return;
} else if (dbVersion.version === 1) {
await dbRun("ALTER TABLE highScores ADD COLUMN created TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
await dbRun("UPDATE version SET version = 2");
return;
}
} }
await dbRun(`CREATE TABLE IF NOT EXISTS users ( await dbRun(`CREATE TABLE IF NOT EXISTS users (
@ -53,7 +59,7 @@ app.get("/leaderboard", async (req: Request, res: Response) => {
const { limit = 100, offset = 0 } = req.query; const { limit = 100, offset = 0 } = req.query;
const leaders = await dbAll(` const leaders = await dbAll(`
select h.score, u.name select h.score, u.name, h.created
from highScores h from highScores h
join main.users u on u.id = h.user join main.users u on u.id = h.user
order by score desc order by score desc