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,
"location" TEXT,
"country" TEXT,
PRIMARY KEY ("circuitId")
);

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

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



INSERT INTO "circuits" VALUES ("1", "Shanghai", "China");
INSERT INTO "circuits" VALUES ("2", "Monaco", "Monaco");
INSERT INTO "circuits" VALUES ("3", "Silverstone", "United Kingdom");
INSERT INTO "circuits" VALUES ("4", "Suzuka", "Japan");
INSERT INTO "circuits" VALUES ("5", "Shanghai", "China");
INSERT INTO "seasons" VALUES ("2018");
INSERT INTO "seasons" VALUES ("2019");
INSERT INTO "seasons" VALUES ("2020");
INSERT INTO "seasons" VALUES ("2021");
INSERT INTO "seasons" VALUES ("2022");
INSERT INTO "races" VALUES ("101", "2018", "1", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("102", "2019", "1", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("103", "2020", "2", "Monaco Grand Prix");
INSERT INTO "races" VALUES ("104", "2021", "3", "British Grand Prix");
INSERT INTO "races" VALUES ("105", "2022", "4", "Japanese Grand Prix");
INSERT INTO "races" VALUES ("106", "2022", "5", "Shanghai Night Race");