PRAGMA foreign_keys = ON;

PRAGMA writable_schema = 1;
DELETE FROM sqlite_master WHERE type IN ("table", "index", "trigger");
PRAGMA writable_schema = 0;
VACUUM;

CREATE TABLE "driverStandings" (
"driverStandingsId" INT,
"points" FLOAT,
PRIMARY KEY ("driverStandingsId")
);

CREATE TABLE "lapTimes" (
"raceId" INT,
"driverId" INT,
"lap" INT,
"milliseconds" INT,
PRIMARY KEY ("raceId", "driverId", "lap")
);

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"number" INT,
PRIMARY KEY ("driverId")
);

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"q3" TEXT,
PRIMARY KEY ("qualifyId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
PRIMARY KEY ("raceId")
);

CREATE TABLE "results" (
"resultId" INT,
"position" INT,
PRIMARY KEY ("resultId")
);



INSERT INTO "driverStandings" VALUES ("1", "25.0");
INSERT INTO "driverStandings" VALUES ("2", "18.0");
INSERT INTO "driverStandings" VALUES ("3", "15.0");
INSERT INTO "driverStandings" VALUES ("4", "12.0");
INSERT INTO "driverStandings" VALUES ("5", "10.0");
INSERT INTO "lapTimes" VALUES ("1", "1", "1", "90000");
INSERT INTO "lapTimes" VALUES ("1", "1", "2", "89000");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "91000");
INSERT INTO "lapTimes" VALUES ("2", "3", "1", "88000");
INSERT INTO "lapTimes" VALUES ("2", "4", "1", "92000");
INSERT INTO "drivers" VALUES ("1", "44");
INSERT INTO "drivers" VALUES ("2", "77");
INSERT INTO "drivers" VALUES ("3", "33");
INSERT INTO "drivers" VALUES ("4", "16");
INSERT INTO "drivers" VALUES ("5", "5");
INSERT INTO "drivers" VALUES ("6", "11");
INSERT INTO "races" VALUES ("901");
INSERT INTO "races" VALUES ("902");
INSERT INTO "races" VALUES ("903");
INSERT INTO "races" VALUES ("904");
INSERT INTO "races" VALUES ("905");
INSERT INTO "qualifying" VALUES ("1", "901", "1", "1:25.123");
INSERT INTO "qualifying" VALUES ("2", "901", "2", "1:25.500");
INSERT INTO "qualifying" VALUES ("3", "902", "3", "1:24.999");
INSERT INTO "qualifying" VALUES ("4", "903", "4", "0:01:54.000");
INSERT INTO "qualifying" VALUES ("5", "903", "5", "0:01:55.123");
INSERT INTO "qualifying" VALUES ("6", "903", "6", "0:01:54.500");
INSERT INTO "qualifying" VALUES ("7", "904", "1", "1:26.000");
INSERT INTO "qualifying" VALUES ("8", "905", "2", "1:27.000");
INSERT INTO "qualifying" VALUES ("9", "903", "1", "0:01:54.001");
INSERT INTO "qualifying" VALUES ("10", "903", "2", "0:01:54.999");
INSERT INTO "qualifying" VALUES ("11", "903", "3", "0:01:54");
INSERT INTO "qualifying" VALUES ("12", "903", "4", "0:01:54.123");
INSERT INTO "qualifying" VALUES ("13", "903", "5", "0:01:54.0");
INSERT INTO "qualifying" VALUES ("14", "903", "6", "0:01:54.00");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");
INSERT INTO "results" VALUES ("4", "4");
INSERT INTO "results" VALUES ("5", "5");