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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"position" INT,
"rank" INT,
"fastestLapTime" TEXT,
"fastestLapSpeed" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId")
);



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", "2023", "3", "Bahrain Grand Prix");
INSERT INTO "races" VALUES ("5", "2022", "1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("6", "2021", "7", "Austrian Grand Prix");
INSERT INTO "races" VALUES ("7", "2020", "7", "Styrian Grand Prix");
INSERT INTO "lapTimes" VALUES ("1", "101", "1", "1:25.000", "85000");
INSERT INTO "lapTimes" VALUES ("1", "101", "2", "1:24.500", "84500");
INSERT INTO "lapTimes" VALUES ("2", "102", "1", "1:07.500", "67500");
INSERT INTO "lapTimes" VALUES ("2", "102", "2", "1:07.000", "67000");
INSERT INTO "lapTimes" VALUES ("3", "103", "1", "1:06.800", "66800");
INSERT INTO "lapTimes" VALUES ("3", "103", "2", "1:06.500", "66500");
INSERT INTO "lapTimes" VALUES ("4", "104", "1", "1:32.000", "92000");
INSERT INTO "lapTimes" VALUES ("6", "105", "1", "1:06.900", "66900");
INSERT INTO "lapTimes" VALUES ("6", "105", "2", "1:06.700", "66700");
INSERT INTO "lapTimes" VALUES ("7", "106", "1", "1:07.100", "67100");
INSERT INTO "lapTimes" VALUES ("7", "106", "2", "1:07.050", "67050");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "1:23.500", "250.0");
INSERT INTO "results" VALUES ("2", "2", "1", "1", "1:06.000", "230.0");
INSERT INTO "results" VALUES ("3", "3", "2", "2", "1:06.200", "229.5");
INSERT INTO "results" VALUES ("4", "4", "1", "1", "1:31.000", "245.0");
INSERT INTO "results" VALUES ("5", "5", "3", "3", "1:24.000", "249.0");
INSERT INTO "results" VALUES ("6", "6", "1", "1", "1:06.100", "229.8");
INSERT INTO "results" VALUES ("7", "7", "2", "2", "1:06.500", "228.0");