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,
PRIMARY KEY ("raceId", "driverId", "lap")
);

CREATE TABLE "pitStops" (
"raceId" INT,
"driverId" INT,
"stop" INT,
"time" TEXT,
PRIMARY KEY ("raceId", "driverId", "stop")
);

CREATE TABLE "qualifying" (
"qualifyId" INT,
"q1" TEXT,
PRIMARY KEY ("qualifyId")
);

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

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

CREATE TABLE "status" (
"statusId" INT UNIQUE,
"status" TEXT,
PRIMARY KEY ("statusId")
);



INSERT INTO "races" VALUES ("50");
INSERT INTO "races" VALUES ("51");
INSERT INTO "races" VALUES ("75");
INSERT INTO "races" VALUES ("99");
INSERT INTO "races" VALUES ("100");
INSERT INTO "races" VALUES ("101");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Disqualified");
INSERT INTO "status" VALUES ("3", "Accident");
INSERT INTO "status" VALUES ("4", "Engine");
INSERT INTO "results" VALUES ("1", "50", "1:20:00.000", "1");
INSERT INTO "results" VALUES ("2", "50", "1:20:05.000", "2");
INSERT INTO "results" VALUES ("3", "50", "null", "3");
INSERT INTO "results" VALUES ("4", "51", "1:25:00.000", "1");
INSERT INTO "results" VALUES ("5", "51", "1:25:10.000", "2");
INSERT INTO "results" VALUES ("6", "75", "1:30:00.000", "1");
INSERT INTO "results" VALUES ("7", "75", "1:30:02.000", "2");
INSERT INTO "results" VALUES ("8", "75", "1:30:05.000", "2");
INSERT INTO "results" VALUES ("9", "99", "1:15:00.000", "1");
INSERT INTO "results" VALUES ("10", "99", "1:15:01.000", "2");
INSERT INTO "results" VALUES ("11", "100", "1:22:00.000", "1");
INSERT INTO "results" VALUES ("12", "100", "null", "2");
INSERT INTO "results" VALUES ("13", "101", "1:23:00.000", "2");
INSERT INTO "results" VALUES ("14", "50", "1:20:10.000", "1");
INSERT INTO "results" VALUES ("15", "75", "null", "4");
INSERT INTO "results" VALUES ("16", "99", "1:15:05.000", "1");
INSERT INTO "results" VALUES ("17", "99", "1:15:08.000", "2");
INSERT INTO "results" VALUES ("18", "51", "null", "1");