Skip to content

Commit

Permalink
Add last_played and first_played columns to ladder table
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Oct 22, 2024
1 parent fb000e6 commit 1486ae1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ladder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface LadderEntry {
elo: number;
col1: number;
oldelo: number;
first_played: number;
last_played: number;
}

interface MatchElement {
Expand Down Expand Up @@ -73,9 +75,11 @@ export class Ladder {
if (!create) return null;

const rp = this.getRP();
const now = time();
const res = await ladder.insert({
formatid: this.formatid, username: user, userid,
rptime: rp, rpdata: '', col1: 0,
first_played: now, last_played: now,
});
return {
entryid: res.insertId,
Expand All @@ -90,6 +94,8 @@ export class Ladder {
elo: 1000,
col1: 0,
oldelo: 0,
first_played: now,
last_played: now,
};
}
static async getAllRatings(user: string) {
Expand Down Expand Up @@ -172,7 +178,7 @@ export class Ladder {
col1, entryid,
} = rating;
return !!(await ladder.update(entryid, {
elo, w, l, t, r, rd, sigma, rptime, rpr, rprd, rpsigma, rpdata, gxe, col1,
elo, w, l, t, r, rd, sigma, rptime, rpr, rprd, rpsigma, rpdata, gxe, col1, last_played: time(),
}));
}

Expand Down
8 changes: 8 additions & 0 deletions src/schemas/migrations/ladder-1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BEGIN;

ALTER TABLE ntbb_ladder
ADD COLUMN first_played bigint(20),
ADD COLUMN last_played bigint(20),
ALGORITHM=INSTANT;

COMMIT;

0 comments on commit 1486ae1

Please sign in to comment.