sportdb-models 1.19.0 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -20
  3. data/Manifest.txt +27 -38
  4. data/README.md +31 -31
  5. data/Rakefile +32 -32
  6. data/lib/sportdb/models.rb +212 -159
  7. data/lib/sportdb/{deleter.rb → models/deleter.rb} +3 -9
  8. data/lib/sportdb/models/formats.rb +23 -0
  9. data/lib/sportdb/models/models/assoc.rb +38 -0
  10. data/lib/sportdb/models/{badge.rb → models/badge.rb} +14 -14
  11. data/lib/sportdb/models/models/event.rb +55 -0
  12. data/lib/sportdb/models/{forward.rb → models/forward.rb} +55 -55
  13. data/lib/sportdb/models/{goal.rb → models/goal.rb} +15 -15
  14. data/lib/sportdb/models/models/ground.rb +16 -0
  15. data/lib/sportdb/models/{group.rb → models/group.rb} +10 -7
  16. data/lib/sportdb/models/models/league.rb +20 -0
  17. data/lib/sportdb/models/{roster.rb → models/lineup.rb} +17 -18
  18. data/lib/sportdb/models/{game.rb → models/match.rb} +18 -61
  19. data/lib/sportdb/models/{person.rb → models/person.rb} +21 -21
  20. data/lib/sportdb/models/{round.rb → models/round.rb} +1 -6
  21. data/lib/sportdb/models/{season.rb → models/season.rb} +15 -14
  22. data/lib/sportdb/models/{stage.rb → models/stage.rb} +9 -5
  23. data/lib/sportdb/models/{stats/alltime_standing_entry.rb → models/stats/alltime_standing.rb} +9 -1
  24. data/lib/sportdb/models/{stats/event_standing_entry.rb → models/stats/event_standing.rb} +31 -21
  25. data/lib/sportdb/models/{stats/group_standing_entry.rb → models/stats/group_standing.rb} +10 -1
  26. data/lib/sportdb/models/models/team.rb +56 -0
  27. data/lib/sportdb/models/{world → models/world}/city.rb +2 -2
  28. data/lib/sportdb/models/{world → models/world}/continent.rb +20 -20
  29. data/lib/sportdb/models/{world → models/world}/country.rb +0 -0
  30. data/lib/sportdb/models/{world → models/world}/state.rb +19 -19
  31. data/lib/sportdb/models/schema.rb +466 -0
  32. data/lib/sportdb/models/stats.rb +23 -0
  33. data/lib/sportdb/models/utils.rb +24 -24
  34. data/lib/sportdb/{version.rb → models/version.rb} +27 -22
  35. data/test/helper.rb +46 -42
  36. data/test/test_changes.rb +38 -38
  37. data/test/test_cursor.rb +15 -15
  38. data/test/test_winner.rb +75 -70
  39. metadata +39 -44
  40. data/lib/sportdb/calc.rb +0 -279
  41. data/lib/sportdb/models/assoc.rb +0 -106
  42. data/lib/sportdb/models/assoc_assoc.rb +0 -15
  43. data/lib/sportdb/models/event.rb +0 -66
  44. data/lib/sportdb/models/event_ground.rb +0 -15
  45. data/lib/sportdb/models/event_team.rb +0 -16
  46. data/lib/sportdb/models/ground.rb +0 -100
  47. data/lib/sportdb/models/group_team.rb +0 -14
  48. data/lib/sportdb/models/league.rb +0 -83
  49. data/lib/sportdb/models/stage_team.rb +0 -14
  50. data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
  51. data/lib/sportdb/models/stats/event_standing.rb +0 -55
  52. data/lib/sportdb/models/stats/group_standing.rb +0 -50
  53. data/lib/sportdb/models/team.rb +0 -119
  54. data/lib/sportdb/models/team_compat.rb +0 -64
  55. data/lib/sportdb/patterns.rb +0 -37
  56. data/lib/sportdb/schema.rb +0 -397
  57. data/lib/sportdb/standings.rb +0 -178
  58. data/lib/sportdb/stats.rb +0 -27
