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,
"location" TEXT,
"country" TEXT,
"lat" FLOAT,
PRIMARY KEY ("circuitId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"constructorId" INT,
"milliseconds" INT,
"fastestLapTime" TEXT,
"fastestLapSpeed" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId")
);



INSERT INTO "circuits" VALUES ("1", "Red Bull Ring", "Spielberg", "Austria", "47.2197");
INSERT INTO "circuits" VALUES ("2", "Silverstone Circuit", "Silverstone", "United Kingdom", "52.0786");
INSERT INTO "circuits" VALUES ("3", "Monza Circuit", "Monza", "Italy", "45.6156");
INSERT INTO "races" VALUES ("101", "2023", "10", "1", "Austrian Grand Prix", "2023-07-09", "14:00:00");
INSERT INTO "races" VALUES ("102", "2022", "11", "1", "Austrian Grand Prix", "2022-07-10", "14:00:00");
INSERT INTO "races" VALUES ("103", "2023", "12", "2", "British Grand Prix", "2023-07-16", "14:00:00");
INSERT INTO "races" VALUES ("104", "2023", "13", "3", "Italian Grand Prix", "2023-09-03", "14:00:00");
INSERT INTO "lapTimes" VALUES ("101", "201", "1", "1:05.123", "65123");
INSERT INTO "lapTimes" VALUES ("101", "201", "2", "1:04.987", "64987");
INSERT INTO "lapTimes" VALUES ("101", "202", "1", "1:05.500", "65500");
INSERT INTO "lapTimes" VALUES ("102", "201", "1", "1:05.200", "65200");
INSERT INTO "lapTimes" VALUES ("102", "203", "1", "1:04.800", "64800");
INSERT INTO "lapTimes" VALUES ("103", "204", "1", "1:25.000", "85000");
INSERT INTO "lapTimes" VALUES ("104", "205", "1", "1:20.000", "80000");
INSERT INTO "results" VALUES ("1001", "101", "201", "301", "5400000", "1:04.987", "230.5");
INSERT INTO "results" VALUES ("1002", "102", "203", "302", "5380000", "1:04.800", "231.0");
INSERT INTO "results" VALUES ("1003", "103", "204", "303", "6000000", "1:25.000", "210.0");
INSERT INTO "results" VALUES ("1004", "104", "205", "304", "5900000", "1:20.000", "220.0");