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,
"position" 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,
"circuitId" INT,
"date" DATE,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);

CREATE TABLE "results" (
"resultId" INT,
"position" INT,
PRIMARY KEY ("resultId")
);



INSERT INTO "circuits" VALUES ("1", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("2", "Monza Circuit");
INSERT INTO "circuits" VALUES ("3", "Spa-Francorchamps");
INSERT INTO "circuits" VALUES ("4", "Suzuka Circuit");
INSERT INTO "races" VALUES ("101", "1", "2023-07-09");
INSERT INTO "races" VALUES ("102", "2", "2023-09-03");
INSERT INTO "races" VALUES ("103", "3", "2023-08-27");
INSERT INTO "races" VALUES ("104", "4", "2023-10-08");
INSERT INTO "lapTimes" VALUES ("101", "201", "1", "1", "1:27.345", "8745");
INSERT INTO "lapTimes" VALUES ("101", "202", "1", "2", "1:27.678", "8778");
INSERT INTO "lapTimes" VALUES ("101", "201", "2", "1", "1:26.999", "8699");
INSERT INTO "lapTimes" VALUES ("101", "203", "1", "3", "1:28.123", "88123");
INSERT INTO "lapTimes" VALUES ("102", "204", "1", "1", "1:30.456", "90456");
INSERT INTO "lapTimes" VALUES ("102", "205", "1", "2", "1:30.789", "90789");
INSERT INTO "lapTimes" VALUES ("102", "204", "2", "1", "1:29.999", "89999");
INSERT INTO "lapTimes" VALUES ("103", "206", "1", "1", "1:45.321", "105321");
INSERT INTO "lapTimes" VALUES ("103", "207", "1", "2", "1:45.654", "105654");
INSERT INTO "lapTimes" VALUES ("103", "206", "2", "1", "1:44.999", "104999");
INSERT INTO "lapTimes" VALUES ("104", "208", "1", "1", "1:32.111", "92111");
INSERT INTO "lapTimes" VALUES ("104", "209", "1", "2", "1:32.444", "92444");
INSERT INTO "lapTimes" VALUES ("104", "208", "2", "1", "1:31.999", "91999");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");
INSERT INTO "results" VALUES ("4", "4");