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,
"lap" INT,
"duration" TEXT,
PRIMARY KEY ("raceId", "driverId", "stop"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

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

CREATE TABLE "qualifying" (
"qualifyId" INT,
"position" INT,
PRIMARY KEY ("qualifyId")
);

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

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



INSERT INTO "drivers" VALUES ("1");
INSERT INTO "drivers" VALUES ("2");
INSERT INTO "drivers" VALUES ("3");
INSERT INTO "races" VALUES ("101");
INSERT INTO "races" VALUES ("102");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "90000");
INSERT INTO "lapTimes" VALUES ("101", "1", "2", "88000");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "91000");
INSERT INTO "lapTimes" VALUES ("101", "3", "1", "92000");
INSERT INTO "lapTimes" VALUES ("102", "1", "1", "87000");
INSERT INTO "lapTimes" VALUES ("102", "2", "1", "86000");
INSERT INTO "pitStops" VALUES ("101", "1", "1", "15", "00:20.500");
INSERT INTO "pitStops" VALUES ("101", "1", "2", "30", "00:18.300");
INSERT INTO "pitStops" VALUES ("101", "2", "1", "20", "00:22.100");
INSERT INTO "pitStops" VALUES ("101", "3", "1", "25", "00:19.900");
INSERT INTO "pitStops" VALUES ("102", "1", "1", "10", "00:21.000");
INSERT INTO "pitStops" VALUES ("102", "2", "1", "18", "00:23.750");
INSERT INTO "pitStops" VALUES ("102", "3", "1", "22", "00:20.000");
INSERT INTO "qualifying" VALUES ("201", "1");
INSERT INTO "qualifying" VALUES ("202", "2");
INSERT INTO "qualifying" VALUES ("203", "3");
INSERT INTO "results" VALUES ("301", "1");
INSERT INTO "results" VALUES ("302", "2");
INSERT INTO "results" VALUES ("303", "3");