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 "constructorResults" (
"constructorResultsId" INT,
"points" FLOAT,
PRIMARY KEY ("constructorResultsId")
);

CREATE TABLE "lapTimes" (
"raceId" INT,
"driverId" INT,
"lap" INT,
"milliseconds" INT,
PRIMARY KEY ("raceId", "driverId", "lap")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
PRIMARY KEY ("raceId")
);

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"points" FLOAT,
"fastestLapTime" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId")
);



INSERT INTO "constructorResults" VALUES ("1", "25.0");
INSERT INTO "constructorResults" VALUES ("2", "18.0");
INSERT INTO "constructorResults" VALUES ("3", "15.0");
INSERT INTO "races" VALUES ("101", "2020");
INSERT INTO "races" VALUES ("102", "2021");
INSERT INTO "races" VALUES ("103", "2022");
INSERT INTO "results" VALUES ("201", "101", "25.0", "01:15.345");
INSERT INTO "results" VALUES ("202", "101", "18.0", "01:16.789");
INSERT INTO "results" VALUES ("203", "102", "15.0", "01:14.999");
INSERT INTO "results" VALUES ("204", "102", "10.0", "01:15.500");
INSERT INTO "results" VALUES ("205", "103", "12.0", "01:15.000");
INSERT INTO "results" VALUES ("206", "103", "8.0", "NULL");
INSERT INTO "lapTimes" VALUES ("101", "301", "1", "75345");
INSERT INTO "lapTimes" VALUES ("101", "301", "2", "76000");
INSERT INTO "lapTimes" VALUES ("102", "302", "1", "74999");
INSERT INTO "lapTimes" VALUES ("102", "302", "2", "75500");
INSERT INTO "lapTimes" VALUES ("103", "303", "1", "75000");
INSERT INTO "lapTimes" VALUES ("103", "303", "2", "76000");