-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.sql
192 lines (191 loc) · 5.82 KB
/
stats.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
PRAGMA foreign_keys = ON;
-- Schema: stats
-- stats
ATTACH "stats.sdb" AS "stats";
BEGIN;
CREATE TABLE "stats"."player"(
"id" TEXT PRIMARY KEY NOT NULL
);
CREATE TABLE "stats"."team"(
"id" TEXT PRIMARY KEY NOT NULL,
"captain" TEXT,
"co-captain" TEXT,
"color" TEXT NOT NULL,
CONSTRAINT "fk_team_player1"
FOREIGN KEY("captain")
REFERENCES "player"("id"),
CONSTRAINT "fk_team_player2"
FOREIGN KEY("co-captain")
REFERENCES "player"("id")
);
CREATE INDEX "stats"."team.fk_team_player1_idx" ON "team" ("captain");
CREATE INDEX "stats"."team.fk_team_player2_idx" ON "team" ("co-captain");
CREATE TABLE "stats"."match"(
"id" INTEGER PRIMARY KEY NOT NULL,
"team1" TEXT NOT NULL,
"team2" TEXT NOT NULL,
"year" INTEGER NOT NULL,
"season" REAL NOT NULL,
"week" INTEGER NOT NULL,
"game" INTEGER NOT NULL,
"rink" TEXT,
"date" TEXT,
"time" TEXT,
CONSTRAINT "fk_game_team1"
FOREIGN KEY("team1")
REFERENCES "team"("id"),
CONSTRAINT "fk_game_team2"
FOREIGN KEY("team2")
REFERENCES "team"("id")
);
CREATE INDEX "stats"."match.fk_game_team1_idx" ON "match" ("team1");
CREATE INDEX "stats"."match.fk_game_team2_idx" ON "match" ("team2");
CREATE TABLE "stats"."shot"(
"id" INTEGER PRIMARY KEY NOT NULL,
"match" INTEGER NOT NULL,
"team" TEXT NOT NULL,
"goalie" TEXT,
"period" INTEGER,
"SH" INTEGER DEFAULT 0,
CONSTRAINT "fk_shots_player1"
FOREIGN KEY("goalie")
REFERENCES "player"("id"),
CONSTRAINT "fk_shots_game1"
FOREIGN KEY("match")
REFERENCES "match"("id"),
CONSTRAINT "fk_shots_team1"
FOREIGN KEY("team")
REFERENCES "team"("id")
);
CREATE INDEX "stats"."shot.fk_shots_player1_idx" ON "shot" ("goalie");
CREATE INDEX "stats"."shot.fk_shots_game1_idx" ON "shot" ("match");
CREATE INDEX "stats"."shot.fk_shots_team1_idx" ON "shot" ("team");
CREATE TABLE "stats"."point"(
"id" INTEGER PRIMARY KEY NOT NULL,
"match" INTEGER NOT NULL,
"team" TEXT NOT NULL,
"period" INTEGER,
"time" TEXT,
"shooter" TEXT NOT NULL,
"assist1" TEXT,
"assist2" TEXT,
"goalie" TEXT,
"EV" INTEGER NOT NULL,
"PP" INTEGER NOT NULL,
"SH" INTEGER NOT NULL,
"EN" INTEGER NOT NULL,
CONSTRAINT "fk_scoring_game1"
FOREIGN KEY("match")
REFERENCES "match"("id"),
CONSTRAINT "fk_scoring_team1"
FOREIGN KEY("team")
REFERENCES "team"("id"),
CONSTRAINT "fk_scoring_player1"
FOREIGN KEY("shooter")
REFERENCES "player"("id"),
CONSTRAINT "fk_scoring_player2"
FOREIGN KEY("assist1")
REFERENCES "player"("id"),
CONSTRAINT "fk_scoring_player3"
FOREIGN KEY("assist2")
REFERENCES "player"("id"),
CONSTRAINT "fk_scoring_player4"
FOREIGN KEY("goalie")
REFERENCES "player"("id")
);
CREATE INDEX "stats"."point.fk_scoring_game1_idx" ON "point" ("match");
CREATE INDEX "stats"."point.fk_scoring_team1_idx" ON "point" ("team");
CREATE INDEX "stats"."point.fk_scoring_player1_idx" ON "point" ("shooter");
CREATE INDEX "stats"."point.fk_scoring_player2_idx" ON "point" ("assist1");
CREATE INDEX "stats"."point.fk_scoring_player3_idx" ON "point" ("assist2");
CREATE INDEX "stats"."point.fk_scoring_player4_idx" ON "point" ("goalie");
CREATE TABLE "stats"."roster"(
"team" TEXT NOT NULL,
"player" TEXT NOT NULL,
PRIMARY KEY("team","player"),
CONSTRAINT "fk_team_has_player_team1"
FOREIGN KEY("team")
REFERENCES "team"("id"),
CONSTRAINT "fk_team_has_player_player1"
FOREIGN KEY("player")
REFERENCES "player"("id")
);
CREATE INDEX "stats"."roster.fk_team_has_player_player1_idx" ON "roster" ("player");
CREATE INDEX "stats"."roster.fk_team_has_player_team1_idx" ON "roster" ("team");
CREATE TABLE "stats"."penalty"(
"id" INTEGER PRIMARY KEY NOT NULL,
"match" INTEGER NOT NULL,
"team" TEXT NOT NULL,
"period" INTEGER,
"time" TEXT,
"player" TEXT,
"server" TEXT,
"call" TEXT,
"duration" INTEGER NOT NULL,
"goalie" TEXT,
"scored" INTEGER,
CONSTRAINT "fk_penalty_game1"
FOREIGN KEY("match")
REFERENCES "match"("id"),
CONSTRAINT "fk_penalty_team1"
FOREIGN KEY("team")
REFERENCES "team"("id"),
CONSTRAINT "fk_penalty_player1"
FOREIGN KEY("player")
REFERENCES "player"("id"),
CONSTRAINT "fk_penalty_player2"
FOREIGN KEY("server")
REFERENCES "player"("id"),
CONSTRAINT "fk_penalty_player3"
FOREIGN KEY("goalie")
REFERENCES "player"("id")
);
CREATE INDEX "stats"."penalty.fk_penalty_game1_idx" ON "penalty" ("match");
CREATE INDEX "stats"."penalty.fk_penalty_team1_idx" ON "penalty" ("team");
CREATE INDEX "stats"."penalty.fk_penalty_player1_idx" ON "penalty" ("player");
CREATE INDEX "stats"."penalty.fk_penalty_player2_idx" ON "penalty" ("server");
CREATE INDEX "stats"."penalty.fk_penalty_player3_idx" ON "penalty" ("goalie");
CREATE TABLE "stats"."meta"(
"id" INTEGER PRIMARY KEY NOT NULL,
"match" INTEGER,
"period" INTEGER,
"time" TEXT,
"note" TEXT NOT NULL,
"subject" TEXT,
"verb" TEXT,
"object" TEXT,
CONSTRAINT "fk_table1_game1"
FOREIGN KEY("match")
REFERENCES "match"("id")
);
CREATE INDEX "stats"."meta.fk_table1_game1_idx" ON "meta" ("match");
CREATE TABLE "stats"."lstat"(
"id" INTEGER PRIMARY KEY NOT NULL,
"team" TEXT NOT NULL,
"player" TEXT NOT NULL,
"year" INTEGER NOT NULL,
"season" INTEGER NOT NULL,
"G" INTEGER DEFAULT 0,
"A" INTEGER DEFAULT 0,
"PIM" INTEGER DEFAULT 0,
"PPG" INTEGER DEFAULT 0,
"PPA" INTEGER DEFAULT 0,
"SHG" INTEGER DEFAULT 0,
"SHA" INTEGER DEFAULT 0,
"GWG" INTEGER DEFAULT 0,
"W" INTEGER DEFAULT 0,
"L" INTEGER DEFAULT 0,
"OTL" INTEGER DEFAULT 0,
"SH" INTEGER DEFAULT 0,
"GA" INTEGER DEFAULT 0,
"SHO" INTEGER DEFAULT 0,
CONSTRAINT "fk_lstats_team1"
FOREIGN KEY("team")
REFERENCES "team"("id"),
CONSTRAINT "fk_lstats_player1"
FOREIGN KEY("player")
REFERENCES "player"("id")
);
CREATE INDEX "stats"."lstat.fk_lstats_team1_idx" ON "lstat" ("team");
CREATE INDEX "stats"."lstat.fk_lstats_player1_idx" ON "lstat" ("player");
COMMIT;