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 "driverStandings" (
"driverStandingsId" INT,
"driverId" INT,
PRIMARY KEY ("driverStandingsId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

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

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"dob" DATE,
PRIMARY KEY ("driverId")
);

CREATE TABLE "races" (
"raceId" INT,
"date" DATE,
PRIMARY KEY ("raceId")
);

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"time" TEXT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);



INSERT INTO "drivers" VALUES ("1", "1985-04-12");
INSERT INTO "drivers" VALUES ("2", "1990-11-23");
INSERT INTO "drivers" VALUES ("3", "1982-07-30");
INSERT INTO "drivers" VALUES ("4", "1988-01-15");
INSERT INTO "drivers" VALUES ("5", "1982-07-30");
INSERT INTO "drivers" VALUES ("6", "1995-05-05");
INSERT INTO "races" VALUES ("590", "2023-07-01");
INSERT INTO "races" VALUES ("591", "2023-07-08");
INSERT INTO "races" VALUES ("592", "2023-07-15");
INSERT INTO "races" VALUES ("593", "2023-07-22");
INSERT INTO "results" VALUES ("1001", "592", "1", "1:30:45");
INSERT INTO "results" VALUES ("1002", "592", "2", "1:31:10");
INSERT INTO "results" VALUES ("1003", "592", "3", "1:29:55");
INSERT INTO "results" VALUES ("1004", "592", "4", "NULL");
INSERT INTO "results" VALUES ("1005", "592", "5", "1:30:00");
INSERT INTO "results" VALUES ("1006", "592", "6", "1:32:20");
INSERT INTO "results" VALUES ("1007", "590", "1", "1:28:00");
INSERT INTO "results" VALUES ("1008", "591", "2", "1:29:00");
INSERT INTO "driverStandings" VALUES ("201", "1");
INSERT INTO "driverStandings" VALUES ("202", "2");
INSERT INTO "driverStandings" VALUES ("203", "3");
INSERT INTO "driverStandings" VALUES ("204", "4");
INSERT INTO "driverStandings" VALUES ("205", "5");
INSERT INTO "driverStandings" VALUES ("206", "6");
INSERT INTO "lapTimes" VALUES ("592", "1", "1", "90000");
INSERT INTO "lapTimes" VALUES ("592", "1", "2", "89500");
INSERT INTO "lapTimes" VALUES ("592", "2", "1", "91000");
INSERT INTO "lapTimes" VALUES ("592", "3", "1", "88000");
INSERT INTO "lapTimes" VALUES ("592", "5", "1", "88500");
INSERT INTO "lapTimes" VALUES ("592", "6", "1", "92000");
INSERT INTO "lapTimes" VALUES ("592", "4", "1", "93000");