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

CREATE TABLE "pitStops" (
"raceId" INT,
"driverId" INT,
"stop" INT,
"time" TEXT,
"duration" TEXT,
PRIMARY KEY ("raceId", "driverId", "stop"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"time" TEXT,
"milliseconds" INT,
PRIMARY KEY ("resultId")
);



INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("3", "Charles", "Leclerc");
INSERT INTO "drivers" VALUES ("4", "Fernando", "Alonso");
INSERT INTO "drivers" VALUES ("5", "Sergio", "Perez");
INSERT INTO "pitStops" VALUES ("1", "1", "1", "14:30:00", "2.500");
INSERT INTO "pitStops" VALUES ("1", "1", "2", "14:55:00", "3.100");
INSERT INTO "pitStops" VALUES ("1", "2", "1", "14:31:00", "2.200");
INSERT INTO "pitStops" VALUES ("2", "1", "1", "15:05:00", "2.800");
INSERT INTO "pitStops" VALUES ("2", "1", "2", "15:30:00", "4.000");
INSERT INTO "pitStops" VALUES ("2", "3", "1", "15:06:00", "2.300");
INSERT INTO "pitStops" VALUES ("3", "1", "1", "16:10:00", "2.900");
INSERT INTO "pitStops" VALUES ("3", "4", "1", "16:11:00", "2.600");
INSERT INTO "pitStops" VALUES ("4", "1", "1", "17:00:00", "2.700");
INSERT INTO "pitStops" VALUES ("4", "1", "2", "17:25:00", "3.500");
INSERT INTO "pitStops" VALUES ("4", "5", "1", "17:01:00", "2.400");
INSERT INTO "lapTimes" VALUES ("1", "1", "1", "1:30.000");
INSERT INTO "lapTimes" VALUES ("1", "1", "2", "1:29.500");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "1:30.100");
INSERT INTO "lapTimes" VALUES ("2", "1", "1", "1:28.000");
INSERT INTO "lapTimes" VALUES ("2", "3", "1", "1:28.500");
INSERT INTO "results" VALUES ("1", "1:35:00.000", "5700000");
INSERT INTO "results" VALUES ("2", "1:34:50.000", "5690000");
INSERT INTO "results" VALUES ("3", "1:36:10.000", "5770000");