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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2dca58496a25d977a305dabb59fb4068f6a27d0
|
4
|
+
data.tar.gz: 454d482974847f5fee5d025e03449f9058c0b48f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2588e9757f5277b9f2088cd4b2222cb2712372a25b8ab01cb8346ae908c6c2c8ea8e3a7b9dd3e93d2a69117d30158dfc92a1d914dcb638826d34ecbf90619ecb
|
7
|
+
data.tar.gz: 517e715c5c132c1ae5e9c5794ec91f556a5b2bc56efe3b9429df1f4f50cdecc0bd3fcf48a3bae7c41e3407eeb2198a744a2aec1004ac6968d34e61aa3b36470a
|
data/CHANGELOG.md
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
### 0.4.0 / 2012-10-16
|
2
|
-
|
3
|
-
* Add plain text fixture reader/loader
|
4
|
-
* Add --generate/g option for generating fixtures from the DB using templates
|
5
|
-
|
6
|
-
### 0.3.1 / 2012-10-14
|
7
|
-
|
8
|
-
* Move models into its own namespace, that is, SportDB::Models
|
9
|
-
* Add ActiveRecord logging for --verbose option
|
10
|
-
|
11
|
-
### 0.3.0 / 2012-10-07
|
12
|
-
|
13
|
-
* Add --delete option to delete all records
|
14
|
-
|
15
|
-
### 0.2.0 / 2012-10-06
|
16
|
-
|
17
|
-
* Add --load option for builtin fixtures
|
18
|
-
|
19
|
-
### 0.1.0 / 2012-10-06
|
20
|
-
|
1
|
+
### 0.4.0 / 2012-10-16
|
2
|
+
|
3
|
+
* Add plain text fixture reader/loader
|
4
|
+
* Add --generate/g option for generating fixtures from the DB using templates
|
5
|
+
|
6
|
+
### 0.3.1 / 2012-10-14
|
7
|
+
|
8
|
+
* Move models into its own namespace, that is, SportDB::Models
|
9
|
+
* Add ActiveRecord logging for --verbose option
|
10
|
+
|
11
|
+
### 0.3.0 / 2012-10-07
|
12
|
+
|
13
|
+
* Add --delete option to delete all records
|
14
|
+
|
15
|
+
### 0.2.0 / 2012-10-06
|
16
|
+
|
17
|
+
* Add --load option for builtin fixtures
|
18
|
+
|
19
|
+
### 0.1.0 / 2012-10-06
|
20
|
+
|
21
21
|
* Everything is new. First release
|
data/README.md
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
# sportdb-models gem - sport.db schema 'n' models for easy (re)use
|
2
|
-
|
3
|
-
<!--
|
4
|
-
[![Build Status](https://secure.travis-ci.org/geraldb/sport.db.ruby.png?branch=master)](http://travis-ci.org/geraldb/sport.db.ruby)
|
5
|
-
-->
|
6
|
-
|
7
|
-
* home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
|
8
|
-
* bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
|
9
|
-
* gem :: [rubygems.org/gems/sportdb-models](https://rubygems.org/gems/sportdb-models)
|
10
|
-
* rdoc :: [rubydoc.info/gems/sportdb-models](http://rubydoc.info/gems/sportdb-models)
|
11
|
-
* forum :: [groups.google.com/group/opensport](https://groups.google.com/group/opensport)
|
12
|
-
|
13
|
-
|
14
|
-
## Usage Models
|
15
|
-
|
16
|
-
![](sportdb-models.png)
|
17
|
-
|
18
|
-
|
19
|
-
## License
|
20
|
-
|
21
|
-
![](https://publicdomainworks.github.io/buttons/zero88x31.png)
|
22
|
-
|
23
|
-
The `sportdb-models` scripts are dedicated to the public domain.
|
24
|
-
Use it as you please with no restrictions whatsoever.
|
25
|
-
|
26
|
-
|
27
|
-
## Questions? Comments?
|
28
|
-
|
29
|
-
Send them along to the
|
30
|
-
[Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
|
31
|
-
Thanks!
|
1
|
+
# sportdb-models gem - sport.db schema 'n' models for easy (re)use
|
2
|
+
|
3
|
+
<!--
|
4
|
+
[![Build Status](https://secure.travis-ci.org/geraldb/sport.db.ruby.png?branch=master)](http://travis-ci.org/geraldb/sport.db.ruby)
|
5
|
+
-->
|
6
|
+
|
7
|
+
* home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
|
8
|
+
* bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
|
9
|
+
* gem :: [rubygems.org/gems/sportdb-models](https://rubygems.org/gems/sportdb-models)
|
10
|
+
* rdoc :: [rubydoc.info/gems/sportdb-models](http://rubydoc.info/gems/sportdb-models)
|
11
|
+
* forum :: [groups.google.com/group/opensport](https://groups.google.com/group/opensport)
|
12
|
+
|
13
|
+
|
14
|
+
## Usage Models
|
15
|
+
|
16
|
+
![](sportdb-models.png)
|
17
|
+
|
18
|
+
|
19
|
+
## License
|
20
|
+
|
21
|
+
![](https://publicdomainworks.github.io/buttons/zero88x31.png)
|
22
|
+
|
23
|
+
The `sportdb-models` scripts are dedicated to the public domain.
|
24
|
+
Use it as you please with no restrictions whatsoever.
|
25
|
+
|
26
|
+
|
27
|
+
## Questions? Comments?
|
28
|
+
|
29
|
+
Send them along to the
|
30
|
+
[Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
|
31
|
+
Thanks!
|
data/Rakefile
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
require 'hoe'
|
2
|
-
require './lib/sportdb/models/version.rb'
|
3
|
-
|
4
|
-
|
5
|
-
Hoe.spec 'sportdb-models' do
|
6
|
-
|
7
|
-
self.version = SportDb::Module::Models::VERSION
|
8
|
-
|
9
|
-
self.summary = "sportdb-models - sport.db schema 'n' models for easy (re)use"
|
10
|
-
self.description = summary
|
11
|
-
|
12
|
-
self.urls =
|
13
|
-
|
14
|
-
self.author = 'Gerald Bauer'
|
15
|
-
self.email = 'opensport@googlegroups.com'
|
16
|
-
|
17
|
-
# switch extension to .markdown for gihub formatting
|
18
|
-
# -- NB: auto-changed when included in manifest
|
19
|
-
self.readme_file = 'README.md'
|
20
|
-
self.history_file = 'CHANGELOG.md'
|
21
|
-
|
22
|
-
self.extra_deps = [
|
23
|
-
['worlddb-models', '>= 2.4.0'], # Note: pull in all (extra) dependencies va worlddb-models
|
24
|
-
['persondb-models', '>= 0.5.0'], # persons (people) table
|
25
|
-
]
|
26
|
-
|
27
|
-
self.licenses = ['Public Domain']
|
28
|
-
|
29
|
-
self.spec_extras = {
|
30
|
-
required_ruby_version: '>= 2.2.2'
|
31
|
-
}
|
32
|
-
end
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/sportdb/models/version.rb'
|
3
|
+
|
4
|
+
|
5
|
+
Hoe.spec 'sportdb-models' do
|
6
|
+
|
7
|
+
self.version = SportDb::Module::Models::VERSION
|
8
|
+
|
9
|
+
self.summary = "sportdb-models - sport.db schema 'n' models for easy (re)use"
|
10
|
+
self.description = summary
|
11
|
+
|
12
|
+
self.urls = { home: 'https://github.com/sportdb/sport.db' }
|
13
|
+
|
14
|
+
self.author = 'Gerald Bauer'
|
15
|
+
self.email = 'opensport@googlegroups.com'
|
16
|
+
|
17
|
+
# switch extension to .markdown for gihub formatting
|
18
|
+
# -- NB: auto-changed when included in manifest
|
19
|
+
self.readme_file = 'README.md'
|
20
|
+
self.history_file = 'CHANGELOG.md'
|
21
|
+
|
22
|
+
self.extra_deps = [
|
23
|
+
['worlddb-models', '>= 2.4.0'], # Note: pull in all (extra) dependencies va worlddb-models
|
24
|
+
['persondb-models', '>= 0.5.0'], # persons (people) table
|
25
|
+
]
|
26
|
+
|
27
|
+
self.licenses = ['Public Domain']
|
28
|
+
|
29
|
+
self.spec_extras = {
|
30
|
+
required_ruby_version: '>= 2.2.2'
|
31
|
+
}
|
32
|
+
end
|
data/lib/sportdb/models.rb
CHANGED
@@ -1,179 +1,212 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
require 'sportdb/models/
|
12
|
-
|
13
|
-
require 'sportdb/models/
|
14
|
-
require 'sportdb/models/models/
|
15
|
-
|
16
|
-
require 'sportdb/models/models/world/
|
17
|
-
|
18
|
-
require 'sportdb/models/models/
|
19
|
-
require 'sportdb/models/models/
|
20
|
-
|
21
|
-
require 'sportdb/models/models/
|
22
|
-
require 'sportdb/models/models/
|
23
|
-
require 'sportdb/models/models/
|
24
|
-
require 'sportdb/models/models/
|
25
|
-
require 'sportdb/models/models/
|
26
|
-
require 'sportdb/models/models/
|
27
|
-
require 'sportdb/models/models/
|
28
|
-
require 'sportdb/models/models/
|
29
|
-
require 'sportdb/models/models/
|
30
|
-
require 'sportdb/models/models/
|
31
|
-
require 'sportdb/models/models/
|
32
|
-
|
33
|
-
require 'sportdb/models/models/
|
34
|
-
require 'sportdb/models/models/
|
35
|
-
|
36
|
-
|
37
|
-
require 'sportdb/models/models
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
require 'sportdb/models/
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
##
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
##
|
177
|
-
|
178
|
-
|
179
|
-
|
1
|
+
# core and stlibs (note: get included via worlddb-models gem; see worlddb-models gem/lib)
|
2
|
+
require 'worlddb/models' # NOTE: include worlddb-models gem (not cli tools gem, that is, worlddb)
|
3
|
+
require 'persondb/models'
|
4
|
+
|
5
|
+
|
6
|
+
# our own code
|
7
|
+
|
8
|
+
require 'sportdb/models/version' # let version always go first
|
9
|
+
|
10
|
+
require 'sportdb/models/formats'
|
11
|
+
require 'sportdb/models/models/forward'
|
12
|
+
|
13
|
+
require 'sportdb/models/models/world/city'
|
14
|
+
require 'sportdb/models/models/world/country'
|
15
|
+
require 'sportdb/models/models/world/continent'
|
16
|
+
require 'sportdb/models/models/world/state'
|
17
|
+
|
18
|
+
require 'sportdb/models/models/assoc'
|
19
|
+
require 'sportdb/models/models/badge'
|
20
|
+
require 'sportdb/models/models/event'
|
21
|
+
require 'sportdb/models/models/goal'
|
22
|
+
require 'sportdb/models/models/ground'
|
23
|
+
require 'sportdb/models/models/group'
|
24
|
+
require 'sportdb/models/models/league'
|
25
|
+
require 'sportdb/models/models/lineup'
|
26
|
+
require 'sportdb/models/models/match'
|
27
|
+
require 'sportdb/models/models/person'
|
28
|
+
require 'sportdb/models/models/round'
|
29
|
+
require 'sportdb/models/models/season'
|
30
|
+
require 'sportdb/models/models/stage'
|
31
|
+
require 'sportdb/models/models/team'
|
32
|
+
|
33
|
+
require 'sportdb/models/models/stats/alltime_standing'
|
34
|
+
require 'sportdb/models/models/stats/event_standing'
|
35
|
+
require 'sportdb/models/models/stats/group_standing'
|
36
|
+
|
37
|
+
require 'sportdb/models/schema' # note: requires sportdb/models (include SportDB::Models)
|
38
|
+
|
39
|
+
require 'sportdb/models/utils' # e.g. MatchCursor
|
40
|
+
|
41
|
+
require 'sportdb/models/deleter'
|
42
|
+
require 'sportdb/models/stats'
|
43
|
+
|
44
|
+
|
45
|
+
module SportDb
|
46
|
+
|
47
|
+
def self.create
|
48
|
+
CreateDb.new.up
|
49
|
+
ConfDb::Model::Prop.create!( key: 'db.schema.sport.version', value: VERSION )
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.create_all
|
53
|
+
## build schema - convenience helper
|
54
|
+
LogDb.create
|
55
|
+
ConfDb.create
|
56
|
+
TagDb.create
|
57
|
+
WorldDb.create
|
58
|
+
PersonDb.create
|
59
|
+
SportDb.create
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.auto_migrate!
|
63
|
+
### todo/fix:
|
64
|
+
## check props table and versions!!!!!
|
65
|
+
|
66
|
+
# first time? - auto-run db migratation, that is, create db tables
|
67
|
+
unless LogDb::Model::Log.table_exists?
|
68
|
+
LogDb.create # add logs table
|
69
|
+
end
|
70
|
+
|
71
|
+
unless ConfDb::Model::Prop.table_exists?
|
72
|
+
ConfDb.create # add props table
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
unless TagDb::Model::Tag.table_exists?
|
77
|
+
TagDb.create # add tags & taggings tables
|
78
|
+
end
|
79
|
+
|
80
|
+
unless WorldDb::Model::Place.table_exists?
|
81
|
+
WorldDb.create # add places, & co. tables
|
82
|
+
end
|
83
|
+
|
84
|
+
unless PersonDb::Model::Person.table_exists?
|
85
|
+
PersonDb.create # add persons table
|
86
|
+
end
|
87
|
+
|
88
|
+
unless SportDb::Model::League.table_exists?
|
89
|
+
SportDb.create
|
90
|
+
end
|
91
|
+
end # method auto_migrate!
|
92
|
+
|
93
|
+
|
94
|
+
# delete ALL records (use with care!)
|
95
|
+
def self.delete!
|
96
|
+
puts '*** deleting sport table records/data...'
|
97
|
+
Deleter.new.run
|
98
|
+
end # method delete!
|
99
|
+
|
100
|
+
|
101
|
+
def self.tables
|
102
|
+
Stats.new.tables
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def self.connect!( config={} ) # convenience shortcut w/ automigrate
|
107
|
+
connect( config )
|
108
|
+
auto_migrate!
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.connect( config={} )
|
112
|
+
if config.empty?
|
113
|
+
puts "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"
|
114
|
+
|
115
|
+
### change default to ./sport.db ?? why? why not?
|
116
|
+
db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///sport.db' )
|
117
|
+
|
118
|
+
config = if db.scheme == 'postgres'
|
119
|
+
{ adapter: 'postgresql',
|
120
|
+
host: db.host,
|
121
|
+
port: db.port,
|
122
|
+
username: db.user,
|
123
|
+
password: db.password,
|
124
|
+
database: db.path[1..-1],
|
125
|
+
encoding: 'utf8'
|
126
|
+
}
|
127
|
+
else # assume sqlite3
|
128
|
+
{ adapter: db.scheme, # sqlite3
|
129
|
+
database: db.path[1..-1] # sport.db (NB: cut off leading /, thus 1..-1)
|
130
|
+
}
|
131
|
+
end
|
132
|
+
else
|
133
|
+
## note: for compatibility lets you also pass-in/use string keys
|
134
|
+
## e.g. YAML.load uses/returns always string keys - always auto-convert to symbols
|
135
|
+
config = config.symbolize_keys
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
## todo/check/fix: move jruby "hack" to attic - why? why not?
|
140
|
+
## todo/check: use if defined?( JRUBY_VERSION ) instead ??
|
141
|
+
## if RUBY_PLATFORM =~ /java/ && config[:adapter] == 'sqlite3'
|
142
|
+
# quick hack for JRuby sqlite3 support via jdbc
|
143
|
+
## puts "jruby quick hack - adding jdbc libs for jruby sqlite3 database support"
|
144
|
+
## require 'jdbc/sqlite3'
|
145
|
+
## require 'active_record/connection_adapters/jdbc_adapter'
|
146
|
+
## require 'active_record/connection_adapters/jdbcsqlite3_adapter'
|
147
|
+
## end
|
148
|
+
|
149
|
+
puts "Connecting to db using settings: "
|
150
|
+
pp config
|
151
|
+
ActiveRecord::Base.establish_connection( config )
|
152
|
+
# ActiveRecord::Base.logger = Logger.new( STDOUT )
|
153
|
+
|
154
|
+
## if sqlite3 add (use) some pragmas for speedups
|
155
|
+
if config[:adapter] == 'sqlite3' &&
|
156
|
+
config[:database] != ':memory:'
|
157
|
+
## note: if in memory database e.g. ':memory:' no pragma needed!!
|
158
|
+
## try to speed up sqlite
|
159
|
+
## see http://www.sqlite.org/pragma.html
|
160
|
+
con = ActiveRecord::Base.connection
|
161
|
+
con.execute( 'PRAGMA synchronous=OFF;' )
|
162
|
+
con.execute( 'PRAGMA journal_mode=OFF;' )
|
163
|
+
con.execute( 'PRAGMA temp_store=MEMORY;' )
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
def self.setup_in_memory_db
|
169
|
+
# Database Setup & Config
|
170
|
+
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
171
|
+
## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
|
172
|
+
|
173
|
+
connect( adapter: 'sqlite3',
|
174
|
+
database: ':memory:' )
|
175
|
+
|
176
|
+
## build schema
|
177
|
+
create_all
|
178
|
+
end # setup_in_memory_db (using SQLite :memory:)
|
179
|
+
|
180
|
+
|
181
|
+
end # module SportDb
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
module SportDb
|
186
|
+
module Model
|
187
|
+
##################
|
188
|
+
# add alias why? why not?
|
189
|
+
#
|
190
|
+
# more aliases to consider:
|
191
|
+
# - Tournament for Event?
|
192
|
+
# - Cup for League?
|
193
|
+
# - Roster for Lineup?
|
194
|
+
# - Stadium for Ground? - why? why not?
|
195
|
+
|
196
|
+
|
197
|
+
Competition = Event
|
198
|
+
Comp = Event
|
199
|
+
|
200
|
+
LineUp = Lineup
|
201
|
+
Squad = Lineup
|
202
|
+
|
203
|
+
Game = Match ## add (old) alias - why? why not?
|
204
|
+
end # module Model
|
205
|
+
end # module SportDb
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
## say hello
|
210
|
+
puts SportDb::Module::Models.banner
|
211
|
+
|
212
|
+
|