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,
PRIMARY KEY ("driverId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"fastestLapTime" 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 "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("4", "Charles", "Leclerc");
INSERT INTO "races" VALUES ("101");
INSERT INTO "races" VALUES ("102");
INSERT INTO "races" VALUES ("103");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Retired");
INSERT INTO "status" VALUES ("3", "Disqualified");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "1:25.345");
INSERT INTO "results" VALUES ("1002", "101", "2", "2", "1:26.789");
INSERT INTO "results" VALUES ("1003", "101", "3", "3", "1:27.123");
INSERT INTO "results" VALUES ("1004", "102", "1", "2", "1:24.999");
INSERT INTO "results" VALUES ("1005", "102", "4", "1", "1:25.500");
INSERT INTO "results" VALUES ("1006", "103", "1", "3", "1:25.000");
INSERT INTO "results" VALUES ("1007", "103", "3", "1", "1:24.800");
INSERT INTO "results" VALUES ("1008", "103", "2", "2", "1:25.200");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "85435");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "85345");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "86789");
INSERT INTO "lapTimes" VALUES ("101", "3", "1", "87123");
INSERT INTO "lapTimes" VALUES ("102", "1", "1", "84999");
INSERT INTO "lapTimes" VALUES ("102", "4", "1", "85500");
INSERT INTO "lapTimes" VALUES ("103", "1", "1", "85000");
INSERT INTO "lapTimes" VALUES ("103", "3", "1", "84800");
INSERT INTO "lapTimes" VALUES ("103", "2", "1", "85200");