@@ -1,119 +0,0 @@
1
-
2
- module SportDb
3
- module Model
4
-
5
- ##################
6
- # FIX: add ?
7
- #
8
- # use single table inheritance STI ????
9
- # - to mark two dervided classes e.g.
10
- # - Club ??? - why? why not?
11
- # - NationalTeam ??? - why? why not?
12
-
13
-
14
- class Team < ActiveRecord::Base
15
-
16
- has_many :home_games, class_name: 'Game', foreign_key: 'team1_id'
17
- has_many :away_games, class_name: 'Game', foreign_key: 'team2_id'
18
-
19
- ## todo/fix: must be 3 or more letters (plus allow digits e.g. salzburgii, muenchen1980, etc.) - why? why not??
20
- validates :key, format: { with: /#{TEAM_KEY_PATTERN}/, message: TEAM_KEY_PATTERN_MESSAGE }
21
- validates :code, format: { with: /#{TEAM_CODE_PATTERN}/, message: TEAM_CODE_PATTERN_MESSAGE }, allow_nil: true
22
-
23
- has_many :event_teams, class_name: 'EventTeam' # join table (events+teams)
24
- has_many :events, :through => :event_teams
25
-
26
- # note: team belongs_to a single (optinal) assoc for now (national assoc may have many assocs)
27
- belongs_to :assoc
28
-
29
- ### fix!!! - how to do it with has_many macro? use finder_sql?
30
- ## finder_sql is depreciated in Rails 4!!!
31
- # use -> { where() } etc. -- try it if it works
32
- ## keep as is! best solution ??
33
- ## a discussion here -> https://github.com/rails/rails/issues/9726
34
- ## a discussion here (not really helpful) -> http://stackoverflow.com/questions/2125440/activerecord-has-many-where-two-columns-in-table-a-are-primary-keys-in-table-b
35
-
36
- def games
37
- Game.where( 'team1_id = ? or team2_id = ?', id, id ).order( 'play_at' )
38
- end
39
-
40
- def upcoming_games
41
- Game.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'play_at > ?', Time.now ).order( 'play_at' )
42
- end
43
-
44
- def past_games
45
- Game.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'play_at < ?', Time.now ).order( 'play_at desc' )
46
- end
47
-
48
-
49
- has_many :badges # Winner, 2nd, Cupsieger, Aufsteiger, Absteiger, etc.
50
-
51
- belongs_to :country, class_name: 'WorldDb::Model::Country', foreign_key: 'country_id'
52
- belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
53
-
54
-
55
- ## fix/todo: change title to name; title2 to name2 etc.
56
- def name() title; end
57
-
58
-
59
- def self.create_or_update_from_values( new_attributes, values )
60
-
61
- ## fix: add/configure logger for ActiveRecord!!!
62
- logger = LogUtils::Logger.root
63
-
64
-
65
- ## check optional values
66
- values.each_with_index do |value, index|
67
- if value =~ /^city:/ ## city:
68
- value_city_key = value[5..-1] ## cut off city: prefix
69
- value_city = City.find_by_key( value_city_key )
70
- if value_city.present?
71
- new_attributes[ :city_id ] = value_city.id
72
- else
73
- ## todo/fix: add strict mode flag - fail w/ exit 1 in strict mode
74
- logger.warn "city with key #{value_city_key} missing"
75
- ## todo: log errors to db log???
76
- end
77
- elsif value =~ /^(18|19|20)[0-9]{2}$/ ## assume founding year -- allow 18|19|20
78
- ## logger.info " founding/opening year #{value}"
79
- new_attributes[ :since ] = value.to_i
80
- elsif value =~ /\/{2}/ # assume it's an address line e.g. xx // xx
81
- ## logger.info " found address line #{value}"
82
- new_attributes[ :address ] = value
83
- elsif value =~ /^(?:[a-z]{2}\.)?wikipedia:/ # assume it's wikipedia e.g. [es.]wikipedia:
84
- logger.info " found wikipedia line #{value}; skipping for now"
85
- elsif value =~ /(^www\.)|(\.com$)/ # FIX: !!!! use a better matcher not just www. and .com
86
- new_attributes[ :web ] = value
87
- elsif value =~ /^[A-Z][A-Z0-9][A-Z0-9_]?$/ ## assume two or three-letter code e.g. FCB, RBS, etc.
88
- new_attributes[ :code ] = value
89
- elsif value =~ /^[a-z]{2,3}$/ ## assume two or three-letter country key e.g. at,de,mx, or eng,sco,wal,nir etc.
90
- ## fix: if country does NOT match / NOT found - just continue w/ next match!!!!
91
- # - just issue an error/warn do NOT crash
92
- value_country = Country.find_by_key!( value )
93
- new_attributes[ :country_id ] = value_country.id
94
- else
95
- ## todo: assume title2 ??
96
- # issue warning: unknown type for value
97
- logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
98
- end
99
- end
100
-
101
- rec = Team.find_by_key( new_attributes[ :key ] )
102
- if rec.present?
103
- logger.debug "update Team #{rec.id}-#{rec.key}:"
104
- else
105
- logger.debug "create Team:"
106
- rec = Team.new
107
- end
108
-
109
- logger.debug new_attributes.to_json
110
-
111
- rec.update_attributes!( new_attributes )
112
-
113
- end # create_or_update_from_values
114
-
115
- end # class Team
116
-
117
-
118
- end # module Model
119
- end # module SportDb
@@ -1,64 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Model
5
-
6
- #############################################################
7
- # collect depreciated or methods for future removal here
8
- # - keep for now for compatibility (for old code)
9
-
10
- class Team
11
-
12
-
13
- def self.create_from_ary!( teams, more_values={} )
14
- teams.each do |values|
15
-
16
- ## key & title required
17
- attr = {
18
- key: values[0]
19
- }
20
-
21
- ## title (split of optional synonyms)
22
- # e.g. FC Bayern Muenchen|Bayern Muenchen|Bayern
23
- titles = values[1].split('|')
24
-
25
- attr[ :title ] = titles[0]
26
- ## add optional synonyms
27
- attr[ :synonyms ] = titles[1..-1].join('|') if titles.size > 1
28
-
29
-
30
- attr = attr.merge( more_values )
31
-
32
- ## check for optional values
33
- values[2..-1].each do |value|
34
- if value.is_a? Country
35
- attr[ :country_id ] = value.id
36
- elsif value.is_a? City
37
- attr[ :city_id ] = value.id
38
- elsif value =~ /#{TEAM_CODE_PATTERN}/ ## assume its three letter code (e.g. ITA or S04 etc.)
39
- attr[ :code ] = value
40
- elsif value =~ /^city:/ ## city:
41
- value_city_key = value[5..-1] ## cut off city: prefix
42
- value_city = City.find_by_key!( value_city_key )
43
- attr[ :city_id ] = value_city.id
44
- else
45
- attr[ :title2 ] = value
46
- end
47
- end
48
-
49
- ## check if exists
50
- team = Team.find_by_key( values[0] )
51
- if team.present?
52
- puts "*** warning team with key '#{values[0]}' exists; skipping create"
53
- else
54
- Team.create!( attr )
55
- end
56
- end # each team
57
- end
58
-
59
- end # class Team
60
-
61
-
62
-
63
- end # module Model
64
- end # module SportDb
@@ -1,37 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
-
5
- # collection of regex patterns for reuse (SportDb specific)
6
-
7
- ### todo: add a patterns.md page to github ??
8
- ## - add regexper pics??
9
-
10
- ############
11
- # about ruby regexps
12
- #
13
- # try the rubular - Ruby regular expression editor and tester
14
- # -> http://rubular.com
15
- # code -> ?? by ??
16
- #
17
- #
18
- # Jeff Avallone's Regexper - Shows State-Automata Diagrams
19
- # try -> http://regexper.com
20
- # code -> https://github.com/javallone/regexper
21
- #
22
- #
23
- # Regular Expressions | The Bastards Book of Ruby by Dan Nguyen
24
- # http://ruby.bastardsbook.com/chapters/regexes/
25
- #
26
- # move to notes regex|patterns on geraldb.github.io ??
27
- #
28
-
29
- TEAM_KEY_PATTERN = '\A[a-z]{3,}\z'
30
- TEAM_KEY_PATTERN_MESSAGE = "expected three or more lowercase letters a-z /#{TEAM_KEY_PATTERN}/"
31
-
32
- # must start w/ letter A-Z (2nd,3rd,4th or 5th can be number or underscore _)
33
- TEAM_CODE_PATTERN = '\A[A-Z_][A-Z0-9_]{1,4}\z'
34
- TEAM_CODE_PATTERN_MESSAGE = "expected two or three or four or five uppercase letters A-Z (and 0-9_; must start with A-Z) /#{TEAM_CODE_PATTERN}/"
35
-
36
-
37
- end # module SportDb
@@ -1,397 +0,0 @@
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 :title, null: false
12
- t.string :title2
13
- t.string :code # make it not null? - three letter code (short title)
14
- t.string :synonyms # comma separated list of synonyms
15
- t.references :country, null: false
16
- t.references :city # NB: city is optional (should be required for clubs e.g. non-national teams)
17
- t.boolean :club, null: false, default: false # is it a club (not a national team)?
18
-
19
- t.integer :since # founding year
20
- t.string :address
21
- t.string :web
22
-
23
- t.references :assoc # optional: national football assoc(iation), for example - used for national teams
24
-
25
- ### fix: remove and add virtual attribute in model instead
26
- t.boolean :national, null: false, default: false # is it a national selection team (not a club)?
27
- t.timestamps
28
- end
29
-
30
- add_index :teams, :key, unique: true
31
-
32
- ###########
33
- # check: use table (rename to) venues / stadiums - why? why not?
34
- create_table :grounds do |t|
35
- t.string :key, null: false # import/export key
36
- t.string :title, null: false
37
- t.string :synonyms # comma separated list of synonyms
38
-
39
- t.references :country, null: false
40
- t.references :city # todo: make city required ???
41
-
42
- t.integer :since # founding year
43
- t.integer :capacity # attentence capacity e.g. 10_000 or 50_000 etc.
44
- t.string :address
45
-
46
-
47
- ### fix/todo: add since/founded/opened/build attrib eg. 2011 or 1987
48
- ## - add capacity e.g. 40_000
49
- ## fix: add address !!!! etc
50
-
51
- ## add region ??? or just use region from city ??
52
-
53
- t.timestamps
54
- end
55
-
56
- add_index :grounds, :key, unique: true
57
-
58
-
59
- # join table: person+game(team1+team2+event(season+league))
60
- create_table :goals do |t|
61
- t.references :person, null: false
62
- t.references :game, null: false
63
- t.references :team, null: false ## use integer instead w/ values 1 or 2 for team1 or team2 ?? why? why not?
64
-
65
- t.integer :minute
66
- t.integer :offset, null: false, default: 0 # e.g. 45' +3 or 90' +2
67
-
68
- t.integer :score1
69
- t.integer :score2
70
-
71
- ## type of goal (penalty, owngoal)
72
- t.boolean :penalty, null: false, default: false
73
- t.boolean :owngoal, null: false, default: false # de: Eigentor -> # todo: find better name?
74
-
75
- t.timestamps
76
- end
77
-
78
-
79
- ################
80
- # fix/todo: rename to squads / lineups
81
-
82
- # join table -> person+team+event(season+league)
83
- create_table :rosters do |t| # use squads as an alternative name? why? why not??
84
- t.references :person, null: false
85
- t.references :team, null: false
86
- t.references :event # make required?
87
- t.integer :pos, null: false
88
-
89
- t.timestamps
90
- end
91
-
92
-
93
- create_table :events do |t|
94
- t.string :key, null: false # import/export key
95
- t.references :league, null: false
96
- t.references :season, null: false
97
- t.date :start_at, null: false # NB: only use date (w/o time)
98
- t.date :end_at # make it required??? # NB: only use date (w/o time)
99
- t.boolean :team3, null: false, default: true ## e.g. Champions League has no 3rd place (only 1st and 2nd/final)
100
-
101
- #### track 1-n sources (from repos) - # todo move to its own table later
102
- ## NB: relative to event.yml - use mapper to "resolve" to full path w/ repo; use league+season keys
103
- t.string :sources # e.g. cup or bl,bl_ii # NB: for now store all in on string separated by comma
104
- t.string :config # e.g. cup or bl # e.g assumes cup.yml, bl.yml etc. for now
105
-
106
-
107
- t.timestamps
108
- end
109
-
110
- add_index :events, :key, unique: true
111
-
112
-
113
- create_table :rounds do |t|
114
- t.references :event, null: false, index: false ## Note: do NOT auto-add index
115
- t.string :title, null: false
116
- t.string :title2
117
- t.integer :pos, null: false
118
- ## add new table stage/stages for grouping rounds in group rounds and playoff rounds, for example???
119
- ## # "regular" season (group) games or post-season (playoff) knockouts (k.o's)
120
- t.boolean :knockout, null: false, default: false
121
- t.date :start_at, null: false # NB: only use date (w/o time)
122
- t.date :end_at # todo: make it required e.g. :null => false # NB: only use date (w/o time)
123
-
124
- ## auto-added flag (e.g. start_at n end_at dates got calculated)
125
- ## if auto-added flag is false - do NOT auto-update start_at, end_at etc.
126
- t.boolean :auto, null: false, default: true
127
-
128
- t.timestamps
129
- end
130
-
131
- add_index :rounds, :event_id # fk event_id index
132
-
133
-
134
- create_table :groups do |t| # Teamgruppe (zB Gruppe A, Gruppe B, etc.)
135
- t.references :event, null: false, index: false ## Note: do NOT auto-add index
136
- t.string :title, null: false
137
- t.integer :pos, null: false
138
- t.timestamps
139
- end
140
-
141
- add_index :groups, :event_id # fk event_id index
142
-
143
-
144
- create_table :stages do |t| # e.g. regular season, champions round, etc.
145
- t.references :event, null: false, index: false ## Note: do NOT auto-add index
146
- t.string :title, null: false
147
- t.timestamps
148
- end
149
-
150
- add_index :stages, :event_id # fk event_id index
151
-
152
-
153
-
154
- ###########################
155
- # fix: rename table to matches
156
- create_table :games do |t|
157
- t.string :key # import/export key
158
- t.references :round, null: false, index: false ## Note: do NOT auto-add index
159
- t.integer :pos, null: false
160
- t.references :group, index: false ## Note: do NOT auto-add index -- group is optional
161
- t.references :stage, index: false # optional - regular seasion / champions round etc.
162
- t.references :team1, null: false, index: false ## Note: do NOT auto-add index
163
- t.references :team2, null: false, index: false ## Note: do NOT auto-add index
164
-
165
- t.datetime :play_at, null: false
166
- t.boolean :postponed, null: false, default: false
167
- t.datetime :play_at_v2 # optional old date (when postponed)
168
- t.datetime :play_at_v3 # optional odl date (when postponed twice)
169
-
170
- t.references :ground # optional - stadium (lets you get city,region,country,etc)
171
- t.references :city # optional - convenience for ground.city_id ???
172
-
173
-
174
- t.boolean :knockout, null: false, default: false
175
- t.boolean :home, null: false, default: true # is team1 play at home (that is, at its home stadium)
176
- t.integer :score1
177
- t.integer :score2
178
- t.integer :score1et # extratime - team 1 (opt)
179
- t.integer :score2et # extratime - team 2 (opt)
180
- t.integer :score1p # penalty - team 1 (opt)
181
- t.integer :score2p # penalty - team 2 (opt) elfmeter (opt)
182
- t.integer :score1i # half time / first third (opt)
183
- t.integer :score2i # half time - team 2
184
- t.integer :score1ii # second third (opt)
185
- t.integer :score2ii # second third - team2 (opt)
186
- t.references :next_game, index: false ## Note: do NOT auto-add index -- for hinspiel bei rueckspiel in knockout game
187
- t.references :prev_game, index: false ## Note: do NOT auto-add index
188
-
189
- t.integer :winner # 1,2,0,nil calculate on save - "real" winner (after 90 or extra time or penalty, aggregated first+second leg?)
190
- 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!)
191
-
192
- t.timestamps
193
- end
194
-
195
- add_index :games, :key, unique: true
196
- add_index :games, :round_id # fk round_id index
197
- add_index :games, :group_id # fk group_id index
198
- add_index :games, :next_game_id # fk next_game_id index
199
- add_index :games, :prev_game_id # fk next_game_id index
200
- add_index :games, :team1_id
201
- add_index :games, :team2_id
202
-
203
-
204
- # todo: remove id from join table (without extra fields)? why?? why not??
205
- create_table :events_teams do |t|
206
- t.references :event, null: false, index: false ## Note: do NOT auto-add index
207
- t.references :team, null: false, index: false ## Note: do NOT auto-add index
208
- t.timestamps
209
- end
210
-
211
- add_index :events_teams, [:event_id, :team_id], unique: true
212
- add_index :events_teams, :event_id
213
-
214
-
215
- # todo: remove id from join table (without extra fields)? why?? why not??
216
- create_table :stages_teams do |t|
217
- t.references :stage, null: false, index: false ## Note: do NOT auto-add index
218
- t.references :team, null: false, index: false ## Note: do NOT auto-add index
219
- t.timestamps
220
- end
221
-
222
- add_index :stages_teams, [:stage_id, :team_id], unique: true
223
- add_index :stages_teams, :stage_id
224
-
225
-
226
-
227
- # todo: remove id from join table (without extra fields)? why?? why not??
228
- create_table :events_grounds do |t|
229
- t.references :event, null: false, index: false ## Note: do NOT auto-add index
230
- t.references :ground, null: false, index: false ## Note: do NOT auto-add index
231
- t.timestamps
232
- end
233
-
234
- add_index :events_grounds, [:event_id, :ground_id], unique: true
235
- add_index :events_grounds, :event_id
236
-
237
-
238
-
239
- create_table :groups_teams do |t|
240
- t.references :group, null: false, index: false ## Note: do NOT auto-add index
241
- t.references :team, null: false, index: false ## Note: do NOT auto-add index
242
- t.timestamps
243
- end
244
-
245
- add_index :groups_teams, [:group_id, :team_id], unique: true
246
- add_index :groups_teams, :group_id
247
-
248
-
249
- ### todo: add models and some seed data
250
-
251
- create_table :seasons do |t| ## also used for years
252
- t.string :key, null: false
253
- t.string :title, null: false # e.g. 2011/12, 2012/13 ### what to do w/ 2012? for world cup etc?
254
- t.timestamps
255
- end
256
-
257
- create_table :leagues do |t| ## also for cups/conferences/tournaments/world series/etc.
258
- t.string :key, null: false
259
- t.string :title, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
260
- t.references :country ## optional for now , :null => false ### todo: create "virtual" country for international leagues e.g. use int? or world (ww?)/europe (eu)/etc. similar? already taken??
261
-
262
- ## fix: rename to :clubs from :club
263
- t.boolean :club, null: false, default: false # club teams or national teams?
264
- ## todo: add t.boolean :national flag? for national teams?
265
- ## t.boolean :international, :null => false, :default => false # national league or international?
266
- ## t.boolean :cup ## or regular season league??
267
- t.timestamps
268
- end
269
-
270
- create_table :badges do |t|
271
- t.references :team, null: false
272
- ## todo/fix: use event insead of league+season ??
273
- ## t.references :event, :null => false # event => league+season
274
- t.references :league, null: false
275
- t.references :season, null: false
276
- t.string :title, null: false # Meister, Weltmeister, Europameister, Cupsieger, Vize-Meister, Aufsteiger, Absteiger, etc.
277
- t.timestamps
278
- end
279
-
280
-
281
- create_table :assocs do |t|
282
- t.string :key, null: false
283
- t.string :title, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
284
-
285
- t.integer :since # founding year
286
- t.string :web
287
-
288
- ### if national assoc - has (optional) country ref
289
- t.references :country # note: optional - only used/set (required) for national assocs (or subnational too?)
290
- t.boolean :national, null: false, default: false
291
-
292
- ## add :world flag for FIFA? - just check if parent is null? for root assoc(s)? why? why not?
293
- ## add :regional flag for continental subdivision?
294
- t.boolean :continental, null: false, default: false
295
- t.boolean :intercontinental, null: false, default: false # e.g. arab football league (africa+western asia/middle east)
296
- t.timestamps
297
- end
298
-
299
- add_index :assocs, :key, unique: true
300
-
301
-
302
-
303
- create_table :assocs_assocs do |t|
304
- t.references :assoc1, null: false, index: false ## Note: do NOT auto-add index -- parent assoc
305
- t.references :assoc2, null: false, index: false ## Note: do NOT auto-add index -- child assoc is_member_of parent assoc
306
- t.timestamps
307
- end
308
-
309
- add_index :assocs_assocs, [:assoc1_id,:assoc2_id], unique: true
310
- add_index :assocs_assocs, :assoc1_id
311
- add_index :assocs_assocs, :assoc2_id
312
-
313
-
314
-
315
- ############################################
316
- # stats tables
317
-
318
- # use tables for standings e.g group_tables? - why? why not?
319
- #
320
- # todo: add group_standings per round with pos diffs e.g +1,+2, -3 etc.
321
-
322
- create_table :group_standings do |t|
323
- t.references :group, null: false
324
- t.timestamps
325
- end
326
-
327
- ### use items instead of entries - why (shorter! simple plural e.g. just add s)
328
-
329
- create_table :group_standing_entries do |t|
330
- t.references :group_standing, null: false
331
- t.references :team, null: false
332
- t.integer :pos
333
- t.integer :played
334
- t.integer :won
335
- t.integer :lost
336
- t.integer :drawn
337
- t.integer :goals_for # todo: find a short name - gf? why? why not?
338
- t.integer :goals_against # todo: find a shorter name - ga? why? why not?
339
- t.integer :pts
340
- t.string :comments
341
- t.timestamps
342
- end
343
-
344
-
345
- create_table :event_standings do |t|
346
- t.references :event, null: false
347
- t.timestamps
348
- end
349
-
350
- create_table :event_standing_entries do |t|
351
- t.references :event_standing, null: false
352
- t.references :team, null: false
353
- t.integer :pos
354
- t.integer :played
355
- t.integer :won
356
- t.integer :lost
357
- t.integer :drawn
358
- t.integer :goals_for # todo: find a short name - gf? or for? why? why not?
359
- t.integer :goals_against # todo: find a shorter name - ga? or against? why? why not?
360
- t.integer :pts
361
- t.string :comments
362
- t.timestamps
363
- end
364
-
365
-
366
- ## flex (free-style/form) standings table - lets you add as many events as you like (not bound to single event/season/etc.)
367
- ## -use (find a better) a different name? why? why not?
368
- create_table :alltime_standings do |t|
369
- t.string :key, null: false
370
- t.string :title, null: false
371
- t.timestamps
372
- end
373
-
374
- create_table :alltime_standing_entries do |t|
375
- t.references :alltime_standing, null: false
376
- t.references :team, null: false
377
- t.integer :pos
378
- t.integer :played # todo: use a different name - why? why not?
379
- t.integer :won
380
- t.integer :lost
381
- t.integer :drawn
382
- t.integer :goals_for # todo: find a short name - gf? why? why not?
383
- t.integer :goals_against # todo: find a shorter name - ga? why? why not?
384
- t.integer :pts
385
- t.integer :recs # note: specific to alltime - stats records counter (e.g. appearance counter)
386
- t.string :comments
387
- t.timestamps
388
- end
389
-
390
-
391
- end # Schema.define
392
- end # method up
393
-
394
-
395
- end # class CreateDb
396
-
397
- end # module SportDb