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 "lapTimes" (
"raceId" INT,
"driverId" INT,
"lap" INT,
"milliseconds" INT,
PRIMARY KEY ("raceId", "driverId", "lap")
);

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"forename" TEXT,
"surname" TEXT,
"dob" DATE,
PRIMARY KEY ("driverId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"time" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

CREATE TABLE "status" (
"statusId" INT,
"status" TEXT,
PRIMARY KEY ("statusId")
);



INSERT INTO "lapTimes" VALUES ("872", "1", "1", "90000");
INSERT INTO "lapTimes" VALUES ("872", "1", "2", "89000");
INSERT INTO "lapTimes" VALUES ("872", "2", "1", "91000");
INSERT INTO "lapTimes" VALUES ("872", "2", "2", "90500");
INSERT INTO "lapTimes" VALUES ("872", "3", "1", "92000");
INSERT INTO "lapTimes" VALUES ("872", "3", "2", "91500");
INSERT INTO "lapTimes" VALUES ("872", "4", "1", "93000");
INSERT INTO "lapTimes" VALUES ("872", "4", "2", "92500");
INSERT INTO "lapTimes" VALUES ("873", "1", "1", "88000");
INSERT INTO "lapTimes" VALUES ("873", "5", "1", "95000");
INSERT INTO "drivers" VALUES ("1", "Max", "Verstappen", "1997-09-30");
INSERT INTO "drivers" VALUES ("2", "Lewis", "Hamilton", "1985-01-07");
INSERT INTO "drivers" VALUES ("3", "Charles", "Leclerc", "1997-10-16");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso", "1981-07-29");
INSERT INTO "drivers" VALUES ("5", "Lando", "Norris", "1999-11-13");
INSERT INTO "drivers" VALUES ("6", "George", "Russell", "1998-02-15");
INSERT INTO "races" VALUES ("872");
INSERT INTO "races" VALUES ("873");
INSERT INTO "races" VALUES ("874");
INSERT INTO "results" VALUES ("1", "872", "1", "1", "1:30:00.000");
INSERT INTO "results" VALUES ("2", "872", "2", "2", "1:30:05.000");
INSERT INTO "results" VALUES ("3", "872", "3", "3", "1:30:10.000");
INSERT INTO "results" VALUES ("4", "872", "4", "4", "NULL");
INSERT INTO "results" VALUES ("5", "873", "1", "1", "1:29:00.000");
INSERT INTO "results" VALUES ("6", "873", "5", "2", "1:29:10.000");
INSERT INTO "results" VALUES ("7", "872", "5", "5", "1:30:15.000");
INSERT INTO "results" VALUES ("8", "872", "6", "6", "1:30:20.000");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Retired");
INSERT INTO "status" VALUES ("3", "Disqualified");