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

CREATE TABLE "League" (
"id" INT UNIQUE,
"country_id" INT,
PRIMARY KEY ("id")
);

CREATE TABLE "Match" (
"id" INT,
"country_id" INT,
"league_id" INT,
"date" TEXT,
"home_team_api_id" INT,
"away_team_api_id" INT,
"home_team_goal" INT,
"away_team_goal" INT,
PRIMARY KEY ("id"),
FOREIGN KEY ("away_team_api_id") REFERENCES "Team"("team_api_id"),
FOREIGN KEY ("home_team_api_id") REFERENCES "Team"("team_api_id"),
FOREIGN KEY ("league_id") REFERENCES "League"("id"),
FOREIGN KEY ("country_id") REFERENCES "Country"("id")
);

CREATE TABLE "Team" (
"id" INT,
"team_api_id" INT UNIQUE,
"team_long_name" TEXT,
PRIMARY KEY ("id")
);



INSERT INTO "Country" VALUES ("1", "Italy");
INSERT INTO "Country" VALUES ("2", "Spain");
INSERT INTO "Country" VALUES ("3", "England");
INSERT INTO "League" VALUES ("1001", "1");
INSERT INTO "League" VALUES ("1002", "2");
INSERT INTO "League" VALUES ("1003", "1");
INSERT INTO "League" VALUES ("1004", "3");
INSERT INTO "Team" VALUES ("1", "100", "Parma");
INSERT INTO "Team" VALUES ("2", "101", "Juventus");
INSERT INTO "Team" VALUES ("3", "102", "AC Milan");
INSERT INTO "Team" VALUES ("4", "103", "Inter Milan");
INSERT INTO "Team" VALUES ("5", "104", "Real Madrid");
INSERT INTO "Team" VALUES ("6", "105", "Barcelona");
INSERT INTO "Team" VALUES ("7", "106", "Napoli");
INSERT INTO "Team" VALUES ("8", "107", "Roma");
INSERT INTO "Match" VALUES ("1", "1", "1001", "2015-01-10", "101", "100", "2", "1");
INSERT INTO "Match" VALUES ("2", "1", "1001", "2015-01-17", "102", "100", "0", "0");
INSERT INTO "Match" VALUES ("3", "1", "1001", "2015-01-24", "103", "100", "3", "2");
INSERT INTO "Match" VALUES ("4", "1", "1001", "2015-02-01", "100", "101", "1", "1");
INSERT INTO "Match" VALUES ("5", "2", "1002", "2015-01-10", "104", "105", "2", "1");
INSERT INTO "Match" VALUES ("6", "1", "1003", "2015-03-01", "106", "100", "1", "3");
INSERT INTO "Match" VALUES ("7", "1", "1001", "2015-03-08", "107", "100", "0", "2");
INSERT INTO "Match" VALUES ("8", "1", "1001", "2015-03-15", "101", "100", "4", "0");
INSERT INTO "Match" VALUES ("9", "3", "1004", "2015-04-01", "100", "102", "1", "0");
INSERT INTO "Match" VALUES ("10", "1", "1001", "2015-04-08", "102", "100", "1", "1");