diff --git a/index.ts b/index.ts index 310ed6e..b4d67a1 100644 --- a/index.ts +++ b/index.ts @@ -17,9 +17,15 @@ declare module "express-session" { const dbVersion: { version: number } | undefined = await dbGet("SELECT version FROM version;"); - if (dbVersion && dbVersion.version === 1) { - console.log("skip db setup") - return; + if (dbVersion) { + if (dbVersion.version === 2) { + console.log("skip db setup") + 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 ( @@ -53,7 +59,7 @@ app.get("/leaderboard", async (req: Request, res: Response) => { const { limit = 100, offset = 0 } = req.query; const leaders = await dbAll(` -select h.score, u.name +select h.score, u.name, h.created from highScores h join main.users u on u.id = h.user order by score desc