Database: Add upload timestamp to MKW ghost data

This commit is contained in:
mkwcat
2024-09-07 15:05:51 -04:00
parent 240fdea556
commit 46f269d470
7 changed files with 90 additions and 73 deletions

View File

@@ -30,10 +30,10 @@ const (
"ORDER BY score DESC " +
"LIMIT 1"
insertGhostFileStatement = "" +
"INSERT INTO mario_kart_wii_sake (regionid, courseid, score, pid, playerinfo, ghost) " +
"VALUES ($1, $2, $3, $4, $5, $6) " +
"INSERT INTO mario_kart_wii_sake (regionid, courseid, score, pid, playerinfo, ghost, upload_time) " +
"VALUES ($1, $2, $3, $4, $5, $6, CURRENT_TIMESTAMP) " +
"ON CONFLICT (courseid, pid) DO UPDATE " +
"SET regionid = EXCLUDED.regionid, score = EXCLUDED.score, playerinfo = EXCLUDED.playerinfo, ghost = EXCLUDED.ghost"
"SET regionid = EXCLUDED.regionid, score = EXCLUDED.score, playerinfo = EXCLUDED.playerinfo, ghost = EXCLUDED.ghost, upload_time = CURRENT_TIMESTAMP"
)
func GetMarioKartWiiTopTenRankings(pool *pgxpool.Pool, ctx context.Context, regionId common.MarioKartWiiLeaderboardRegionId,

View File

@@ -19,22 +19,14 @@ ALTER TABLE ONLY public.users
ADD IF NOT EXISTS ban_reason_hidden character varying,
ADD IF NOT EXISTS ban_moderator character varying,
ADD IF NOT EXISTS ban_tos boolean,
ADD IF NOT EXISTS open_host boolean DEFAULT false
ADD IF NOT EXISTS open_host boolean DEFAULT false;
`)
CREATE TABLE IF NOT EXISTS public.mario_kart_wii_sake (
regionid smallint NOT NULL CHECK (regionid >= 1 AND regionid <= 7),
courseid smallint NOT NULL CHECK (courseid >= 0 AND courseid <= 32767),
score integer NOT NULL CHECK (score > 0),
pid integer NOT NULL CHECK (pid > 0),
playerinfo varchar(108) NOT NULL CHECK (LENGTH(playerinfo) = 108),
ghost bytea CHECK (ghost IS NULL OR (OCTET_LENGTH(ghost) BETWEEN 148 AND 10240)),
pool.Exec(ctx, `
ALTER TABLE ONLY public.mario_kart_wii_sake
ADD IF NOT EXISTS upload_time timestamp without time zone;
CONSTRAINT one_time_per_course_constraint UNIQUE (courseid, pid)
);
ALTER TABLE public.mario_kart_wii_sake OWNER TO wiilink;
`)
`)
}