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

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

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



INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Max", "Verstappen");
INSERT INTO "races" VALUES ("101");
INSERT INTO "races" VALUES ("102");
INSERT INTO "races" VALUES ("103");
INSERT INTO "pitStops" VALUES ("101", "1", "1", "22000");
INSERT INTO "pitStops" VALUES ("101", "1", "2", "21000");
INSERT INTO "pitStops" VALUES ("102", "1", "1", "23000");
INSERT INTO "pitStops" VALUES ("103", "1", "1", "21500");
INSERT INTO "pitStops" VALUES ("101", "2", "1", "25000");
INSERT INTO "pitStops" VALUES ("102", "2", "1", "24000");
INSERT INTO "pitStops" VALUES ("103", "3", "1", "20000");
INSERT INTO "pitStops" VALUES ("103", "3", "2", "19500");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "90000");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "88000");
INSERT INTO "lapTimes" VALUES ("102", "1", "1", "87000");
INSERT INTO "lapTimes" VALUES ("103", "1", "1", "86000");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "89000");
INSERT INTO "lapTimes" VALUES ("102", "2", "1", "88500");
INSERT INTO "lapTimes" VALUES ("103", "3", "1", "87000");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");