sportdb-models 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -20
- data/README.md +31 -31
- data/Rakefile +32 -32
- data/lib/sportdb/models.rb +212 -179
- 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 +17 -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/world/continent.rb +20 -20
- data/lib/sportdb/models/models/world/state.rb +19 -19
- data/lib/sportdb/models/schema.rb +466 -466
- data/lib/sportdb/models/version.rb +27 -29
- data/test/helper.rb +46 -46
- metadata +12 -6
@@ -1,31 +1,31 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
module Model
|
5
|
-
|
6
|
-
|
7
|
-
class EventStanding < ActiveRecord::Base
|
8
|
-
|
9
|
-
self.table_name = 'event_standings'
|
10
|
-
|
11
|
-
has_many :entries, class_name: 'SportDb::Model::EventStandingEntry', foreign_key: 'event_standing_id', :dependent => :delete_all
|
12
|
-
belongs_to :event
|
13
|
-
|
14
|
-
end # class EventStanding
|
15
|
-
|
16
|
-
|
17
|
-
class EventStandingEntry < ActiveRecord::Base
|
18
|
-
|
19
|
-
self.table_name = 'event_standing_entries'
|
20
|
-
|
21
|
-
belongs_to :standing, class_name: 'SportDb::Model::EventStanding', foreign_key: 'event_standing_id'
|
22
|
-
belongs_to :team
|
23
|
-
|
24
|
-
## note:
|
25
|
-
## map standing_id to group_standing_id - convenience alias
|
26
|
-
def standing_id=(value) write_attribute(:event_standing_id, value); end
|
27
|
-
|
28
|
-
end # class EventStandingEntry
|
29
|
-
|
30
|
-
end # module Model
|
31
|
-
end # module SportDb
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
|
7
|
+
class EventStanding < ActiveRecord::Base
|
8
|
+
|
9
|
+
self.table_name = 'event_standings'
|
10
|
+
|
11
|
+
has_many :entries, class_name: 'SportDb::Model::EventStandingEntry', foreign_key: 'event_standing_id', :dependent => :delete_all
|
12
|
+
belongs_to :event
|
13
|
+
|
14
|
+
end # class EventStanding
|
15
|
+
|
16
|
+
|
17
|
+
class EventStandingEntry < ActiveRecord::Base
|
18
|
+
|
19
|
+
self.table_name = 'event_standing_entries'
|
20
|
+
|
21
|
+
belongs_to :standing, class_name: 'SportDb::Model::EventStanding', foreign_key: 'event_standing_id'
|
22
|
+
belongs_to :team
|
23
|
+
|
24
|
+
## note:
|
25
|
+
## map standing_id to group_standing_id - convenience alias
|
26
|
+
def standing_id=(value) write_attribute(:event_standing_id, value); end
|
27
|
+
|
28
|
+
end # class EventStandingEntry
|
29
|
+
|
30
|
+
end # module Model
|
31
|
+
end # module SportDb
|
@@ -1,20 +1,20 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module WorldDb
|
4
|
-
module Model
|
5
|
-
|
6
|
-
class Continent
|
7
|
-
has_many :teams, :through => :countries
|
8
|
-
|
9
|
-
# fix: require active record 4
|
10
|
-
# has_many :clubs, :through => :countries
|
11
|
-
# has_many :national_teams, :through => :countries
|
12
|
-
|
13
|
-
|
14
|
-
has_many :leagues, :through => :countries
|
15
|
-
has_many :grounds, :through => :countries
|
16
|
-
end # class Continent
|
17
|
-
|
18
|
-
end # module Model
|
19
|
-
end # module WorldDb
|
20
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module WorldDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
class Continent
|
7
|
+
has_many :teams, :through => :countries
|
8
|
+
|
9
|
+
# fix: require active record 4
|
10
|
+
# has_many :clubs, :through => :countries
|
11
|
+
# has_many :national_teams, :through => :countries
|
12
|
+
|
13
|
+
|
14
|
+
has_many :leagues, :through => :countries
|
15
|
+
has_many :grounds, :through => :countries
|
16
|
+
end # class Continent
|
17
|
+
|
18
|
+
end # module Model
|
19
|
+
end # module WorldDb
|
20
|
+
|
@@ -1,19 +1,19 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
module WorldDb
|
5
|
-
module Model
|
6
|
-
|
7
|
-
class State
|
8
|
-
has_many :teams, class_name: 'SportDb::Model::Team', :through => :cities
|
9
|
-
|
10
|
-
# fix: require active record 4
|
11
|
-
# has_many :clubs, class_name: 'SportDb::Model::Team', :through => :cities
|
12
|
-
# has_many :national_teams, class_name: 'SportDb::Model::Team', :through => :cities
|
13
|
-
|
14
|
-
has_many :grounds, class_name: 'SportDb::Model::Ground', :through => :cities
|
15
|
-
end # class State
|
16
|
-
|
17
|
-
end # module Model
|
18
|
-
end # module WorldDb
|
19
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module WorldDb
|
5
|
+
module Model
|
6
|
+
|
7
|
+
class State
|
8
|
+
has_many :teams, class_name: 'SportDb::Model::Team', :through => :cities
|
9
|
+
|
10
|
+
# fix: require active record 4
|
11
|
+
# has_many :clubs, class_name: 'SportDb::Model::Team', :through => :cities
|
12
|
+
# has_many :national_teams, class_name: 'SportDb::Model::Team', :through => :cities
|
13
|
+
|
14
|
+
has_many :grounds, class_name: 'SportDb::Model::Ground', :through => :cities
|
15
|
+
end # class State
|
16
|
+
|
17
|
+
end # module Model
|
18
|
+
end # module WorldDb
|
19
|
+
|
@@ -1,466 +1,466 @@
|
|
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
|
-
t.time :time
|
212
|
-
|
213
|
-
t.boolean :postponed, null: false, default: false
|
214
|
-
## t.date :date2 # optional old date (when postponed)
|
215
|
-
## t.date :date3 # optional old date (when postponed twice)
|
216
|
-
|
217
|
-
t.string :status ## optional match status - note: uses UPCASE string constants for now
|
218
|
-
## e.g. CANCELLED / ABANDONED / REPLAY / AWARDED / POSTPONED / etc.
|
219
|
-
|
220
|
-
|
221
|
-
t.references :ground, index: false # optional - stadium (lets you get city,region,country,etc)
|
222
|
-
t.references :city, index: false # optional - convenience for ground.city_id ???
|
223
|
-
|
224
|
-
## change home to neutral - why? why not?
|
225
|
-
t.boolean :home, null: false, default: true # is team1 play at home or neutral (that is, at its home stadium)
|
226
|
-
t.boolean :knockout, null: false, default: false
|
227
|
-
|
228
|
-
t.integer :score1
|
229
|
-
t.integer :score2
|
230
|
-
t.integer :score1et # extratime - team 1 (opt)
|
231
|
-
t.integer :score2et # extratime - team 2 (opt)
|
232
|
-
t.integer :score1p # penalty - team 1 (opt)
|
233
|
-
t.integer :score2p # penalty - team 2 (opt) elfmeter (opt)
|
234
|
-
t.integer :score1i # half time / first third (opt)
|
235
|
-
t.integer :score2i # half time - team 2
|
236
|
-
t.integer :score1ii # second third (opt)
|
237
|
-
t.integer :score2ii # second third - team2 (opt)
|
238
|
-
t.references :next_match, index: false ## Note: do NOT auto-add index -- for hinspiel bei rueckspiel in knockout match
|
239
|
-
t.references :prev_match, index: false ## Note: do NOT auto-add index
|
240
|
-
|
241
|
-
t.integer :winner # 1,2,0,nil calculate on save - "real" winner (after 90 or extra time or penalty, aggregated first+second leg?)
|
242
|
-
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!)
|
243
|
-
|
244
|
-
t.string :comments
|
245
|
-
|
246
|
-
t.timestamps
|
247
|
-
end
|
248
|
-
|
249
|
-
add_index :matches, :key, unique: true
|
250
|
-
add_index :matches, :event_id # fk event_id index
|
251
|
-
add_index :matches, :round_id # fk round_id index
|
252
|
-
add_index :matches, :group_id # fk group_id index
|
253
|
-
add_index :matches, :next_match_id # fk next_match_id index
|
254
|
-
add_index :matches, :prev_match_id # fk next_match_id index
|
255
|
-
add_index :matches, :team1_id
|
256
|
-
add_index :matches, :team2_id
|
257
|
-
|
258
|
-
|
259
|
-
# todo: remove id from join table (without extra fields)? why?? why not??
|
260
|
-
create_table :events_teams do |t|
|
261
|
-
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
262
|
-
t.references :team, null: false, index: false ## Note: do NOT auto-add index
|
263
|
-
t.timestamps
|
264
|
-
end
|
265
|
-
|
266
|
-
add_index :events_teams, [:event_id, :team_id], unique: true
|
267
|
-
add_index :events_teams, :event_id
|
268
|
-
|
269
|
-
|
270
|
-
# todo: remove id from join table (without extra fields)? why?? why not??
|
271
|
-
create_table :stages_teams do |t|
|
272
|
-
t.references :stage, null: false, index: false ## Note: do NOT auto-add index
|
273
|
-
t.references :team, null: false, index: false ## Note: do NOT auto-add index
|
274
|
-
t.timestamps
|
275
|
-
end
|
276
|
-
|
277
|
-
add_index :stages_teams, [:stage_id, :team_id], unique: true
|
278
|
-
add_index :stages_teams, :stage_id
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
# todo: remove id from join table (without extra fields)? why?? why not??
|
283
|
-
create_table :events_grounds do |t|
|
284
|
-
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
285
|
-
t.references :ground, null: false, index: false ## Note: do NOT auto-add index
|
286
|
-
t.timestamps
|
287
|
-
end
|
288
|
-
|
289
|
-
add_index :events_grounds, [:event_id, :ground_id], unique: true
|
290
|
-
add_index :events_grounds, :event_id
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
create_table :groups_teams do |t|
|
295
|
-
t.references :group, null: false, index: false ## Note: do NOT auto-add index
|
296
|
-
t.references :team, null: false, index: false ## Note: do NOT auto-add index
|
297
|
-
t.timestamps
|
298
|
-
end
|
299
|
-
|
300
|
-
add_index :groups_teams, [:group_id, :team_id], unique: true
|
301
|
-
add_index :groups_teams, :group_id
|
302
|
-
|
303
|
-
|
304
|
-
### todo: add models and some seed data
|
305
|
-
|
306
|
-
create_table :seasons do |t| ## also used for years - add a boolean year true/false flag too - why? why not?
|
307
|
-
t.string :key, null: false
|
308
|
-
t.string :name, null: false # e.g. 2011/12, 2012/13 ### what to do w/ 2012? for world cup etc?
|
309
|
-
t.timestamps
|
310
|
-
end
|
311
|
-
|
312
|
-
|
313
|
-
create_table :leagues do |t| ## also for cups/conferences/tournaments/world series/etc.
|
314
|
-
t.string :key, null: false
|
315
|
-
t.string :name, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
|
316
|
-
t.string :alt_names # comma separated list of alt names / synonyms
|
317
|
-
|
318
|
-
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??
|
319
|
-
|
320
|
-
## fix: rename to :clubs from :club - why? why not?
|
321
|
-
## fix: rename to :intl from :international - why? why not? shorter? better?
|
322
|
-
## todo/check: flip clup to league flag? why? why not?
|
323
|
-
t.boolean :clubs, null: false, default: false # club teams or national teams?
|
324
|
-
t.boolean :intl, null: false, default: false # national league or international?
|
325
|
-
t.boolean :cup, null: false, default: false ## or regular season league?? use a tournament type field with enums - why? why not?
|
326
|
-
|
327
|
-
t.integer :level ## use tier? e.g. level 1, level 2, etc.
|
328
|
-
|
329
|
-
t.integer :start_year
|
330
|
-
t.integer :end_year
|
331
|
-
|
332
|
-
## todo: add t.boolean :national flag? for national teams?
|
333
|
-
t.timestamps
|
334
|
-
end
|
335
|
-
|
336
|
-
|
337
|
-
create_table :badges do |t|
|
338
|
-
t.references :team, null: false, index: false
|
339
|
-
## todo/fix: use event insead of league+season ??
|
340
|
-
## t.references :event, :null => false # event => league+season
|
341
|
-
t.references :league, null: false, index: false
|
342
|
-
t.references :season, null: false, index: false
|
343
|
-
t.string :name, null: false # Meister, Weltmeister, Europameister, Cupsieger, Vize-Meister, Aufsteiger, Absteiger, etc.
|
344
|
-
t.timestamps
|
345
|
-
end
|
346
|
-
|
347
|
-
|
348
|
-
create_table :assocs do |t|
|
349
|
-
t.string :key, null: false
|
350
|
-
t.string :name, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
|
351
|
-
|
352
|
-
t.integer :start_year # founding year
|
353
|
-
t.string :web
|
354
|
-
|
355
|
-
### if national assoc - has (optional) country ref
|
356
|
-
t.references :country, index: false # note: optional - only used/set (required) for national assocs (or subnational too?)
|
357
|
-
t.boolean :national, null: false, default: false
|
358
|
-
|
359
|
-
## add :world flag for FIFA? - just check if parent is null? for root assoc(s)? why? why not?
|
360
|
-
## add :regional flag for continental subdivision?
|
361
|
-
## todo: shorten to contl and intercontl - why? why not?
|
362
|
-
t.boolean :continental, null: false, default: false
|
363
|
-
t.boolean :intercontinental, null: false, default: false # e.g. arab football league (africa+western asia/middle east)
|
364
|
-
t.timestamps
|
365
|
-
end
|
366
|
-
|
367
|
-
add_index :assocs, :key, unique: true
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
create_table :assocs_assocs do |t|
|
372
|
-
t.references :assoc1, null: false, index: false ## Note: do NOT auto-add index -- parent assoc
|
373
|
-
t.references :assoc2, null: false, index: false ## Note: do NOT auto-add index -- child assoc is_member_of parent assoc
|
374
|
-
t.timestamps
|
375
|
-
end
|
376
|
-
|
377
|
-
add_index :assocs_assocs, [:assoc1_id,:assoc2_id], unique: true
|
378
|
-
add_index :assocs_assocs, :assoc1_id
|
379
|
-
add_index :assocs_assocs, :assoc2_id
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
############################################
|
384
|
-
# stats tables
|
385
|
-
|
386
|
-
# use tables for standings e.g group_tables? - why? why not?
|
387
|
-
#
|
388
|
-
# todo: add group_standings per round with pos diffs e.g +1,+2, -3 etc.
|
389
|
-
|
390
|
-
create_table :group_standings do |t|
|
391
|
-
t.references :group, null: false, index: false
|
392
|
-
t.timestamps
|
393
|
-
end
|
394
|
-
|
395
|
-
### use items or lines instead of entries - why (shorter! simple plural e.g. just add s)
|
396
|
-
## use group_table_lines/stats - why? why not?
|
397
|
-
|
398
|
-
create_table :group_standing_entries do |t|
|
399
|
-
t.references :group_standing, null: false, index: false
|
400
|
-
t.references :team, null: false, index: false
|
401
|
-
t.integer :pos # check/todo: use rank? -- keep/use pos only for "internal" insertation order only - why? why not?
|
402
|
-
t.integer :played ## p/pld
|
403
|
-
t.integer :won ## w
|
404
|
-
t.integer :lost ## l
|
405
|
-
t.integer :drawn ## d or t/tied ??
|
406
|
-
t.integer :goals_for # todo: find a short name - gf? why? why not?
|
407
|
-
t.integer :goals_against # todo: find a shorter name - ga? why? why not?
|
408
|
-
t.integer :pts
|
409
|
-
t.string :comments
|
410
|
-
t.timestamps
|
411
|
-
end
|
412
|
-
|
413
|
-
|
414
|
-
create_table :event_standings do |t|
|
415
|
-
t.references :event, null: false, index: false
|
416
|
-
t.timestamps
|
417
|
-
end
|
418
|
-
|
419
|
-
create_table :event_standing_entries do |t|
|
420
|
-
t.references :event_standing, null: false, index: false
|
421
|
-
t.references :team, null: false, index: false
|
422
|
-
t.integer :pos
|
423
|
-
t.integer :played
|
424
|
-
t.integer :won
|
425
|
-
t.integer :lost
|
426
|
-
t.integer :drawn
|
427
|
-
t.integer :goals_for # todo: find a short name - gf? or for? why? why not?
|
428
|
-
t.integer :goals_against # todo: find a shorter name - ga? or against? why? why not?
|
429
|
-
t.integer :pts
|
430
|
-
t.string :comments
|
431
|
-
t.timestamps
|
432
|
-
end
|
433
|
-
|
434
|
-
|
435
|
-
## flex (free-style/form) standings table - lets you add as many events as you like (not bound to single event/season/etc.)
|
436
|
-
## -use (find a better) a different name? why? why not?
|
437
|
-
create_table :alltime_standings do |t|
|
438
|
-
t.string :key, null: false
|
439
|
-
t.string :name, null: false
|
440
|
-
t.timestamps
|
441
|
-
end
|
442
|
-
|
443
|
-
create_table :alltime_standing_entries do |t|
|
444
|
-
t.references :alltime_standing, null: false, index: false
|
445
|
-
t.references :team, null: false, index: false
|
446
|
-
t.integer :pos
|
447
|
-
t.integer :played # todo: use a different name - why? why not?
|
448
|
-
t.integer :won
|
449
|
-
t.integer :lost
|
450
|
-
t.integer :drawn
|
451
|
-
t.integer :goals_for # todo: find a short name - gf? why? why not?
|
452
|
-
t.integer :goals_against # todo: find a shorter name - ga? why? why not?
|
453
|
-
t.integer :pts
|
454
|
-
t.integer :recs # note: specific to alltime - stats records counter (e.g. appearance counter) - find a better name - why? why not?
|
455
|
-
t.string :comments
|
456
|
-
t.timestamps
|
457
|
-
end
|
458
|
-
|
459
|
-
|
460
|
-
end # Schema.define
|
461
|
-
end # method up
|
462
|
-
|
463
|
-
|
464
|
-
end # class CreateDb
|
465
|
-
|
466
|
-
end # module SportDb
|
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
|
+
t.time :time
|
212
|
+
|
213
|
+
t.boolean :postponed, null: false, default: false
|
214
|
+
## t.date :date2 # optional old date (when postponed)
|
215
|
+
## t.date :date3 # optional old date (when postponed twice)
|
216
|
+
|
217
|
+
t.string :status ## optional match status - note: uses UPCASE string constants for now
|
218
|
+
## e.g. CANCELLED / ABANDONED / REPLAY / AWARDED / POSTPONED / etc.
|
219
|
+
|
220
|
+
|
221
|
+
t.references :ground, index: false # optional - stadium (lets you get city,region,country,etc)
|
222
|
+
t.references :city, index: false # optional - convenience for ground.city_id ???
|
223
|
+
|
224
|
+
## change home to neutral - why? why not?
|
225
|
+
t.boolean :home, null: false, default: true # is team1 play at home or neutral (that is, at its home stadium)
|
226
|
+
t.boolean :knockout, null: false, default: false
|
227
|
+
|
228
|
+
t.integer :score1
|
229
|
+
t.integer :score2
|
230
|
+
t.integer :score1et # extratime - team 1 (opt)
|
231
|
+
t.integer :score2et # extratime - team 2 (opt)
|
232
|
+
t.integer :score1p # penalty - team 1 (opt)
|
233
|
+
t.integer :score2p # penalty - team 2 (opt) elfmeter (opt)
|
234
|
+
t.integer :score1i # half time / first third (opt)
|
235
|
+
t.integer :score2i # half time - team 2
|
236
|
+
t.integer :score1ii # second third (opt)
|
237
|
+
t.integer :score2ii # second third - team2 (opt)
|
238
|
+
t.references :next_match, index: false ## Note: do NOT auto-add index -- for hinspiel bei rueckspiel in knockout match
|
239
|
+
t.references :prev_match, index: false ## Note: do NOT auto-add index
|
240
|
+
|
241
|
+
t.integer :winner # 1,2,0,nil calculate on save - "real" winner (after 90 or extra time or penalty, aggregated first+second leg?)
|
242
|
+
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!)
|
243
|
+
|
244
|
+
t.string :comments
|
245
|
+
|
246
|
+
t.timestamps
|
247
|
+
end
|
248
|
+
|
249
|
+
add_index :matches, :key, unique: true
|
250
|
+
add_index :matches, :event_id # fk event_id index
|
251
|
+
add_index :matches, :round_id # fk round_id index
|
252
|
+
add_index :matches, :group_id # fk group_id index
|
253
|
+
add_index :matches, :next_match_id # fk next_match_id index
|
254
|
+
add_index :matches, :prev_match_id # fk next_match_id index
|
255
|
+
add_index :matches, :team1_id
|
256
|
+
add_index :matches, :team2_id
|
257
|
+
|
258
|
+
|
259
|
+
# todo: remove id from join table (without extra fields)? why?? why not??
|
260
|
+
create_table :events_teams do |t|
|
261
|
+
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
262
|
+
t.references :team, null: false, index: false ## Note: do NOT auto-add index
|
263
|
+
t.timestamps
|
264
|
+
end
|
265
|
+
|
266
|
+
add_index :events_teams, [:event_id, :team_id], unique: true
|
267
|
+
add_index :events_teams, :event_id
|
268
|
+
|
269
|
+
|
270
|
+
# todo: remove id from join table (without extra fields)? why?? why not??
|
271
|
+
create_table :stages_teams do |t|
|
272
|
+
t.references :stage, null: false, index: false ## Note: do NOT auto-add index
|
273
|
+
t.references :team, null: false, index: false ## Note: do NOT auto-add index
|
274
|
+
t.timestamps
|
275
|
+
end
|
276
|
+
|
277
|
+
add_index :stages_teams, [:stage_id, :team_id], unique: true
|
278
|
+
add_index :stages_teams, :stage_id
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
# todo: remove id from join table (without extra fields)? why?? why not??
|
283
|
+
create_table :events_grounds do |t|
|
284
|
+
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
285
|
+
t.references :ground, null: false, index: false ## Note: do NOT auto-add index
|
286
|
+
t.timestamps
|
287
|
+
end
|
288
|
+
|
289
|
+
add_index :events_grounds, [:event_id, :ground_id], unique: true
|
290
|
+
add_index :events_grounds, :event_id
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
create_table :groups_teams do |t|
|
295
|
+
t.references :group, null: false, index: false ## Note: do NOT auto-add index
|
296
|
+
t.references :team, null: false, index: false ## Note: do NOT auto-add index
|
297
|
+
t.timestamps
|
298
|
+
end
|
299
|
+
|
300
|
+
add_index :groups_teams, [:group_id, :team_id], unique: true
|
301
|
+
add_index :groups_teams, :group_id
|
302
|
+
|
303
|
+
|
304
|
+
### todo: add models and some seed data
|
305
|
+
|
306
|
+
create_table :seasons do |t| ## also used for years - add a boolean year true/false flag too - why? why not?
|
307
|
+
t.string :key, null: false
|
308
|
+
t.string :name, null: false # e.g. 2011/12, 2012/13 ### what to do w/ 2012? for world cup etc?
|
309
|
+
t.timestamps
|
310
|
+
end
|
311
|
+
|
312
|
+
|
313
|
+
create_table :leagues do |t| ## also for cups/conferences/tournaments/world series/etc.
|
314
|
+
t.string :key, null: false
|
315
|
+
t.string :name, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
|
316
|
+
t.string :alt_names # comma separated list of alt names / synonyms
|
317
|
+
|
318
|
+
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??
|
319
|
+
|
320
|
+
## fix: rename to :clubs from :club - why? why not?
|
321
|
+
## fix: rename to :intl from :international - why? why not? shorter? better?
|
322
|
+
## todo/check: flip clup to league flag? why? why not?
|
323
|
+
t.boolean :clubs, null: false, default: false # club teams or national teams?
|
324
|
+
t.boolean :intl, null: false, default: false # national league or international?
|
325
|
+
t.boolean :cup, null: false, default: false ## or regular season league?? use a tournament type field with enums - why? why not?
|
326
|
+
|
327
|
+
t.integer :level ## use tier? e.g. level 1, level 2, etc.
|
328
|
+
|
329
|
+
t.integer :start_year
|
330
|
+
t.integer :end_year
|
331
|
+
|
332
|
+
## todo: add t.boolean :national flag? for national teams?
|
333
|
+
t.timestamps
|
334
|
+
end
|
335
|
+
|
336
|
+
|
337
|
+
create_table :badges do |t|
|
338
|
+
t.references :team, null: false, index: false
|
339
|
+
## todo/fix: use event insead of league+season ??
|
340
|
+
## t.references :event, :null => false # event => league+season
|
341
|
+
t.references :league, null: false, index: false
|
342
|
+
t.references :season, null: false, index: false
|
343
|
+
t.string :name, null: false # Meister, Weltmeister, Europameister, Cupsieger, Vize-Meister, Aufsteiger, Absteiger, etc.
|
344
|
+
t.timestamps
|
345
|
+
end
|
346
|
+
|
347
|
+
|
348
|
+
create_table :assocs do |t|
|
349
|
+
t.string :key, null: false
|
350
|
+
t.string :name, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
|
351
|
+
|
352
|
+
t.integer :start_year # founding year
|
353
|
+
t.string :web
|
354
|
+
|
355
|
+
### if national assoc - has (optional) country ref
|
356
|
+
t.references :country, index: false # note: optional - only used/set (required) for national assocs (or subnational too?)
|
357
|
+
t.boolean :national, null: false, default: false
|
358
|
+
|
359
|
+
## add :world flag for FIFA? - just check if parent is null? for root assoc(s)? why? why not?
|
360
|
+
## add :regional flag for continental subdivision?
|
361
|
+
## todo: shorten to contl and intercontl - why? why not?
|
362
|
+
t.boolean :continental, null: false, default: false
|
363
|
+
t.boolean :intercontinental, null: false, default: false # e.g. arab football league (africa+western asia/middle east)
|
364
|
+
t.timestamps
|
365
|
+
end
|
366
|
+
|
367
|
+
add_index :assocs, :key, unique: true
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
create_table :assocs_assocs do |t|
|
372
|
+
t.references :assoc1, null: false, index: false ## Note: do NOT auto-add index -- parent assoc
|
373
|
+
t.references :assoc2, null: false, index: false ## Note: do NOT auto-add index -- child assoc is_member_of parent assoc
|
374
|
+
t.timestamps
|
375
|
+
end
|
376
|
+
|
377
|
+
add_index :assocs_assocs, [:assoc1_id,:assoc2_id], unique: true
|
378
|
+
add_index :assocs_assocs, :assoc1_id
|
379
|
+
add_index :assocs_assocs, :assoc2_id
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
############################################
|
384
|
+
# stats tables
|
385
|
+
|
386
|
+
# use tables for standings e.g group_tables? - why? why not?
|
387
|
+
#
|
388
|
+
# todo: add group_standings per round with pos diffs e.g +1,+2, -3 etc.
|
389
|
+
|
390
|
+
create_table :group_standings do |t|
|
391
|
+
t.references :group, null: false, index: false
|
392
|
+
t.timestamps
|
393
|
+
end
|
394
|
+
|
395
|
+
### use items or lines instead of entries - why (shorter! simple plural e.g. just add s)
|
396
|
+
## use group_table_lines/stats - why? why not?
|
397
|
+
|
398
|
+
create_table :group_standing_entries do |t|
|
399
|
+
t.references :group_standing, null: false, index: false
|
400
|
+
t.references :team, null: false, index: false
|
401
|
+
t.integer :pos # check/todo: use rank? -- keep/use pos only for "internal" insertation order only - why? why not?
|
402
|
+
t.integer :played ## p/pld
|
403
|
+
t.integer :won ## w
|
404
|
+
t.integer :lost ## l
|
405
|
+
t.integer :drawn ## d or t/tied ??
|
406
|
+
t.integer :goals_for # todo: find a short name - gf? why? why not?
|
407
|
+
t.integer :goals_against # todo: find a shorter name - ga? why? why not?
|
408
|
+
t.integer :pts
|
409
|
+
t.string :comments
|
410
|
+
t.timestamps
|
411
|
+
end
|
412
|
+
|
413
|
+
|
414
|
+
create_table :event_standings do |t|
|
415
|
+
t.references :event, null: false, index: false
|
416
|
+
t.timestamps
|
417
|
+
end
|
418
|
+
|
419
|
+
create_table :event_standing_entries do |t|
|
420
|
+
t.references :event_standing, null: false, index: false
|
421
|
+
t.references :team, null: false, index: false
|
422
|
+
t.integer :pos
|
423
|
+
t.integer :played
|
424
|
+
t.integer :won
|
425
|
+
t.integer :lost
|
426
|
+
t.integer :drawn
|
427
|
+
t.integer :goals_for # todo: find a short name - gf? or for? why? why not?
|
428
|
+
t.integer :goals_against # todo: find a shorter name - ga? or against? why? why not?
|
429
|
+
t.integer :pts
|
430
|
+
t.string :comments
|
431
|
+
t.timestamps
|
432
|
+
end
|
433
|
+
|
434
|
+
|
435
|
+
## flex (free-style/form) standings table - lets you add as many events as you like (not bound to single event/season/etc.)
|
436
|
+
## -use (find a better) a different name? why? why not?
|
437
|
+
create_table :alltime_standings do |t|
|
438
|
+
t.string :key, null: false
|
439
|
+
t.string :name, null: false
|
440
|
+
t.timestamps
|
441
|
+
end
|
442
|
+
|
443
|
+
create_table :alltime_standing_entries do |t|
|
444
|
+
t.references :alltime_standing, null: false, index: false
|
445
|
+
t.references :team, null: false, index: false
|
446
|
+
t.integer :pos
|
447
|
+
t.integer :played # todo: use a different name - why? why not?
|
448
|
+
t.integer :won
|
449
|
+
t.integer :lost
|
450
|
+
t.integer :drawn
|
451
|
+
t.integer :goals_for # todo: find a short name - gf? why? why not?
|
452
|
+
t.integer :goals_against # todo: find a shorter name - ga? why? why not?
|
453
|
+
t.integer :pts
|
454
|
+
t.integer :recs # note: specific to alltime - stats records counter (e.g. appearance counter) - find a better name - why? why not?
|
455
|
+
t.string :comments
|
456
|
+
t.timestamps
|
457
|
+
end
|
458
|
+
|
459
|
+
|
460
|
+
end # Schema.define
|
461
|
+
end # method up
|
462
|
+
|
463
|
+
|
464
|
+
end # class CreateDb
|
465
|
+
|
466
|
+
end # module SportDb
|