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 "races" VALUES ("1");
INSERT INTO "races" VALUES ("2");
INSERT INTO "races" VALUES ("3");
INSERT INTO "drivers" VALUES ("101");
INSERT INTO "drivers" VALUES ("102");
INSERT INTO "drivers" VALUES ("103");
INSERT INTO "drivers" VALUES ("104");
INSERT INTO "drivers" VALUES ("105");
INSERT INTO "pitStops" VALUES ("1", "101", "1", "15", "22.345");
INSERT INTO "pitStops" VALUES ("1", "101", "2", "35", "18.500");
INSERT INTO "pitStops" VALUES ("1", "102", "1", "20", "45.000");
INSERT INTO "pitStops" VALUES ("1", "103", "1", "18", "12.000");
INSERT INTO "pitStops" VALUES ("1", "104", "1", "22", "45.000");
INSERT INTO "pitStops" VALUES ("1", "105", "1", "25", "5.500");
INSERT INTO "pitStops" VALUES ("2", "101", "1", "10", "30.123");
INSERT INTO "pitStops" VALUES ("2", "102", "1", "12", "28.999");
INSERT INTO "pitStops" VALUES ("2", "103", "1", "14", "19.876");
INSERT INTO "pitStops" VALUES ("2", "104", "1", "16", "10.000");
INSERT INTO "pitStops" VALUES ("3", "105", "1", "8", "45.000");
INSERT INTO "pitStops" VALUES ("3", "101", "1", "9", "7.250");
INSERT INTO "pitStops" VALUES ("3", "102", "1", "11", "15.000");
INSERT INTO "pitStops" VALUES ("3", "103", "1", "13", "22.500");
INSERT INTO "pitStops" VALUES ("3", "104", "1", "15", "9.999");
INSERT INTO "lapTimes" VALUES ("1", "101", "1", "90000");
INSERT INTO "lapTimes" VALUES ("1", "102", "1", "89000");
INSERT INTO "lapTimes" VALUES ("1", "103", "1", "88000");
INSERT INTO "lapTimes" VALUES ("1", "104", "1", "87000");
INSERT INTO "lapTimes" VALUES ("1", "105", "1", "86000");
INSERT INTO "qualifying" VALUES ("1", "1");
INSERT INTO "qualifying" VALUES ("2", "2");
INSERT INTO "qualifying" VALUES ("3", "3");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");