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 "constructorResults" (
"constructorResultsId" INT,
"status" TEXT,
PRIMARY KEY ("constructorResultsId")
);

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

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

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

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



INSERT INTO "constructorResults" VALUES ("1", "Finished");
INSERT INTO "constructorResults" VALUES ("2", "Accident");
INSERT INTO "constructorResults" VALUES ("3", "Engine Failure");
INSERT INTO "drivers" VALUES ("44", "Lewis", "Hamilton", "British");
INSERT INTO "drivers" VALUES ("33", "Max", "Verstappen", "Dutch");
INSERT INTO "drivers" VALUES ("16", "Charles", "Leclerc", "Monegasque");
INSERT INTO "races" VALUES ("101");
INSERT INTO "races" VALUES ("102");
INSERT INTO "lapTimes" VALUES ("101", "44", "1", "1");
INSERT INTO "lapTimes" VALUES ("101", "44", "2", "1");
INSERT INTO "lapTimes" VALUES ("101", "33", "1", "2");
INSERT INTO "lapTimes" VALUES ("101", "33", "2", "2");
INSERT INTO "lapTimes" VALUES ("102", "44", "1", "3");
INSERT INTO "lapTimes" VALUES ("102", "44", "2", "2");
INSERT INTO "lapTimes" VALUES ("102", "16", "1", "1");
INSERT INTO "pitStops" VALUES ("101", "44", "1", "15", "14:32:10", "22.345", "22345");
INSERT INTO "pitStops" VALUES ("101", "44", "2", "35", "14:50:05", "18.123", "18123");
INSERT INTO "pitStops" VALUES ("101", "33", "1", "20", "14:40:00", "19.876", "19876");
INSERT INTO "pitStops" VALUES ("102", "44", "1", "10", "15:10:00", "25.789", "25789");
INSERT INTO "pitStops" VALUES ("102", "16", "1", "12", "15:12:30", "20.456", "20456");
INSERT INTO "pitStops" VALUES ("102", "44", "2", "30", "15:30:00", "24.000", "24000");