add created timestamp to leaderboard
This commit is contained in:
parent
9d1c43e593
commit
06a95f0f9d
10
index.ts
10
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) {
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue