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,
"lat" FLOAT,
"lng" FLOAT,
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,
"raceId" INT,
"milliseconds" INT,
"fastestLapTime" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId")
);



INSERT INTO "circuits" VALUES ("1", "37.9794", "23.7162");
INSERT INTO "circuits" VALUES ("2", "43.7333", "7.4167");
INSERT INTO "circuits" VALUES ("3", "35.6895", "139.6917");
INSERT INTO "circuits" VALUES ("4", "51.5074", "0.1278");
INSERT INTO "circuits" VALUES ("5", "-33.8688", "151.2093");
INSERT INTO "circuits" VALUES ("6", "48.8566", "2.3522");
INSERT INTO "circuits" VALUES ("7", "40.7128", "-74.0060");
INSERT INTO "circuits" VALUES ("8", "34.0522", "-118.2437");
INSERT INTO "circuits" VALUES ("9", "52.3676", "4.9041");
INSERT INTO "circuits" VALUES ("10", "41.9028", "12.4964");
INSERT INTO "races" VALUES ("1", "1", "2023-03-05");
INSERT INTO "races" VALUES ("2", "2", "2023-03-19");
INSERT INTO "races" VALUES ("3", "3", "2023-04-02");
INSERT INTO "races" VALUES ("4", "4", "2023-04-16");
INSERT INTO "races" VALUES ("5", "5", "2023-04-30");
INSERT INTO "races" VALUES ("6", "1", "2022-03-06");
INSERT INTO "races" VALUES ("7", "2", "2022-03-20");
INSERT INTO "races" VALUES ("8", "3", "2022-04-03");
INSERT INTO "races" VALUES ("9", "6", "2023-05-14");
INSERT INTO "races" VALUES ("10", "7", "2023-05-28");
INSERT INTO "lapTimes" VALUES ("1", "101", "1", "1:30.000", "90000");
INSERT INTO "lapTimes" VALUES ("1", "101", "2", "1:29.488", "89488");
INSERT INTO "lapTimes" VALUES ("1", "102", "1", "1:31.000", "91000");
INSERT INTO "lapTimes" VALUES ("2", "103", "1", "1:28.000", "88000");
INSERT INTO "lapTimes" VALUES ("2", "103", "2", "1:29.488", "89488");
INSERT INTO "lapTimes" VALUES ("3", "104", "1", "1:32.000", "92000");
INSERT INTO "lapTimes" VALUES ("4", "105", "1", "1:29.488", "89488");
INSERT INTO "lapTimes" VALUES ("5", "106", "1", "1:30.500", "90500");
INSERT INTO "lapTimes" VALUES ("6", "107", "1", "1:29.488", "89488");
INSERT INTO "lapTimes" VALUES ("7", "108", "1", "1:29.000", "89000");
INSERT INTO "lapTimes" VALUES ("8", "109", "1", "1:29.488", "89488");
INSERT INTO "lapTimes" VALUES ("9", "110", "1", "1:30.100", "90100");
INSERT INTO "lapTimes" VALUES ("10", "111", "1", "1:29.488", "89488");
INSERT INTO "results" VALUES ("1", "1", "5400000", "1:29.488");
INSERT INTO "results" VALUES ("2", "2", "5300000", "1:28.000");
INSERT INTO "results" VALUES ("3", "3", "5500000", "1:32.000");
INSERT INTO "results" VALUES ("4", "4", "5450000", "1:29.488");
INSERT INTO "results" VALUES ("5", "5", "5600000", "1:30.500");
INSERT INTO "results" VALUES ("6", "6", "5400000", "1:29.488");
INSERT INTO "results" VALUES ("7", "7", "5300000", "1:29.000");
INSERT INTO "results" VALUES ("8", "8", "5500000", "1:29.488");
INSERT INTO "results" VALUES ("9", "9", "5400000", "1:30.100");
INSERT INTO "results" VALUES ("10", "10", "5300000", "1:29.488");