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

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

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 "drivers" VALUES ("4");
INSERT INTO "drivers" VALUES ("5");
INSERT INTO "drivers" VALUES ("6");
INSERT INTO "drivers" VALUES ("7");
INSERT INTO "races" VALUES ("101");
INSERT INTO "lapTimes" VALUES ("101", "1", "1", "1:20.500", "80500");
INSERT INTO "lapTimes" VALUES ("101", "2", "1", "1:19.800", "79800");
INSERT INTO "lapTimes" VALUES ("101", "3", "1", "1:21.000", "81000");
INSERT INTO "lapTimes" VALUES ("101", "4", "1", "1:19.500", "79500");
INSERT INTO "lapTimes" VALUES ("101", "5", "1", "1:20.000", "80000");
INSERT INTO "lapTimes" VALUES ("101", "6", "1", "1:22.000", "82000");
INSERT INTO "lapTimes" VALUES ("101", "7", "1", "1:19.500", "79500");
INSERT INTO "pitStops" VALUES ("101", "1", "1", "25.000");
INSERT INTO "pitStops" VALUES ("101", "2", "1", "24.500");
INSERT INTO "pitStops" VALUES ("101", "3", "1", "26.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");