92 lines
3.7 KiB
JavaScript
92 lines
3.7 KiB
JavaScript
import { sqlite, skinDB } from "./init.js"
|
|
import tasks from "./tasks.js"
|
|
|
|
/**
|
|
* This constructs the DB with indexes and rankings...
|
|
* @module db/generateDB
|
|
*/
|
|
export function generateDB() {
|
|
/* TODO: Clean this up as it is a mess */
|
|
console.log("Generating race index")
|
|
|
|
/* Generate race index TODO: Remove useless ones */
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_race_Map_2" ON "race" ("Map","Name")`)
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_race_Name" ON "race" ("Name","Timestamp")`)
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_race_Server" ON "race" ("Server")`)
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_race_MapTimestamp" ON "race" ("Map","Timestamp")`)
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_race_Timestamp" ON "race" ("Timestamp")`)
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_race_MapNameTime" ON "race" ("Map", "Name", "Time")`)
|
|
|
|
/* Create rankings table */
|
|
console.log("Creating rankings table")
|
|
sqlite.exec(`
|
|
CREATE TABLE IF NOT EXISTS "rankings" (
|
|
"Map" varchar(128) NOT NULL,
|
|
"Name" varchar(16) NOT NULL,
|
|
"Time" float NOT NULL DEFAULT 0,
|
|
"Timestamp" timestamp NOT NULL DEFAULT current_timestamp,
|
|
"Server" char(4) NOT NULL DEFAULT '',
|
|
"rank" INTEGER NOT NULL);
|
|
`)
|
|
|
|
console.log("Calculating rankings for each map")
|
|
tasks.processRankings()
|
|
|
|
/* Generate rankings index */
|
|
console.log("Generating rankings index")
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_rankings_map" ON "rankings" ("Map")`)
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_rankings_rank" ON "rankings" ("rank")`)
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_rankings_player" ON "rankings" ("Name")`)
|
|
|
|
/* Generate teamrace index */
|
|
console.log("Generating teamrace index")
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_teamrace_Map" ON "teamrace" ("Map")`);
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_teamrace_ID" ON "teamrace" ("ID")`);
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_teamrace_MapID" ON "teamrace" ("Map", "ID")`);
|
|
|
|
console.log("Creating teamrankings table")
|
|
sqlite.exec(`
|
|
CREATE TABLE IF NOT EXISTS "teamrankings" (
|
|
"Map" varchar(128) NOT NULL,
|
|
"ID" varbinary(16) NOT NULL,
|
|
"Name" varchar(16) NOT NULL,
|
|
"Time" float NOT NULL DEFAULT 0,
|
|
"Timestamp" timestamp NOT NULL DEFAULT current_timestamp,
|
|
"Server" char(4) NOT NULL DEFAULT '',
|
|
"teamrank" INTEGER NOT NULL);
|
|
`)
|
|
|
|
console.log("Calculating teamrankings for each map")
|
|
tasks.processTeamRankings()
|
|
|
|
console.log("Generating teamrankings index")
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_teamrankings_map" ON "teamrankings" ("Map")`)
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_teamrankings_rank" ON "teamrankings" ("teamrank")`)
|
|
sqlite.exec(`CREATE INDEX IF NOT EXISTS "idx_teamrankings_player" ON "teamrankings" ("name")`)
|
|
|
|
sqlite.exec(`
|
|
CREATE TABLE IF NOT EXISTS "points" (
|
|
"rank" INTEGER NOT NULL,
|
|
"name" varchar(16) NOT NULL,
|
|
"points" INTEGER NOT NULL);
|
|
`)
|
|
|
|
/* Process all types of points */
|
|
console.log("Inserting points to DB")
|
|
tasks.processAllPoints()
|
|
|
|
skinDB.exec(`
|
|
CREATE TABLE IF NOT EXISTS "skindata" (
|
|
"timestamp" INTEGER NOT NULL,
|
|
"player" varchar(16) NOT NULL,
|
|
"clan" varchar(12) NOT NULL,
|
|
"flag" INTEGER NOT NULL,
|
|
"skin" varchar(16) NOT NULL,
|
|
"useColor" INTEGER NOT NULL,
|
|
"colorBodyRaw" INTEGER NOT NULL,
|
|
"colorBodyHex" varchar(8) NOT NULL,
|
|
"colorFeetRaw" INTEGER NOT NULL,
|
|
"colorFeetHex" varchar(8) NOT NULL);
|
|
`)
|
|
}
|