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 "matches" (
"loser_id" INT,
"tourney_date" DATE,
"winner_id" INT,
FOREIGN KEY ("loser_id") REFERENCES "players"("player_id"),
FOREIGN KEY ("winner_id") REFERENCES "players"("player_id")
);

CREATE TABLE "players" (
"player_id" INT UNIQUE,
PRIMARY KEY ("player_id")
);

CREATE TABLE "rankings" (
"ranking_date" DATE,
"player_id" INT,
"tours" INT,
FOREIGN KEY ("player_id") REFERENCES "players"("player_id")
);





INSERT INTO "players" VALUES ("1");
INSERT INTO "players" VALUES ("2");
INSERT INTO "players" VALUES ("3");
INSERT INTO "players" VALUES ("4");
INSERT INTO "players" VALUES ("5");
INSERT INTO "players" VALUES ("6");
INSERT INTO "players" VALUES ("7");
INSERT INTO "players" VALUES ("8");
INSERT INTO "players" VALUES ("9");
INSERT INTO "players" VALUES ("10");
INSERT INTO "matches" VALUES ("2", "2023-01-10", "1");
INSERT INTO "matches" VALUES ("3", "2023-01-10", "4");
INSERT INTO "matches" VALUES ("5", "2023-01-15", "6");
INSERT INTO "matches" VALUES ("7", "2023-01-15", "8");
INSERT INTO "matches" VALUES ("1", "2023-01-20", "9");
INSERT INTO "matches" VALUES ("4", "2023-01-20", "10");
INSERT INTO "matches" VALUES ("6", "2023-01-25", "3");
INSERT INTO "matches" VALUES ("8", "2023-01-25", "2");
INSERT INTO "matches" VALUES ("9", "2023-01-30", "5");
INSERT INTO "matches" VALUES ("10", "2023-01-30", "7");
INSERT INTO "rankings" VALUES ("2023-01-10", "1", "5");
INSERT INTO "rankings" VALUES ("2023-01-10", "2", "3");
INSERT INTO "rankings" VALUES ("2023-01-10", "3", "4");
INSERT INTO "rankings" VALUES ("2023-01-10", "4", "2");
INSERT INTO "rankings" VALUES ("2023-01-15", "5", "6");
INSERT INTO "rankings" VALUES ("2023-01-15", "6", "7");
INSERT INTO "rankings" VALUES ("2023-01-15", "7", "1");
INSERT INTO "rankings" VALUES ("2023-01-15", "8", "3");
INSERT INTO "rankings" VALUES ("2023-01-20", "1", "4");
INSERT INTO "rankings" VALUES ("2023-01-20", "4", "5");
INSERT INTO "rankings" VALUES ("2023-01-20", "9", "2");
INSERT INTO "rankings" VALUES ("2023-01-20", "10", "3");
INSERT INTO "rankings" VALUES ("2023-01-25", "2", "6");
INSERT INTO "rankings" VALUES ("2023-01-25", "3", "5");
INSERT INTO "rankings" VALUES ("2023-01-25", "6", "4");
INSERT INTO "rankings" VALUES ("2023-01-25", "8", "2");
INSERT INTO "rankings" VALUES ("2023-01-30", "5", "7");
INSERT INTO "rankings" VALUES ("2023-01-30", "7", "3");
INSERT INTO "rankings" VALUES ("2023-01-30", "9", "1");
INSERT INTO "rankings" VALUES ("2023-01-30", "10", "4");