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 "circuits" (
"circuitId" INT UNIQUE,
"name" TEXT,
PRIMARY KEY ("circuitId")
);

CREATE TABLE "drivers" (
"driverId" INT,
"forename" TEXT,
PRIMARY KEY ("driverId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"circuitId" INT,
"name" TEXT,
"date" DATE,
"url" TEXT,
PRIMARY KEY ("raceId"),
FOREIGN KEY ("year") REFERENCES "seasons"("year"),
FOREIGN KEY ("circuitId") REFERENCES "circuits"("circuitId")
);

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

CREATE TABLE "seasons" (
"year" INT,
"url" TEXT,
PRIMARY KEY ("year")
);



INSERT INTO "circuits" VALUES ("1", "Silverstone Circuit");
INSERT INTO "circuits" VALUES ("2", "Monza");
INSERT INTO "circuits" VALUES ("3", "Circuit de Monaco");
INSERT INTO "circuits" VALUES ("4", "Circuit de Spa-Francorchamps");
INSERT INTO "circuits" VALUES ("5", "Suzuka Circuit");
INSERT INTO "drivers" VALUES ("1", "Lewis");
INSERT INTO "drivers" VALUES ("2", "Max");
INSERT INTO "drivers" VALUES ("3", "Charles");
INSERT INTO "drivers" VALUES ("4", "Fernando");
INSERT INTO "drivers" VALUES ("5", "Sebastian");
INSERT INTO "seasons" VALUES ("2021", "http://example.com/2021_season");
INSERT INTO "seasons" VALUES ("2022", "http://example.com/2022_season");
INSERT INTO "seasons" VALUES ("2023", "http://example.com/2023_season");
INSERT INTO "races" VALUES ("1001", "2021", "1", "British Grand Prix", "2021-07-18", "http://example.com/2021_british_gp");
INSERT INTO "races" VALUES ("1002", "2021", "2", "Italian Grand Prix", "2021-09-12", "http://example.com/2021_italian_gp");
INSERT INTO "races" VALUES ("1003", "2022", "1", "British Grand Prix", "2022-07-03", "http://example.com/2022_british_gp");
INSERT INTO "races" VALUES ("1004", "2022", "3", "Monaco Grand Prix", "2022-05-29", "http://example.com/2022_monaco_gp");
INSERT INTO "races" VALUES ("1005", "2023", "1", "British Grand Prix", "2023-07-09", "http://example.com/2023_british_gp");
INSERT INTO "races" VALUES ("1006", "2023", "4", "Belgian Grand Prix", "2023-07-30", "http://example.com/2023_belgian_gp");
INSERT INTO "races" VALUES ("1007", "2023", "5", "Japanese Grand Prix", "2023-09-24", "http://example.com/2023_japanese_gp");
INSERT INTO "results" VALUES ("1", "1");
INSERT INTO "results" VALUES ("2", "2");
INSERT INTO "results" VALUES ("3", "3");
INSERT INTO "results" VALUES ("4", "4");
INSERT INTO "results" VALUES ("5", "5");