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 "drivers" (
"driverId" INT UNIQUE,
"forename" TEXT,
"surname" TEXT,
PRIMARY KEY ("driverId")
);

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"q1" TEXT,
PRIMARY KEY ("qualifyId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

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



INSERT INTO "races" VALUES ("1");
INSERT INTO "races" VALUES ("2");
INSERT INTO "races" VALUES ("3");
INSERT INTO "races" VALUES ("345");
INSERT INTO "races" VALUES ("346");
INSERT INTO "races" VALUES ("347");
INSERT INTO "drivers" VALUES ("1", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("3", "Lucas", "di Grassi");
INSERT INTO "drivers" VALUES ("4", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("5", "Valtteri", "Bottas");
INSERT INTO "drivers" VALUES ("6", "Daniel", "Ricciardo");
INSERT INTO "qualifying" VALUES ("1", "1", "1", "1", "1:25.000");
INSERT INTO "qualifying" VALUES ("2", "1", "2", "2", "1:25.100");
INSERT INTO "qualifying" VALUES ("3", "1", "3", "3", "1:25.200");
INSERT INTO "qualifying" VALUES ("4", "345", "1", "1", "1:20.500");
INSERT INTO "qualifying" VALUES ("5", "345", "2", "2", "1:20.600");
INSERT INTO "qualifying" VALUES ("6", "345", "3", "3", "1:20.700");
INSERT INTO "qualifying" VALUES ("7", "345", "4", "4", "1:20.800");
INSERT INTO "qualifying" VALUES ("8", "346", "3", "1", "1:22.000");
INSERT INTO "qualifying" VALUES ("9", "347", "3", "5", "1:23.500");
INSERT INTO "lapTimes" VALUES ("1", "1", "1", "85000");
INSERT INTO "lapTimes" VALUES ("1", "2", "1", "85100");
INSERT INTO "lapTimes" VALUES ("1", "3", "1", "85200");
INSERT INTO "lapTimes" VALUES ("345", "1", "1", "80500");
INSERT INTO "lapTimes" VALUES ("345", "2", "1", "80600");
INSERT INTO "lapTimes" VALUES ("345", "3", "1", "80700");
INSERT INTO "lapTimes" VALUES ("346", "3", "1", "82000");