sportdb-models 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +22 -20
- data/Manifest.txt +0 -4
- data/README.md +28 -31
- data/Rakefile +32 -32
- data/lib/sportdb/models/formats.rb +23 -23
- data/lib/sportdb/models/models/assoc.rb +38 -38
- data/lib/sportdb/models/models/badge.rb +14 -14
- data/lib/sportdb/models/models/forward.rb +55 -55
- data/lib/sportdb/models/models/goal.rb +15 -15
- data/lib/sportdb/models/models/league.rb +20 -20
- data/lib/sportdb/models/models/lineup.rb +20 -17
- data/lib/sportdb/models/models/person.rb +21 -21
- data/lib/sportdb/models/models/season.rb +15 -15
- data/lib/sportdb/models/models/stats/event_standing.rb +31 -31
- data/lib/sportdb/models/models/team.rb +3 -2
- data/lib/sportdb/models/models/world/continent.rb +20 -20
- data/lib/sportdb/models/models/world/state.rb +19 -19
- data/lib/sportdb/models/schema.rb +471 -466
- data/lib/sportdb/models/version.rb +26 -27
- data/lib/sportdb/models.rb +240 -212
- metadata +8 -13
- data/test/helper.rb +0 -46
- data/test/test_changes.rb +0 -78
- data/test/test_cursor.rb +0 -55
- data/test/test_winner.rb +0 -100
@@ -1,466 +1,471 @@
|
|
1
|
-
|
2
|
-
module SportDb
|
3
|
-
|
4
|
-
class CreateDb
|
5
|
-
|
6
|
-
def up
|
7
|
-
ActiveRecord::Schema.define do
|
8
|
-
|
9
|
-
create_table :teams do |t|
|
10
|
-
t.string :key, null: false # import/export key
|
11
|
-
t.string :name, null: false # "canonical" unique name
|
12
|
-
|
13
|
-
t.string :code # three letter code (short name)
|
14
|
-
t.string :alt_names # comma separated list of alt names / synonyms
|
15
|
-
|
16
|
-
t.references :country, null: false, index: false
|
17
|
-
t.references :city, index: false # note: city is optional (should be required for clubs e.g. non-national teams)
|
18
|
-
t.references :district, index: false # note: optional district (in city)
|
19
|
-
|
20
|
-
## todo/check/fix: use team type or such e.g. club/national/etc. - why? why not?
|
21
|
-
### or remove and add virtual attribute in model instead - why? why not?
|
22
|
-
t.boolean :club, null: false, default: false # is it a club (not a national team)?
|
23
|
-
t.boolean :national, null: false, default: false # is it a national selection team (not a club)?
|
24
|
-
|
25
|
-
## todo/fix: add team reference for a and b team!!!!
|
26
|
-
|
27
|
-
|
28
|
-
t.integer :start_year # founding year -fix change to start_year / founded - why? why not?
|
29
|
-
t.integer :end_year
|
30
|
-
## add more? - start_year2, end_year2 - why? why not?
|
31
|
-
# e.g. founded = 1946, 2013 (refounded)
|
32
|
-
# dissolved = 1997
|
33
|
-
|
34
|
-
t.string :address
|
35
|
-
t.string :web
|
36
|
-
|
37
|
-
## todo/fix: change to gov / governing body or such!!!
|
38
|
-
t.references :assoc, index: false # optional: national football assoc(iation), for example - used for national teams
|
39
|
-
|
40
|
-
t.string :comments
|
41
|
-
|
42
|
-
t.timestamps
|
43
|
-
end
|
44
|
-
|
45
|
-
add_index :teams, :key, unique: true
|
46
|
-
|
47
|
-
|
48
|
-
###########
|
49
|
-
# check: use table (rename to) venues / stadiums - why? why not?
|
50
|
-
create_table :grounds do |t|
|
51
|
-
t.string :key, null: false # import/export key
|
52
|
-
t.string :name, null: false
|
53
|
-
t.string :alt_names # comma separated list of alt_names / synonyms
|
54
|
-
|
55
|
-
t.references :country, null: false, index: false
|
56
|
-
t.references :city, index: false # todo: make city required ???
|
57
|
-
t.references :district, index: false # note: optional district (in city)
|
58
|
-
|
59
|
-
t.integer :start_year # founding year
|
60
|
-
t.integer :capacity # attentence capacity e.g. 10_000 or 50_000 etc.
|
61
|
-
t.string :address
|
62
|
-
|
63
|
-
### fix/todo: add since/founded/opened/build attrib eg. 2011 or 1987
|
64
|
-
## - add capacity e.g. 40_000
|
65
|
-
## fix: add address !!!! etc
|
66
|
-
|
67
|
-
## add region ??? or just use region from city ??
|
68
|
-
|
69
|
-
t.timestamps
|
70
|
-
end
|
71
|
-
|
72
|
-
add_index :grounds, :key, unique: true
|
73
|
-
|
74
|
-
|
75
|
-
# join table: person+match(team1+team2+event(season+league))
|
76
|
-
create_table :goals do |t|
|
77
|
-
t.references :person, null: false, index: false
|
78
|
-
t.references :match, null: false, index: false
|
79
|
-
t.references :team, null: false, index: false ## use integer instead w/ values 1 or 2 for team1 or team2 ?? why? why not?
|
80
|
-
|
81
|
-
t.integer :minute
|
82
|
-
t.integer :offset, null: false, default: 0 # e.g. 45' +3 or 90' +2
|
83
|
-
|
84
|
-
t.integer :score1
|
85
|
-
t.integer :score2
|
86
|
-
|
87
|
-
## type of goal (penalty, owngoal)
|
88
|
-
t.boolean :penalty, null: false, default: false
|
89
|
-
t.boolean :owngoal, null: false, default: false # de: Eigentor -> # todo: find better name?
|
90
|
-
|
91
|
-
t.timestamps
|
92
|
-
end
|
93
|
-
|
94
|
-
|
95
|
-
# join table -> person+team+event(season+league)
|
96
|
-
create_table :lineups do |t| # use squads as an alternative name? why? why not??
|
97
|
-
t.references :person, null: false, index: false
|
98
|
-
t.references :team, null: false, index: false
|
99
|
-
t.references :event , index: false # make required?
|
100
|
-
t.integer :num, # optional - jersey (t-shirt) number
|
101
|
-
|
102
|
-
t.timestamps
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
create_table :events do |t|
|
107
|
-
t.string :key, null: false # import/export key
|
108
|
-
t.references :league, null: false, index: false
|
109
|
-
t.references :season, null: false, index: false
|
110
|
-
t.date :start_date, null: false # note: only use date (w/o time)
|
111
|
-
t.date :end_date # note: only use date (w/o time)
|
112
|
-
|
113
|
-
t.integer :num ## optional series counter e.g. World Cup No. 2, Bundesliga No. 43 etc. etc.
|
114
|
-
|
115
|
-
## t.boolean :team3, null: false, default: true ## e.g. Champions League has no 3rd place (only 1st and 2nd/final)
|
116
|
-
## todo: add league/cup flag/flags or to league itself?
|
117
|
-
## or add add a tournament type field - why? why not?
|
118
|
-
|
119
|
-
## auto-added flag (e.g. start_at n end_at dates got calculated)
|
120
|
-
## if auto-added flag is false - do NOT auto-update start_at, end_at etc.
|
121
|
-
t.boolean :auto, null: false, default: true
|
122
|
-
|
123
|
-
|
124
|
-
#### track 1-n sources (from repos) - # todo move to its own table later
|
125
|
-
## NB: relative to event.yml - use mapper to "resolve" to full path w/ repo; use league+season keys
|
126
|
-
# t.string :sources # e.g. cup or bl,bl_ii # NB: for now store all in on string separated by comma
|
127
|
-
# t.string :config # e.g. cup or bl # e.g assumes cup.yml, bl.yml etc. for now
|
128
|
-
|
129
|
-
|
130
|
-
t.timestamps
|
131
|
-
end
|
132
|
-
|
133
|
-
add_index :events, :key, unique: true
|
134
|
-
|
135
|
-
|
136
|
-
create_table :rounds do |t|
|
137
|
-
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
138
|
-
t.string :name, null: false
|
139
|
-
t.integer :pos, null: false ## use only for "internal" sort order (defaults to insertion order)
|
140
|
-
|
141
|
-
t.integer :num ## optional match day/week number
|
142
|
-
t.string :key ## optional match day/week number key (as string)
|
143
|
-
|
144
|
-
## add new table stage/stages for grouping rounds in group rounds and playoff rounds, for example???
|
145
|
-
## # "regular" season (group) matches or post-season (playoff) knockouts (k.o's)
|
146
|
-
t.boolean :knockout, null: false, default: false
|
147
|
-
## todo: add leg (e.g. leg1, leg2, etc. why? why not?)
|
148
|
-
t.date :start_date # note: only use date (w/o time) - fix: change to start_date!!!
|
149
|
-
t.date :end_date # note: only use date (w/o time) - fix: change to end_date!!!
|
150
|
-
t.date :start_date2 # note: only use date (w/o time) - fix: change to start_date!!!
|
151
|
-
t.date :end_date2 # note: only use date (w/o time) - fix: change to end_date!!!
|
152
|
-
|
153
|
-
## add last_date/first-date(auto) - for "real" last and first dates - auto-added - why? why not?
|
154
|
-
|
155
|
-
## auto-added flag (e.g. start_at n end_at dates got calculated)
|
156
|
-
## if auto-added flag is false - do NOT auto-update start_at, end_at etc.
|
157
|
-
t.boolean :auto, null: false, default: true
|
158
|
-
|
159
|
-
t.timestamps
|
160
|
-
end
|
161
|
-
|
162
|
-
add_index :rounds, :event_id # fk event_id index
|
163
|
-
|
164
|
-
|
165
|
-
create_table :groups do |t| # Teamgruppe (zB Gruppe A, Gruppe B, etc.)
|
166
|
-
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
167
|
-
t.string :name, null: false
|
168
|
-
t.integer :pos, null: false ## use only for "internal" sort order (defaults to insertion order)
|
169
|
-
|
170
|
-
t.string :key ## optional group key e.g. A, B, C or 1, 2, etc. - use why? why not?
|
171
|
-
t.timestamps
|
172
|
-
end
|
173
|
-
|
174
|
-
add_index :groups, :event_id # fk event_id index
|
175
|
-
|
176
|
-
|
177
|
-
create_table :stages do |t| # e.g. regular season, champions round, etc.
|
178
|
-
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
179
|
-
t.string :name, null: false
|
180
|
-
## todo/check: add pos for use only for "internal" sort order (defaults to insertion order)??
|
181
|
-
t.timestamps
|
182
|
-
end
|
183
|
-
|
184
|
-
add_index :stages, :event_id # fk event_id index
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
create_table :matches do |t|
|
189
|
-
t.string :key # import/export key
|
190
|
-
t.references :event, null: false, index: false
|
191
|
-
t.integer :pos, null: false ## note: use only for "internal" sort order (defaults to insertion order)
|
192
|
-
t.integer :num ## optional - "event global" match number e.g. World Cup - Match 1, Match 2, etc.
|
193
|
-
t.references :team1, null: false, index: false ## Note: do NOT auto-add index
|
194
|
-
t.references :team2, null: false, index: false ## Note: do NOT auto-add index
|
195
|
-
|
196
|
-
t.references :round, index: false ## Note: do NOT auto-add index
|
197
|
-
t.references :group, index: false ## Note: do NOT auto-add index -- group is optional
|
198
|
-
t.references :stage, index: false # optional - regular seasion / champions round etc.
|
199
|
-
|
200
|
-
## "inline" helper keys auto-populate for easier "no-join/single-table" queries
|
201
|
-
t.string :team1_key
|
202
|
-
t.string :team2_key
|
203
|
-
t.string :event_key
|
204
|
-
t.string :round_key
|
205
|
-
t.integer :round_num ## e.g. 1,2,3 for match day/match week
|
206
|
-
t.string :group_key
|
207
|
-
t.string :stage_key
|
208
|
-
|
209
|
-
|
210
|
-
t.date :date # optional play date - todo/fix: split into play_date AND play_time!!!
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
## t.
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
t.
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
t.
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
t.
|
231
|
-
t.
|
232
|
-
|
233
|
-
t.integer :
|
234
|
-
t.integer :
|
235
|
-
t.integer :
|
236
|
-
t.integer :
|
237
|
-
t.integer :
|
238
|
-
t.
|
239
|
-
t.
|
240
|
-
|
241
|
-
t.integer :
|
242
|
-
t.integer :
|
243
|
-
|
244
|
-
t.
|
245
|
-
|
246
|
-
t.
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
add_index :matches, :
|
255
|
-
add_index :matches, :
|
256
|
-
add_index :matches, :
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
t.
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
t.
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
t.
|
330
|
-
t.
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
t.
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
t.
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
t.
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
t.
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
t.boolean
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
t.
|
405
|
-
t.
|
406
|
-
t.integer :
|
407
|
-
t.integer :
|
408
|
-
t.integer :
|
409
|
-
t.
|
410
|
-
t.
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
t.
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
create_table :
|
420
|
-
t.references :
|
421
|
-
t.
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
t.
|
426
|
-
t.
|
427
|
-
t.integer :
|
428
|
-
t.integer :
|
429
|
-
t.integer :
|
430
|
-
t.
|
431
|
-
t.
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
t.
|
445
|
-
t.
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
t.
|
450
|
-
t.
|
451
|
-
t.integer :
|
452
|
-
t.integer :
|
453
|
-
t.integer :
|
454
|
-
t.integer :
|
455
|
-
t.
|
456
|
-
t.
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
end #
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
|
4
|
+
class CreateDb
|
5
|
+
|
6
|
+
def up
|
7
|
+
ActiveRecord::Schema.define do
|
8
|
+
|
9
|
+
create_table :teams do |t|
|
10
|
+
t.string :key, null: false # import/export key
|
11
|
+
t.string :name, null: false # "canonical" unique name
|
12
|
+
|
13
|
+
t.string :code # three letter code (short name)
|
14
|
+
t.string :alt_names # comma separated list of alt names / synonyms
|
15
|
+
|
16
|
+
t.references :country, null: false, index: false
|
17
|
+
t.references :city, index: false # note: city is optional (should be required for clubs e.g. non-national teams)
|
18
|
+
t.references :district, index: false # note: optional district (in city)
|
19
|
+
|
20
|
+
## todo/check/fix: use team type or such e.g. club/national/etc. - why? why not?
|
21
|
+
### or remove and add virtual attribute in model instead - why? why not?
|
22
|
+
t.boolean :club, null: false, default: false # is it a club (not a national team)?
|
23
|
+
t.boolean :national, null: false, default: false # is it a national selection team (not a club)?
|
24
|
+
|
25
|
+
## todo/fix: add team reference for a and b team!!!!
|
26
|
+
|
27
|
+
|
28
|
+
t.integer :start_year # founding year -fix change to start_year / founded - why? why not?
|
29
|
+
t.integer :end_year
|
30
|
+
## add more? - start_year2, end_year2 - why? why not?
|
31
|
+
# e.g. founded = 1946, 2013 (refounded)
|
32
|
+
# dissolved = 1997
|
33
|
+
|
34
|
+
t.string :address
|
35
|
+
t.string :web
|
36
|
+
|
37
|
+
## todo/fix: change to gov / governing body or such!!!
|
38
|
+
t.references :assoc, index: false # optional: national football assoc(iation), for example - used for national teams
|
39
|
+
|
40
|
+
t.string :comments
|
41
|
+
|
42
|
+
t.timestamps
|
43
|
+
end
|
44
|
+
|
45
|
+
add_index :teams, :key, unique: true
|
46
|
+
|
47
|
+
|
48
|
+
###########
|
49
|
+
# check: use table (rename to) venues / stadiums - why? why not?
|
50
|
+
create_table :grounds do |t|
|
51
|
+
t.string :key, null: false # import/export key
|
52
|
+
t.string :name, null: false
|
53
|
+
t.string :alt_names # comma separated list of alt_names / synonyms
|
54
|
+
|
55
|
+
t.references :country, null: false, index: false
|
56
|
+
t.references :city, index: false # todo: make city required ???
|
57
|
+
t.references :district, index: false # note: optional district (in city)
|
58
|
+
|
59
|
+
t.integer :start_year # founding year
|
60
|
+
t.integer :capacity # attentence capacity e.g. 10_000 or 50_000 etc.
|
61
|
+
t.string :address
|
62
|
+
|
63
|
+
### fix/todo: add since/founded/opened/build attrib eg. 2011 or 1987
|
64
|
+
## - add capacity e.g. 40_000
|
65
|
+
## fix: add address !!!! etc
|
66
|
+
|
67
|
+
## add region ??? or just use region from city ??
|
68
|
+
|
69
|
+
t.timestamps
|
70
|
+
end
|
71
|
+
|
72
|
+
add_index :grounds, :key, unique: true
|
73
|
+
|
74
|
+
|
75
|
+
# join table: person+match(team1+team2+event(season+league))
|
76
|
+
create_table :goals do |t|
|
77
|
+
t.references :person, null: false, index: false
|
78
|
+
t.references :match, null: false, index: false
|
79
|
+
t.references :team, null: false, index: false ## use integer instead w/ values 1 or 2 for team1 or team2 ?? why? why not?
|
80
|
+
|
81
|
+
t.integer :minute
|
82
|
+
t.integer :offset, null: false, default: 0 # e.g. 45' +3 or 90' +2
|
83
|
+
|
84
|
+
t.integer :score1
|
85
|
+
t.integer :score2
|
86
|
+
|
87
|
+
## type of goal (penalty, owngoal)
|
88
|
+
t.boolean :penalty, null: false, default: false
|
89
|
+
t.boolean :owngoal, null: false, default: false # de: Eigentor -> # todo: find better name?
|
90
|
+
|
91
|
+
t.timestamps
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# join table -> person+team+event(season+league)
|
96
|
+
create_table :lineups do |t| # use squads as an alternative name? why? why not??
|
97
|
+
t.references :person, null: false, index: false
|
98
|
+
t.references :team, null: false, index: false
|
99
|
+
t.references :event , index: false # make required?
|
100
|
+
t.integer :num, # optional - jersey (t-shirt) number
|
101
|
+
|
102
|
+
t.timestamps
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
create_table :events do |t|
|
107
|
+
t.string :key, null: false # import/export key
|
108
|
+
t.references :league, null: false, index: false
|
109
|
+
t.references :season, null: false, index: false
|
110
|
+
t.date :start_date, null: false # note: only use date (w/o time)
|
111
|
+
t.date :end_date # note: only use date (w/o time)
|
112
|
+
|
113
|
+
t.integer :num ## optional series counter e.g. World Cup No. 2, Bundesliga No. 43 etc. etc.
|
114
|
+
|
115
|
+
## t.boolean :team3, null: false, default: true ## e.g. Champions League has no 3rd place (only 1st and 2nd/final)
|
116
|
+
## todo: add league/cup flag/flags or to league itself?
|
117
|
+
## or add add a tournament type field - why? why not?
|
118
|
+
|
119
|
+
## auto-added flag (e.g. start_at n end_at dates got calculated)
|
120
|
+
## if auto-added flag is false - do NOT auto-update start_at, end_at etc.
|
121
|
+
t.boolean :auto, null: false, default: true
|
122
|
+
|
123
|
+
|
124
|
+
#### track 1-n sources (from repos) - # todo move to its own table later
|
125
|
+
## NB: relative to event.yml - use mapper to "resolve" to full path w/ repo; use league+season keys
|
126
|
+
# t.string :sources # e.g. cup or bl,bl_ii # NB: for now store all in on string separated by comma
|
127
|
+
# t.string :config # e.g. cup or bl # e.g assumes cup.yml, bl.yml etc. for now
|
128
|
+
|
129
|
+
|
130
|
+
t.timestamps
|
131
|
+
end
|
132
|
+
|
133
|
+
add_index :events, :key, unique: true
|
134
|
+
|
135
|
+
|
136
|
+
create_table :rounds do |t|
|
137
|
+
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
138
|
+
t.string :name, null: false
|
139
|
+
t.integer :pos, null: false ## use only for "internal" sort order (defaults to insertion order)
|
140
|
+
|
141
|
+
t.integer :num ## optional match day/week number
|
142
|
+
t.string :key ## optional match day/week number key (as string)
|
143
|
+
|
144
|
+
## add new table stage/stages for grouping rounds in group rounds and playoff rounds, for example???
|
145
|
+
## # "regular" season (group) matches or post-season (playoff) knockouts (k.o's)
|
146
|
+
t.boolean :knockout, null: false, default: false
|
147
|
+
## todo: add leg (e.g. leg1, leg2, etc. why? why not?)
|
148
|
+
t.date :start_date # note: only use date (w/o time) - fix: change to start_date!!!
|
149
|
+
t.date :end_date # note: only use date (w/o time) - fix: change to end_date!!!
|
150
|
+
t.date :start_date2 # note: only use date (w/o time) - fix: change to start_date!!!
|
151
|
+
t.date :end_date2 # note: only use date (w/o time) - fix: change to end_date!!!
|
152
|
+
|
153
|
+
## add last_date/first-date(auto) - for "real" last and first dates - auto-added - why? why not?
|
154
|
+
|
155
|
+
## auto-added flag (e.g. start_at n end_at dates got calculated)
|
156
|
+
## if auto-added flag is false - do NOT auto-update start_at, end_at etc.
|
157
|
+
t.boolean :auto, null: false, default: true
|
158
|
+
|
159
|
+
t.timestamps
|
160
|
+
end
|
161
|
+
|
162
|
+
add_index :rounds, :event_id # fk event_id index
|
163
|
+
|
164
|
+
|
165
|
+
create_table :groups do |t| # Teamgruppe (zB Gruppe A, Gruppe B, etc.)
|
166
|
+
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
167
|
+
t.string :name, null: false
|
168
|
+
t.integer :pos, null: false ## use only for "internal" sort order (defaults to insertion order)
|
169
|
+
|
170
|
+
t.string :key ## optional group key e.g. A, B, C or 1, 2, etc. - use why? why not?
|
171
|
+
t.timestamps
|
172
|
+
end
|
173
|
+
|
174
|
+
add_index :groups, :event_id # fk event_id index
|
175
|
+
|
176
|
+
|
177
|
+
create_table :stages do |t| # e.g. regular season, champions round, etc.
|
178
|
+
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
179
|
+
t.string :name, null: false
|
180
|
+
## todo/check: add pos for use only for "internal" sort order (defaults to insertion order)??
|
181
|
+
t.timestamps
|
182
|
+
end
|
183
|
+
|
184
|
+
add_index :stages, :event_id # fk event_id index
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
create_table :matches do |t|
|
189
|
+
t.string :key # import/export key
|
190
|
+
t.references :event, null: false, index: false
|
191
|
+
t.integer :pos, null: false ## note: use only for "internal" sort order (defaults to insertion order)
|
192
|
+
t.integer :num ## optional - "event global" match number e.g. World Cup - Match 1, Match 2, etc.
|
193
|
+
t.references :team1, null: false, index: false ## Note: do NOT auto-add index
|
194
|
+
t.references :team2, null: false, index: false ## Note: do NOT auto-add index
|
195
|
+
|
196
|
+
t.references :round, index: false ## Note: do NOT auto-add index
|
197
|
+
t.references :group, index: false ## Note: do NOT auto-add index -- group is optional
|
198
|
+
t.references :stage, index: false # optional - regular seasion / champions round etc.
|
199
|
+
|
200
|
+
## "inline" helper keys auto-populate for easier "no-join/single-table" queries
|
201
|
+
t.string :team1_key
|
202
|
+
t.string :team2_key
|
203
|
+
t.string :event_key
|
204
|
+
t.string :round_key
|
205
|
+
t.integer :round_num ## e.g. 1,2,3 for match day/match week
|
206
|
+
t.string :group_key
|
207
|
+
t.string :stage_key
|
208
|
+
|
209
|
+
|
210
|
+
t.date :date # optional play date - todo/fix: split into play_date AND play_time!!!
|
211
|
+
## note: activerecord(rails) will auto-add date (2000-01-01) to hours/time!!!
|
212
|
+
## work around - save a string type!!!!
|
213
|
+
## e.g. 19:00 etc.
|
214
|
+
## t.time :time
|
215
|
+
t.string :time
|
216
|
+
|
217
|
+
|
218
|
+
t.boolean :postponed, null: false, default: false
|
219
|
+
## t.date :date2 # optional old date (when postponed)
|
220
|
+
## t.date :date3 # optional old date (when postponed twice)
|
221
|
+
|
222
|
+
t.string :status ## optional match status - note: uses UPCASE string constants for now
|
223
|
+
## e.g. CANCELLED / ABANDONED / REPLAY / AWARDED / POSTPONED / etc.
|
224
|
+
|
225
|
+
|
226
|
+
t.references :ground, index: false # optional - stadium (lets you get city,region,country,etc)
|
227
|
+
t.references :city, index: false # optional - convenience for ground.city_id ???
|
228
|
+
|
229
|
+
## change home to neutral - why? why not?
|
230
|
+
t.boolean :home, null: false, default: true # is team1 play at home or neutral (that is, at its home stadium)
|
231
|
+
t.boolean :knockout, null: false, default: false
|
232
|
+
|
233
|
+
t.integer :score1
|
234
|
+
t.integer :score2
|
235
|
+
t.integer :score1et # extratime - team 1 (opt)
|
236
|
+
t.integer :score2et # extratime - team 2 (opt)
|
237
|
+
t.integer :score1p # penalty - team 1 (opt)
|
238
|
+
t.integer :score2p # penalty - team 2 (opt) elfmeter (opt)
|
239
|
+
t.integer :score1i # half time / first third (opt)
|
240
|
+
t.integer :score2i # half time - team 2
|
241
|
+
t.integer :score1ii # second third (opt)
|
242
|
+
t.integer :score2ii # second third - team2 (opt)
|
243
|
+
t.references :next_match, index: false ## Note: do NOT auto-add index -- for hinspiel bei rueckspiel in knockout match
|
244
|
+
t.references :prev_match, index: false ## Note: do NOT auto-add index
|
245
|
+
|
246
|
+
t.integer :winner # 1,2,0,nil calculate on save - "real" winner (after 90 or extra time or penalty, aggregated first+second leg?)
|
247
|
+
t.integer :winner90 # 1,2,0,nil calculate on save - winner after 90 mins (or regugular play time depending on sport - add alias or find a better name!)
|
248
|
+
|
249
|
+
t.string :comments
|
250
|
+
|
251
|
+
t.timestamps
|
252
|
+
end
|
253
|
+
|
254
|
+
add_index :matches, :key, unique: true
|
255
|
+
add_index :matches, :event_id # fk event_id index
|
256
|
+
add_index :matches, :round_id # fk round_id index
|
257
|
+
add_index :matches, :group_id # fk group_id index
|
258
|
+
add_index :matches, :next_match_id # fk next_match_id index
|
259
|
+
add_index :matches, :prev_match_id # fk next_match_id index
|
260
|
+
add_index :matches, :team1_id
|
261
|
+
add_index :matches, :team2_id
|
262
|
+
|
263
|
+
|
264
|
+
# todo: remove id from join table (without extra fields)? why?? why not??
|
265
|
+
create_table :events_teams do |t|
|
266
|
+
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
267
|
+
t.references :team, null: false, index: false ## Note: do NOT auto-add index
|
268
|
+
t.timestamps
|
269
|
+
end
|
270
|
+
|
271
|
+
add_index :events_teams, [:event_id, :team_id], unique: true
|
272
|
+
add_index :events_teams, :event_id
|
273
|
+
|
274
|
+
|
275
|
+
# todo: remove id from join table (without extra fields)? why?? why not??
|
276
|
+
create_table :stages_teams do |t|
|
277
|
+
t.references :stage, null: false, index: false ## Note: do NOT auto-add index
|
278
|
+
t.references :team, null: false, index: false ## Note: do NOT auto-add index
|
279
|
+
t.timestamps
|
280
|
+
end
|
281
|
+
|
282
|
+
add_index :stages_teams, [:stage_id, :team_id], unique: true
|
283
|
+
add_index :stages_teams, :stage_id
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
# todo: remove id from join table (without extra fields)? why?? why not??
|
288
|
+
create_table :events_grounds do |t|
|
289
|
+
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
290
|
+
t.references :ground, null: false, index: false ## Note: do NOT auto-add index
|
291
|
+
t.timestamps
|
292
|
+
end
|
293
|
+
|
294
|
+
add_index :events_grounds, [:event_id, :ground_id], unique: true
|
295
|
+
add_index :events_grounds, :event_id
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
create_table :groups_teams do |t|
|
300
|
+
t.references :group, null: false, index: false ## Note: do NOT auto-add index
|
301
|
+
t.references :team, null: false, index: false ## Note: do NOT auto-add index
|
302
|
+
t.timestamps
|
303
|
+
end
|
304
|
+
|
305
|
+
add_index :groups_teams, [:group_id, :team_id], unique: true
|
306
|
+
add_index :groups_teams, :group_id
|
307
|
+
|
308
|
+
|
309
|
+
### todo: add models and some seed data
|
310
|
+
|
311
|
+
create_table :seasons do |t| ## also used for years - add a boolean year true/false flag too - why? why not?
|
312
|
+
t.string :key, null: false
|
313
|
+
t.string :name, null: false # e.g. 2011/12, 2012/13 ### what to do w/ 2012? for world cup etc?
|
314
|
+
t.timestamps
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
create_table :leagues do |t| ## also for cups/conferences/tournaments/world series/etc.
|
319
|
+
t.string :key, null: false
|
320
|
+
t.string :name, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
|
321
|
+
t.string :alt_names # comma separated list of alt names / synonyms
|
322
|
+
|
323
|
+
t.references :country, index: false ## optional for now ### todo: create "virtual" country for international leagues e.g. use int? or world (ww?)/europe (eu)/etc. similar? already taken??
|
324
|
+
|
325
|
+
## fix: rename to :clubs from :club - why? why not?
|
326
|
+
## fix: rename to :intl from :international - why? why not? shorter? better?
|
327
|
+
## todo/check: flip clup to league flag? why? why not?
|
328
|
+
t.boolean :clubs, null: false, default: false # club teams or national teams?
|
329
|
+
t.boolean :intl, null: false, default: false # national league or international?
|
330
|
+
t.boolean :cup, null: false, default: false ## or regular season league?? use a tournament type field with enums - why? why not?
|
331
|
+
|
332
|
+
t.integer :level ## use tier? e.g. level 1, level 2, etc.
|
333
|
+
|
334
|
+
t.integer :start_year
|
335
|
+
t.integer :end_year
|
336
|
+
|
337
|
+
## todo: add t.boolean :national flag? for national teams?
|
338
|
+
t.timestamps
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
create_table :badges do |t|
|
343
|
+
t.references :team, null: false, index: false
|
344
|
+
## todo/fix: use event insead of league+season ??
|
345
|
+
## t.references :event, :null => false # event => league+season
|
346
|
+
t.references :league, null: false, index: false
|
347
|
+
t.references :season, null: false, index: false
|
348
|
+
t.string :name, null: false # Meister, Weltmeister, Europameister, Cupsieger, Vize-Meister, Aufsteiger, Absteiger, etc.
|
349
|
+
t.timestamps
|
350
|
+
end
|
351
|
+
|
352
|
+
|
353
|
+
create_table :assocs do |t|
|
354
|
+
t.string :key, null: false
|
355
|
+
t.string :name, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
|
356
|
+
|
357
|
+
t.integer :start_year # founding year
|
358
|
+
t.string :web
|
359
|
+
|
360
|
+
### if national assoc - has (optional) country ref
|
361
|
+
t.references :country, index: false # note: optional - only used/set (required) for national assocs (or subnational too?)
|
362
|
+
t.boolean :national, null: false, default: false
|
363
|
+
|
364
|
+
## add :world flag for FIFA? - just check if parent is null? for root assoc(s)? why? why not?
|
365
|
+
## add :regional flag for continental subdivision?
|
366
|
+
## todo: shorten to contl and intercontl - why? why not?
|
367
|
+
t.boolean :continental, null: false, default: false
|
368
|
+
t.boolean :intercontinental, null: false, default: false # e.g. arab football league (africa+western asia/middle east)
|
369
|
+
t.timestamps
|
370
|
+
end
|
371
|
+
|
372
|
+
add_index :assocs, :key, unique: true
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
create_table :assocs_assocs do |t|
|
377
|
+
t.references :assoc1, null: false, index: false ## Note: do NOT auto-add index -- parent assoc
|
378
|
+
t.references :assoc2, null: false, index: false ## Note: do NOT auto-add index -- child assoc is_member_of parent assoc
|
379
|
+
t.timestamps
|
380
|
+
end
|
381
|
+
|
382
|
+
add_index :assocs_assocs, [:assoc1_id,:assoc2_id], unique: true
|
383
|
+
add_index :assocs_assocs, :assoc1_id
|
384
|
+
add_index :assocs_assocs, :assoc2_id
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
############################################
|
389
|
+
# stats tables
|
390
|
+
|
391
|
+
# use tables for standings e.g group_tables? - why? why not?
|
392
|
+
#
|
393
|
+
# todo: add group_standings per round with pos diffs e.g +1,+2, -3 etc.
|
394
|
+
|
395
|
+
create_table :group_standings do |t|
|
396
|
+
t.references :group, null: false, index: false
|
397
|
+
t.timestamps
|
398
|
+
end
|
399
|
+
|
400
|
+
### use items or lines instead of entries - why (shorter! simple plural e.g. just add s)
|
401
|
+
## use group_table_lines/stats - why? why not?
|
402
|
+
|
403
|
+
create_table :group_standing_entries do |t|
|
404
|
+
t.references :group_standing, null: false, index: false
|
405
|
+
t.references :team, null: false, index: false
|
406
|
+
t.integer :pos # check/todo: use rank? -- keep/use pos only for "internal" insertation order only - why? why not?
|
407
|
+
t.integer :played ## p/pld
|
408
|
+
t.integer :won ## w
|
409
|
+
t.integer :lost ## l
|
410
|
+
t.integer :drawn ## d or t/tied ??
|
411
|
+
t.integer :goals_for # todo: find a short name - gf? why? why not?
|
412
|
+
t.integer :goals_against # todo: find a shorter name - ga? why? why not?
|
413
|
+
t.integer :pts
|
414
|
+
t.string :comments
|
415
|
+
t.timestamps
|
416
|
+
end
|
417
|
+
|
418
|
+
|
419
|
+
create_table :event_standings do |t|
|
420
|
+
t.references :event, null: false, index: false
|
421
|
+
t.timestamps
|
422
|
+
end
|
423
|
+
|
424
|
+
create_table :event_standing_entries do |t|
|
425
|
+
t.references :event_standing, null: false, index: false
|
426
|
+
t.references :team, null: false, index: false
|
427
|
+
t.integer :pos
|
428
|
+
t.integer :played
|
429
|
+
t.integer :won
|
430
|
+
t.integer :lost
|
431
|
+
t.integer :drawn
|
432
|
+
t.integer :goals_for # todo: find a short name - gf? or for? why? why not?
|
433
|
+
t.integer :goals_against # todo: find a shorter name - ga? or against? why? why not?
|
434
|
+
t.integer :pts
|
435
|
+
t.string :comments
|
436
|
+
t.timestamps
|
437
|
+
end
|
438
|
+
|
439
|
+
|
440
|
+
## flex (free-style/form) standings table - lets you add as many events as you like (not bound to single event/season/etc.)
|
441
|
+
## -use (find a better) a different name? why? why not?
|
442
|
+
create_table :alltime_standings do |t|
|
443
|
+
t.string :key, null: false
|
444
|
+
t.string :name, null: false
|
445
|
+
t.timestamps
|
446
|
+
end
|
447
|
+
|
448
|
+
create_table :alltime_standing_entries do |t|
|
449
|
+
t.references :alltime_standing, null: false, index: false
|
450
|
+
t.references :team, null: false, index: false
|
451
|
+
t.integer :pos
|
452
|
+
t.integer :played # todo: use a different name - why? why not?
|
453
|
+
t.integer :won
|
454
|
+
t.integer :lost
|
455
|
+
t.integer :drawn
|
456
|
+
t.integer :goals_for # todo: find a short name - gf? why? why not?
|
457
|
+
t.integer :goals_against # todo: find a shorter name - ga? why? why not?
|
458
|
+
t.integer :pts
|
459
|
+
t.integer :recs # note: specific to alltime - stats records counter (e.g. appearance counter) - find a better name - why? why not?
|
460
|
+
t.string :comments
|
461
|
+
t.timestamps
|
462
|
+
end
|
463
|
+
|
464
|
+
|
465
|
+
end # Schema.define
|
466
|
+
end # method up
|
467
|
+
|
468
|
+
|
469
|
+
end # class CreateDb
|
470
|
+
|
471
|
+
end # module SportDb
|