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")
);

CREATE TABLE "circuits" (
"circuitId" INT UNIQUE,
"name" TEXT,
PRIMARY KEY ("circuitId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"circuitId" INT,
"name" TEXT,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);



INSERT INTO "circuits" VALUES ("1", "Albert Park Grand Prix Circuit");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit");
INSERT INTO "circuits" VALUES ("3", "Bahrain International Circuit");
INSERT INTO "circuits" VALUES ("4", "Circuit de Barcelona-Catalunya");
INSERT INTO "circuits" VALUES ("5", "Circuit de Monaco");
INSERT INTO "circuits" VALUES ("6", "Circuit Gilles Villeneuve");
INSERT INTO "circuits" VALUES ("7", "Red Bull Ring");
INSERT INTO "circuits" VALUES ("8", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("9", "Hockenheimring");
INSERT INTO "circuits" VALUES ("10", "Hungaroring");
INSERT INTO "races" VALUES ("1", "2023", "1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "2023", "7", "Austrian Grand Prix");
INSERT INTO "races" VALUES ("3", "2022", "7", "Austrian Grand Prix");
INSERT INTO "races" VALUES ("4", "2021", "7", "Austrian Grand Prix");
INSERT INTO "races" VALUES ("5", "2023", "8", "British Grand Prix");
INSERT INTO "races" VALUES ("6", "2020", "7", "Styrian Grand Prix");
INSERT INTO "races" VALUES ("7", "2019", "7", "Austrian Grand Prix");
INSERT INTO "races" VALUES ("8", "2018", "7", "Austrian Grand Prix");
INSERT INTO "lapTimes" VALUES ("2", "1", "1", "1:07.500", "67500");
INSERT INTO "lapTimes" VALUES ("2", "2", "2", "1:07.450", "67450");
INSERT INTO "lapTimes" VALUES ("2", "3", "3", "1:07.600", "67600");
INSERT INTO "lapTimes" VALUES ("3", "1", "1", "1:07.300", "67300");
INSERT INTO "lapTimes" VALUES ("3", "2", "2", "1:07.350", "67350");
INSERT INTO "lapTimes" VALUES ("4", "1", "1", "1:07.200", "67200");
INSERT INTO "lapTimes" VALUES ("4", "2", "2", "1:07.250", "67250");
INSERT INTO "lapTimes" VALUES ("5", "1", "1", "1:25.000", "85000");
INSERT INTO "lapTimes" VALUES ("6", "1", "1", "1:07.150", "67150");
INSERT INTO "lapTimes" VALUES ("7", "1", "1", "1:07.100", "67100");
INSERT INTO "lapTimes" VALUES ("8", "1", "1", "1:07.050", "67050");
INSERT INTO "lapTimes" VALUES ("8", "2", "2", "1:07.000", "67000");