schema_plus 0.2.1 → 0.3.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.
- data/README.rdoc +32 -3
- data/gemfiles/Gemfile.rails-2.3 +1 -1
- data/gemfiles/Gemfile.rails-2.3.lock +15 -15
- data/gemfiles/Gemfile.rails-3.0.lock +41 -41
- data/gemfiles/Gemfile.rails-3.1 +1 -1
- data/gemfiles/Gemfile.rails-3.1.lock +46 -46
- data/gemfiles/Gemfile.rails-3.2 +1 -1
- data/gemfiles/Gemfile.rails-3.2.lock +49 -49
- data/lib/schema_plus.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/abstract_adapter.rb +41 -1
- data/lib/schema_plus/active_record/connection_adapters/column.rb +1 -0
- data/lib/schema_plus/active_record/connection_adapters/mysql_adapter.rb +6 -0
- data/lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb +44 -0
- data/lib/schema_plus/active_record/connection_adapters/sqlite3_adapter.rb +19 -0
- data/lib/schema_plus/active_record/schema_dumper.rb +7 -1
- data/lib/schema_plus/version.rb +1 -1
- data/runspecs +8 -2
- data/spec/column_definition_spec.rb +99 -0
- data/spec/foreign_key_spec.rb +2 -0
- data/spec/index_spec.rb +1 -1
- data/spec/migration_spec.rb +4 -0
- data/spec/rails3_migration_spec.rb +6 -0
- data/spec/schema_dumper_spec.rb +58 -1
- data/spec/schema_spec.rb +11 -2
- data/spec/views_spec.rb +8 -4
- metadata +23 -20
data/README.rdoc
CHANGED
@@ -11,11 +11,11 @@ For added rails DRYness see also the gems
|
|
11
11
|
== Compatibility
|
12
12
|
|
13
13
|
SchemaPlus supports all combinations of:
|
14
|
-
* rails 2.3, 3.0, or 3.1
|
15
|
-
* MRI ruby 1.8.7 or 1.9.
|
14
|
+
* rails 2.3, 3.0, or 3.1, or 3.2
|
15
|
+
* MRI ruby 1.8.7, 1.9.2 or 1.9.3
|
16
16
|
* PostgreSQL, MySQL (using mysql or mysql2 gem), or SQLite3 (using sqlite3 3.7.7 which has foreign key support)
|
17
17
|
|
18
|
-
Support for rails 2.3 will likely be dropped
|
18
|
+
Support for rails 2.3 will likely be dropped eventually.
|
19
19
|
|
20
20
|
== Installation
|
21
21
|
|
@@ -120,6 +120,33 @@ ActiveRecord works with views the same as with ordinary tables. That is, for th
|
|
120
120
|
class UncommentedPosts < ActiveRecord::Base
|
121
121
|
end
|
122
122
|
|
123
|
+
=== Column Defaults
|
124
|
+
|
125
|
+
SchemaPlus allows expressions to be used as column defaults. For example:
|
126
|
+
|
127
|
+
t.datetime :seen_at, :default => :now
|
128
|
+
|
129
|
+
resolves to
|
130
|
+
|
131
|
+
DEFAULT NOW() # PostgreSQL
|
132
|
+
(DATETIME('now')) # SQLite3
|
133
|
+
invalid # MySQL
|
134
|
+
|
135
|
+
Arbitrary SQL expressions can also be specified by passing a hash with an :expr parameter:
|
136
|
+
|
137
|
+
t.datetime :seen_at, :default => { :expr => 'NOW()' }
|
138
|
+
|
139
|
+
In MySQL only the TIMESTAMP column accepts SQL column defaults and Rails uses DATETIME,
|
140
|
+
so this is not possible at this time.
|
141
|
+
|
142
|
+
Standard default values can be specified verbosely:
|
143
|
+
|
144
|
+
t.datetime :seen_at, :default => { :value => "2011-12-11 00:00:00" }
|
145
|
+
|
146
|
+
But the standard syntax will still work as usual:
|
147
|
+
|
148
|
+
t.datetime :seen_at, :default => "2011-12-11 00:00:00"
|
149
|
+
|
123
150
|
=== Schema Dump and Load (schema.rb)
|
124
151
|
|
125
152
|
When dumping <tt>schema.rb</tt>, SchemaPlus orders the views and tables in
|
@@ -149,6 +176,7 @@ take advantage of auto-creation of foreign keys, you can re-enable it:
|
|
149
176
|
== History
|
150
177
|
|
151
178
|
* Recent Release notes:
|
179
|
+
* 0.3.0 - add :default => expressions (Thanks to Luke Saunders). support rails 3.2 and ruby 1.9.3
|
152
180
|
* 0.2.1 - suppress duplicate add_indexes. compatibility with rails 3.2.0.rc2
|
153
181
|
|
154
182
|
* SchemaPlus is derived from several "Red Hill On Rails" plugins
|
@@ -158,6 +186,7 @@ take advantage of auto-creation of foreign keys, you can re-enable it:
|
|
158
186
|
* François Beausoleil (https://github.com/francois)
|
159
187
|
* Greg Barnett (https://github.com/greg-barnett)
|
160
188
|
* Ronen Barzel (https://github.com/ronen)
|
189
|
+
* Luke Suanders (https://github.com/lukesaunders)
|
161
190
|
|
162
191
|
* SchemaPlus was created in 2011 by Michał Łomnicki and Ronen Barzel
|
163
192
|
|
data/gemfiles/Gemfile.rails-2.3
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/ronen/github/schema_plus
|
3
3
|
specs:
|
4
|
-
schema_plus (0.2.
|
4
|
+
schema_plus (0.2.1)
|
5
5
|
rails
|
6
6
|
valuable
|
7
7
|
|
@@ -19,10 +19,10 @@ GEM
|
|
19
19
|
activesupport (= 2.3.14)
|
20
20
|
activesupport (2.3.14)
|
21
21
|
diff-lcs (1.1.3)
|
22
|
-
multi_json (1.0
|
22
|
+
multi_json (1.1.0)
|
23
23
|
mysql (2.8.1)
|
24
24
|
mysql2 (0.2.18)
|
25
|
-
pg (0.
|
25
|
+
pg (0.13.2)
|
26
26
|
rack (1.1.3)
|
27
27
|
rails (2.3.14)
|
28
28
|
actionmailer (= 2.3.14)
|
@@ -32,22 +32,22 @@ GEM
|
|
32
32
|
activesupport (= 2.3.14)
|
33
33
|
rake (>= 0.8.3)
|
34
34
|
rake (0.8.7)
|
35
|
-
rspec (2.
|
36
|
-
rspec-core (~> 2.
|
37
|
-
rspec-expectations (~> 2.
|
38
|
-
rspec-mocks (~> 2.
|
39
|
-
rspec-core (2.
|
40
|
-
rspec-expectations (2.
|
41
|
-
diff-lcs (~> 1.1.
|
42
|
-
rspec-mocks (2.
|
43
|
-
simplecov (0.
|
44
|
-
multi_json (~> 1.0
|
35
|
+
rspec (2.9.0)
|
36
|
+
rspec-core (~> 2.9.0)
|
37
|
+
rspec-expectations (~> 2.9.0)
|
38
|
+
rspec-mocks (~> 2.9.0)
|
39
|
+
rspec-core (2.9.0)
|
40
|
+
rspec-expectations (2.9.0)
|
41
|
+
diff-lcs (~> 1.1.3)
|
42
|
+
rspec-mocks (2.9.0)
|
43
|
+
simplecov (0.6.1)
|
44
|
+
multi_json (~> 1.0)
|
45
45
|
simplecov-html (~> 0.5.3)
|
46
46
|
simplecov-gem-adapter (1.0.1)
|
47
47
|
simplecov
|
48
48
|
simplecov-html (0.5.3)
|
49
49
|
sqlite3 (1.3.5)
|
50
|
-
valuable (0.9.
|
50
|
+
valuable (0.9.3)
|
51
51
|
|
52
52
|
PLATFORMS
|
53
53
|
ruby
|
@@ -56,7 +56,7 @@ DEPENDENCIES
|
|
56
56
|
mysql
|
57
57
|
mysql2 (~> 0.2.7)
|
58
58
|
pg
|
59
|
-
rails (~> 2.3)
|
59
|
+
rails (~> 2.3.0)
|
60
60
|
rake (~> 0.8.7)
|
61
61
|
rspec
|
62
62
|
schema_plus!
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/ronen/github/schema_plus
|
3
3
|
specs:
|
4
|
-
schema_plus (0.2.
|
4
|
+
schema_plus (0.2.1)
|
5
5
|
rails
|
6
6
|
valuable
|
7
7
|
|
@@ -9,82 +9,82 @@ GEM
|
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
11
|
abstract (1.0.0)
|
12
|
-
actionmailer (3.0.
|
13
|
-
actionpack (= 3.0.
|
12
|
+
actionmailer (3.0.12)
|
13
|
+
actionpack (= 3.0.12)
|
14
14
|
mail (~> 2.2.19)
|
15
|
-
actionpack (3.0.
|
16
|
-
activemodel (= 3.0.
|
17
|
-
activesupport (= 3.0.
|
15
|
+
actionpack (3.0.12)
|
16
|
+
activemodel (= 3.0.12)
|
17
|
+
activesupport (= 3.0.12)
|
18
18
|
builder (~> 2.1.2)
|
19
19
|
erubis (~> 2.6.6)
|
20
20
|
i18n (~> 0.5.0)
|
21
|
-
rack (~> 1.2.
|
21
|
+
rack (~> 1.2.5)
|
22
22
|
rack-mount (~> 0.6.14)
|
23
23
|
rack-test (~> 0.5.7)
|
24
24
|
tzinfo (~> 0.3.23)
|
25
|
-
activemodel (3.0.
|
26
|
-
activesupport (= 3.0.
|
25
|
+
activemodel (3.0.12)
|
26
|
+
activesupport (= 3.0.12)
|
27
27
|
builder (~> 2.1.2)
|
28
28
|
i18n (~> 0.5.0)
|
29
|
-
activerecord (3.0.
|
30
|
-
activemodel (= 3.0.
|
31
|
-
activesupport (= 3.0.
|
29
|
+
activerecord (3.0.12)
|
30
|
+
activemodel (= 3.0.12)
|
31
|
+
activesupport (= 3.0.12)
|
32
32
|
arel (~> 2.0.10)
|
33
33
|
tzinfo (~> 0.3.23)
|
34
|
-
activeresource (3.0.
|
35
|
-
activemodel (= 3.0.
|
36
|
-
activesupport (= 3.0.
|
37
|
-
activesupport (3.0.
|
34
|
+
activeresource (3.0.12)
|
35
|
+
activemodel (= 3.0.12)
|
36
|
+
activesupport (= 3.0.12)
|
37
|
+
activesupport (3.0.12)
|
38
38
|
arel (2.0.10)
|
39
39
|
builder (2.1.2)
|
40
40
|
diff-lcs (1.1.3)
|
41
41
|
erubis (2.6.6)
|
42
42
|
abstract (>= 1.0.0)
|
43
43
|
i18n (0.5.0)
|
44
|
-
json (1.6.
|
44
|
+
json (1.6.5)
|
45
45
|
mail (2.2.19)
|
46
46
|
activesupport (>= 2.3.6)
|
47
47
|
i18n (>= 0.4.0)
|
48
48
|
mime-types (~> 1.16)
|
49
49
|
treetop (~> 1.4.8)
|
50
50
|
mime-types (1.17.2)
|
51
|
-
multi_json (1.0
|
51
|
+
multi_json (1.1.0)
|
52
52
|
mysql (2.8.1)
|
53
53
|
mysql2 (0.2.18)
|
54
|
-
pg (0.
|
54
|
+
pg (0.13.2)
|
55
55
|
polyglot (0.3.3)
|
56
56
|
rack (1.2.5)
|
57
57
|
rack-mount (0.6.14)
|
58
58
|
rack (>= 1.0.0)
|
59
59
|
rack-test (0.5.7)
|
60
60
|
rack (>= 1.0)
|
61
|
-
rails (3.0.
|
62
|
-
actionmailer (= 3.0.
|
63
|
-
actionpack (= 3.0.
|
64
|
-
activerecord (= 3.0.
|
65
|
-
activeresource (= 3.0.
|
66
|
-
activesupport (= 3.0.
|
61
|
+
rails (3.0.12)
|
62
|
+
actionmailer (= 3.0.12)
|
63
|
+
actionpack (= 3.0.12)
|
64
|
+
activerecord (= 3.0.12)
|
65
|
+
activeresource (= 3.0.12)
|
66
|
+
activesupport (= 3.0.12)
|
67
67
|
bundler (~> 1.0)
|
68
|
-
railties (= 3.0.
|
69
|
-
railties (3.0.
|
70
|
-
actionpack (= 3.0.
|
71
|
-
activesupport (= 3.0.
|
68
|
+
railties (= 3.0.12)
|
69
|
+
railties (3.0.12)
|
70
|
+
actionpack (= 3.0.12)
|
71
|
+
activesupport (= 3.0.12)
|
72
72
|
rake (>= 0.8.7)
|
73
73
|
rdoc (~> 3.4)
|
74
74
|
thor (~> 0.14.4)
|
75
75
|
rake (0.8.7)
|
76
76
|
rdoc (3.12)
|
77
77
|
json (~> 1.4)
|
78
|
-
rspec (2.
|
79
|
-
rspec-core (~> 2.
|
80
|
-
rspec-expectations (~> 2.
|
81
|
-
rspec-mocks (~> 2.
|
82
|
-
rspec-core (2.
|
83
|
-
rspec-expectations (2.
|
84
|
-
diff-lcs (~> 1.1.
|
85
|
-
rspec-mocks (2.
|
86
|
-
simplecov (0.
|
87
|
-
multi_json (~> 1.0
|
78
|
+
rspec (2.9.0)
|
79
|
+
rspec-core (~> 2.9.0)
|
80
|
+
rspec-expectations (~> 2.9.0)
|
81
|
+
rspec-mocks (~> 2.9.0)
|
82
|
+
rspec-core (2.9.0)
|
83
|
+
rspec-expectations (2.9.0)
|
84
|
+
diff-lcs (~> 1.1.3)
|
85
|
+
rspec-mocks (2.9.0)
|
86
|
+
simplecov (0.6.1)
|
87
|
+
multi_json (~> 1.0)
|
88
88
|
simplecov-html (~> 0.5.3)
|
89
89
|
simplecov-gem-adapter (1.0.1)
|
90
90
|
simplecov
|
@@ -94,8 +94,8 @@ GEM
|
|
94
94
|
treetop (1.4.10)
|
95
95
|
polyglot
|
96
96
|
polyglot (>= 0.3.1)
|
97
|
-
tzinfo (0.3.
|
98
|
-
valuable (0.9.
|
97
|
+
tzinfo (0.3.32)
|
98
|
+
valuable (0.9.3)
|
99
99
|
|
100
100
|
PLATFORMS
|
101
101
|
ruby
|
data/gemfiles/Gemfile.rails-3.1
CHANGED
@@ -1,60 +1,60 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/ronen/github/schema_plus
|
3
3
|
specs:
|
4
|
-
schema_plus (0.2.
|
4
|
+
schema_plus (0.2.1)
|
5
5
|
rails
|
6
6
|
valuable
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionmailer (3.1.
|
12
|
-
actionpack (= 3.1.
|
11
|
+
actionmailer (3.1.4)
|
12
|
+
actionpack (= 3.1.4)
|
13
13
|
mail (~> 2.3.0)
|
14
|
-
actionpack (3.1.
|
15
|
-
activemodel (= 3.1.
|
16
|
-
activesupport (= 3.1.
|
14
|
+
actionpack (3.1.4)
|
15
|
+
activemodel (= 3.1.4)
|
16
|
+
activesupport (= 3.1.4)
|
17
17
|
builder (~> 3.0.0)
|
18
18
|
erubis (~> 2.7.0)
|
19
19
|
i18n (~> 0.6)
|
20
|
-
rack (~> 1.3.
|
20
|
+
rack (~> 1.3.6)
|
21
21
|
rack-cache (~> 1.1)
|
22
22
|
rack-mount (~> 0.8.2)
|
23
23
|
rack-test (~> 0.6.1)
|
24
24
|
sprockets (~> 2.0.3)
|
25
|
-
activemodel (3.1.
|
26
|
-
activesupport (= 3.1.
|
25
|
+
activemodel (3.1.4)
|
26
|
+
activesupport (= 3.1.4)
|
27
27
|
builder (~> 3.0.0)
|
28
28
|
i18n (~> 0.6)
|
29
|
-
activerecord (3.1.
|
30
|
-
activemodel (= 3.1.
|
31
|
-
activesupport (= 3.1.
|
32
|
-
arel (~> 2.2.
|
29
|
+
activerecord (3.1.4)
|
30
|
+
activemodel (= 3.1.4)
|
31
|
+
activesupport (= 3.1.4)
|
32
|
+
arel (~> 2.2.3)
|
33
33
|
tzinfo (~> 0.3.29)
|
34
|
-
activeresource (3.1.
|
35
|
-
activemodel (= 3.1.
|
36
|
-
activesupport (= 3.1.
|
37
|
-
activesupport (3.1.
|
34
|
+
activeresource (3.1.4)
|
35
|
+
activemodel (= 3.1.4)
|
36
|
+
activesupport (= 3.1.4)
|
37
|
+
activesupport (3.1.4)
|
38
38
|
multi_json (~> 1.0)
|
39
|
-
arel (2.2.
|
39
|
+
arel (2.2.3)
|
40
40
|
builder (3.0.0)
|
41
41
|
diff-lcs (1.1.3)
|
42
42
|
erubis (2.7.0)
|
43
43
|
hike (1.2.1)
|
44
44
|
i18n (0.6.0)
|
45
|
-
json (1.6.
|
46
|
-
mail (2.3.
|
45
|
+
json (1.6.5)
|
46
|
+
mail (2.3.3)
|
47
47
|
i18n (>= 0.4.0)
|
48
48
|
mime-types (~> 1.16)
|
49
49
|
treetop (~> 1.4.8)
|
50
50
|
mime-types (1.17.2)
|
51
|
-
multi_json (1.0
|
51
|
+
multi_json (1.1.0)
|
52
52
|
mysql (2.8.1)
|
53
53
|
mysql2 (0.3.11)
|
54
|
-
pg (0.
|
54
|
+
pg (0.13.2)
|
55
55
|
polyglot (0.3.3)
|
56
56
|
rack (1.3.6)
|
57
|
-
rack-cache (1.
|
57
|
+
rack-cache (1.2)
|
58
58
|
rack (>= 0.4)
|
59
59
|
rack-mount (0.8.3)
|
60
60
|
rack (>= 1.0.0)
|
@@ -62,17 +62,17 @@ GEM
|
|
62
62
|
rack
|
63
63
|
rack-test (0.6.1)
|
64
64
|
rack (>= 1.0)
|
65
|
-
rails (3.1.
|
66
|
-
actionmailer (= 3.1.
|
67
|
-
actionpack (= 3.1.
|
68
|
-
activerecord (= 3.1.
|
69
|
-
activeresource (= 3.1.
|
70
|
-
activesupport (= 3.1.
|
65
|
+
rails (3.1.4)
|
66
|
+
actionmailer (= 3.1.4)
|
67
|
+
actionpack (= 3.1.4)
|
68
|
+
activerecord (= 3.1.4)
|
69
|
+
activeresource (= 3.1.4)
|
70
|
+
activesupport (= 3.1.4)
|
71
71
|
bundler (~> 1.0)
|
72
|
-
railties (= 3.1.
|
73
|
-
railties (3.1.
|
74
|
-
actionpack (= 3.1.
|
75
|
-
activesupport (= 3.1.
|
72
|
+
railties (= 3.1.4)
|
73
|
+
railties (3.1.4)
|
74
|
+
actionpack (= 3.1.4)
|
75
|
+
activesupport (= 3.1.4)
|
76
76
|
rack-ssl (~> 1.3.2)
|
77
77
|
rake (>= 0.8.7)
|
78
78
|
rdoc (~> 3.4)
|
@@ -80,16 +80,16 @@ GEM
|
|
80
80
|
rake (0.8.7)
|
81
81
|
rdoc (3.12)
|
82
82
|
json (~> 1.4)
|
83
|
-
rspec (2.
|
84
|
-
rspec-core (~> 2.
|
85
|
-
rspec-expectations (~> 2.
|
86
|
-
rspec-mocks (~> 2.
|
87
|
-
rspec-core (2.
|
88
|
-
rspec-expectations (2.
|
89
|
-
diff-lcs (~> 1.1.
|
90
|
-
rspec-mocks (2.
|
91
|
-
simplecov (0.
|
92
|
-
multi_json (~> 1.0
|
83
|
+
rspec (2.9.0)
|
84
|
+
rspec-core (~> 2.9.0)
|
85
|
+
rspec-expectations (~> 2.9.0)
|
86
|
+
rspec-mocks (~> 2.9.0)
|
87
|
+
rspec-core (2.9.0)
|
88
|
+
rspec-expectations (2.9.0)
|
89
|
+
diff-lcs (~> 1.1.3)
|
90
|
+
rspec-mocks (2.9.0)
|
91
|
+
simplecov (0.6.1)
|
92
|
+
multi_json (~> 1.0)
|
93
93
|
simplecov-html (~> 0.5.3)
|
94
94
|
simplecov-gem-adapter (1.0.1)
|
95
95
|
simplecov
|
@@ -104,8 +104,8 @@ GEM
|
|
104
104
|
treetop (1.4.10)
|
105
105
|
polyglot
|
106
106
|
polyglot (>= 0.3.1)
|
107
|
-
tzinfo (0.3.
|
108
|
-
valuable (0.9.
|
107
|
+
tzinfo (0.3.32)
|
108
|
+
valuable (0.9.3)
|
109
109
|
|
110
110
|
PLATFORMS
|
111
111
|
ruby
|
@@ -114,7 +114,7 @@ DEPENDENCIES
|
|
114
114
|
mysql
|
115
115
|
mysql2
|
116
116
|
pg
|
117
|
-
rails (~> 3.1)
|
117
|
+
rails (~> 3.1.0)
|
118
118
|
rake (~> 0.8.7)
|
119
119
|
rspec
|
120
120
|
schema_plus!
|
data/gemfiles/Gemfile.rails-3.2
CHANGED
@@ -1,76 +1,76 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/ronen/github/schema_plus
|
3
3
|
specs:
|
4
|
-
schema_plus (0.2.
|
4
|
+
schema_plus (0.2.1)
|
5
5
|
rails
|
6
6
|
valuable
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionmailer (3.2.
|
12
|
-
actionpack (= 3.2.
|
13
|
-
mail (~> 2.
|
14
|
-
actionpack (3.2.
|
15
|
-
activemodel (= 3.2.
|
16
|
-
activesupport (= 3.2.
|
11
|
+
actionmailer (3.2.2)
|
12
|
+
actionpack (= 3.2.2)
|
13
|
+
mail (~> 2.4.0)
|
14
|
+
actionpack (3.2.2)
|
15
|
+
activemodel (= 3.2.2)
|
16
|
+
activesupport (= 3.2.2)
|
17
17
|
builder (~> 3.0.0)
|
18
18
|
erubis (~> 2.7.0)
|
19
|
-
journey (~> 1.0.
|
19
|
+
journey (~> 1.0.1)
|
20
20
|
rack (~> 1.4.0)
|
21
21
|
rack-cache (~> 1.1)
|
22
22
|
rack-test (~> 0.6.1)
|
23
23
|
sprockets (~> 2.1.2)
|
24
|
-
activemodel (3.2.
|
25
|
-
activesupport (= 3.2.
|
24
|
+
activemodel (3.2.2)
|
25
|
+
activesupport (= 3.2.2)
|
26
26
|
builder (~> 3.0.0)
|
27
|
-
activerecord (3.2.
|
28
|
-
activemodel (= 3.2.
|
29
|
-
activesupport (= 3.2.
|
30
|
-
arel (~> 3.0.
|
27
|
+
activerecord (3.2.2)
|
28
|
+
activemodel (= 3.2.2)
|
29
|
+
activesupport (= 3.2.2)
|
30
|
+
arel (~> 3.0.2)
|
31
31
|
tzinfo (~> 0.3.29)
|
32
|
-
activeresource (3.2.
|
33
|
-
activemodel (= 3.2.
|
34
|
-
activesupport (= 3.2.
|
35
|
-
activesupport (3.2.
|
32
|
+
activeresource (3.2.2)
|
33
|
+
activemodel (= 3.2.2)
|
34
|
+
activesupport (= 3.2.2)
|
35
|
+
activesupport (3.2.2)
|
36
36
|
i18n (~> 0.6)
|
37
37
|
multi_json (~> 1.0)
|
38
|
-
arel (3.0.
|
38
|
+
arel (3.0.2)
|
39
39
|
builder (3.0.0)
|
40
40
|
diff-lcs (1.1.3)
|
41
41
|
erubis (2.7.0)
|
42
42
|
hike (1.2.1)
|
43
43
|
i18n (0.6.0)
|
44
|
-
journey (1.0.
|
45
|
-
json (1.6.
|
46
|
-
mail (2.
|
44
|
+
journey (1.0.3)
|
45
|
+
json (1.6.5)
|
46
|
+
mail (2.4.4)
|
47
47
|
i18n (>= 0.4.0)
|
48
48
|
mime-types (~> 1.16)
|
49
49
|
treetop (~> 1.4.8)
|
50
50
|
mime-types (1.17.2)
|
51
|
-
multi_json (1.0
|
51
|
+
multi_json (1.1.0)
|
52
52
|
mysql (2.8.1)
|
53
53
|
mysql2 (0.3.11)
|
54
|
-
pg (0.
|
54
|
+
pg (0.13.2)
|
55
55
|
polyglot (0.3.3)
|
56
|
-
rack (1.4.
|
57
|
-
rack-cache (1.
|
56
|
+
rack (1.4.1)
|
57
|
+
rack-cache (1.2)
|
58
58
|
rack (>= 0.4)
|
59
59
|
rack-ssl (1.3.2)
|
60
60
|
rack
|
61
61
|
rack-test (0.6.1)
|
62
62
|
rack (>= 1.0)
|
63
|
-
rails (3.2.
|
64
|
-
actionmailer (= 3.2.
|
65
|
-
actionpack (= 3.2.
|
66
|
-
activerecord (= 3.2.
|
67
|
-
activeresource (= 3.2.
|
68
|
-
activesupport (= 3.2.
|
63
|
+
rails (3.2.2)
|
64
|
+
actionmailer (= 3.2.2)
|
65
|
+
actionpack (= 3.2.2)
|
66
|
+
activerecord (= 3.2.2)
|
67
|
+
activeresource (= 3.2.2)
|
68
|
+
activesupport (= 3.2.2)
|
69
69
|
bundler (~> 1.0)
|
70
|
-
railties (= 3.2.
|
71
|
-
railties (3.2.
|
72
|
-
actionpack (= 3.2.
|
73
|
-
activesupport (= 3.2.
|
70
|
+
railties (= 3.2.2)
|
71
|
+
railties (3.2.2)
|
72
|
+
actionpack (= 3.2.2)
|
73
|
+
activesupport (= 3.2.2)
|
74
74
|
rack-ssl (~> 1.3.2)
|
75
75
|
rake (>= 0.8.7)
|
76
76
|
rdoc (~> 3.4)
|
@@ -78,16 +78,16 @@ GEM
|
|
78
78
|
rake (0.8.7)
|
79
79
|
rdoc (3.12)
|
80
80
|
json (~> 1.4)
|
81
|
-
rspec (2.
|
82
|
-
rspec-core (~> 2.
|
83
|
-
rspec-expectations (~> 2.
|
84
|
-
rspec-mocks (~> 2.
|
85
|
-
rspec-core (2.
|
86
|
-
rspec-expectations (2.
|
87
|
-
diff-lcs (~> 1.1.
|
88
|
-
rspec-mocks (2.
|
89
|
-
simplecov (0.
|
90
|
-
multi_json (~> 1.0
|
81
|
+
rspec (2.9.0)
|
82
|
+
rspec-core (~> 2.9.0)
|
83
|
+
rspec-expectations (~> 2.9.0)
|
84
|
+
rspec-mocks (~> 2.9.0)
|
85
|
+
rspec-core (2.9.0)
|
86
|
+
rspec-expectations (2.9.0)
|
87
|
+
diff-lcs (~> 1.1.3)
|
88
|
+
rspec-mocks (2.9.0)
|
89
|
+
simplecov (0.6.1)
|
90
|
+
multi_json (~> 1.0)
|
91
91
|
simplecov-html (~> 0.5.3)
|
92
92
|
simplecov-gem-adapter (1.0.1)
|
93
93
|
simplecov
|
@@ -102,8 +102,8 @@ GEM
|
|
102
102
|
treetop (1.4.10)
|
103
103
|
polyglot
|
104
104
|
polyglot (>= 0.3.1)
|
105
|
-
tzinfo (0.3.
|
106
|
-
valuable (0.9.
|
105
|
+
tzinfo (0.3.32)
|
106
|
+
valuable (0.9.3)
|
107
107
|
|
108
108
|
PLATFORMS
|
109
109
|
ruby
|
@@ -112,7 +112,7 @@ DEPENDENCIES
|
|
112
112
|
mysql
|
113
113
|
mysql2
|
114
114
|
pg
|
115
|
-
rails (~> 3.2.0
|
115
|
+
rails (~> 3.2.0)
|
116
116
|
rake (~> 0.8.7)
|
117
117
|
rspec
|
118
118
|
schema_plus!
|
data/lib/schema_plus.rb
CHANGED
@@ -20,6 +20,7 @@ module SchemaPlus
|
|
20
20
|
module ConnectionAdapters
|
21
21
|
autoload :MysqlAdapter, 'schema_plus/active_record/connection_adapters/mysql_adapter'
|
22
22
|
autoload :PostgresqlAdapter, 'schema_plus/active_record/connection_adapters/postgresql_adapter'
|
23
|
+
autoload :PostgreSQLColumn, 'schema_plus/active_record/connection_adapters/postgresql_adapter'
|
23
24
|
autoload :Sqlite3Adapter, 'schema_plus/active_record/connection_adapters/sqlite3_adapter'
|
24
25
|
end
|
25
26
|
end
|
@@ -28,7 +28,7 @@ module SchemaPlus
|
|
28
28
|
adapter = 'MysqlAdapter'
|
29
29
|
when 'PostgreSQL'
|
30
30
|
adapter = 'PostgresqlAdapter'
|
31
|
-
when 'SQLite'
|
31
|
+
when 'SQLite'
|
32
32
|
adapter = 'Sqlite3Adapter'
|
33
33
|
end
|
34
34
|
if adapter
|
@@ -43,6 +43,13 @@ module SchemaPlus
|
|
43
43
|
monkeypatch = SchemaPlus::ActiveRecord::ConnectionAdapters::IndexDefinition
|
44
44
|
mysql2index.send(:include, monkeypatch) unless mysql2index.include? monkeypatch
|
45
45
|
end
|
46
|
+
|
47
|
+
if adapter == 'PostgresqlAdapter'
|
48
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLColumn.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::PostgreSQLColumn) unless ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn.include?(SchemaPlus::ActiveRecord::ConnectionAdapters::PostgreSQLColumn)
|
49
|
+
end
|
50
|
+
if adapter == 'Sqlite3Adapter'
|
51
|
+
::ActiveRecord::ConnectionAdapters::SQLiteColumn.send(:include, SchemaPlus::ActiveRecord::ConnectionAdapters::SQLiteColumn) unless ::ActiveRecord::ConnectionAdapters::SQLiteColumn.include?(SchemaPlus::ActiveRecord::ConnectionAdapters::SQLiteColumn)
|
52
|
+
end
|
46
53
|
end
|
47
54
|
extend(SchemaPlus::ActiveRecord::ForeignKeys)
|
48
55
|
end
|
@@ -114,6 +121,39 @@ module SchemaPlus
|
|
114
121
|
false
|
115
122
|
end
|
116
123
|
|
124
|
+
def add_column_options!(sql, options)
|
125
|
+
if options_include_default?(options)
|
126
|
+
default = options[:default]
|
127
|
+
# figure out if this is an expression and if not treat as standard default value
|
128
|
+
expr = sql_for_function( (default.is_a? Hash) ? default[:expr] : default )
|
129
|
+
if !expr && default.is_a?(Hash) && default[:expr]
|
130
|
+
if default_expr_valid? default[:expr]
|
131
|
+
expr = default[:expr]
|
132
|
+
else
|
133
|
+
raise(ArgumentError)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
if expr
|
137
|
+
sql << " DEFAULT #{expr}"
|
138
|
+
else
|
139
|
+
value = (default.is_a? Hash) ? default[:value] : default
|
140
|
+
sql << " DEFAULT #{quote(value.to_s, options[:column])}" if value
|
141
|
+
end
|
142
|
+
end
|
143
|
+
# must explicitly check for :null to allow change_column to work on migrations
|
144
|
+
if options[:null] == false
|
145
|
+
sql << " NOT NULL"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def default_expr_valid?(expr)
|
150
|
+
# override in database specific adaptor
|
151
|
+
end
|
152
|
+
|
153
|
+
def sql_for_function(function_name)
|
154
|
+
# override in database specific adaptor
|
155
|
+
end
|
156
|
+
|
117
157
|
# This is define in rails 3.x, but not in rails2.x
|
118
158
|
unless defined? ::ActiveRecord::ConnectionAdapters::SchemaStatements::index_name_exists?
|
119
159
|
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 403
|
@@ -1,6 +1,39 @@
|
|
1
1
|
module SchemaPlus
|
2
2
|
module ActiveRecord
|
3
3
|
module ConnectionAdapters
|
4
|
+
# PostgreSQL-specific extensions to column definitions in a table.
|
5
|
+
module PostgreSQLColumn
|
6
|
+
# Extracts the value from a PostgreSQL column default definition.
|
7
|
+
def self.included(base) #:nodoc:
|
8
|
+
base.extend ClassMethods
|
9
|
+
base.class_eval do
|
10
|
+
class << self
|
11
|
+
alias_method_chain :extract_value_from_default, :schema_plus
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(name, default, sql_type = nil, null = true)
|
17
|
+
if default.is_a? Hash
|
18
|
+
if default[:expr]
|
19
|
+
@default_expr = default[:expr]
|
20
|
+
end
|
21
|
+
default = nil
|
22
|
+
end
|
23
|
+
super(name, default, sql_type, null)
|
24
|
+
end
|
25
|
+
|
26
|
+
module ClassMethods
|
27
|
+
def extract_value_from_default_with_schema_plus(default)
|
28
|
+
value = extract_value_from_default_without_schema_plus(default)
|
29
|
+
if value.nil? && !default.nil?
|
30
|
+
value = { :expr => default }
|
31
|
+
end
|
32
|
+
value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
4
37
|
# The Postgresql adapter implements the SchemaPlus extensions and
|
5
38
|
# enhancements
|
6
39
|
module PostgresqlAdapter
|
@@ -159,6 +192,17 @@ module SchemaPlus
|
|
159
192
|
|
160
193
|
foreign_keys
|
161
194
|
end
|
195
|
+
|
196
|
+
def default_expr_valid?(expr)
|
197
|
+
true # arbitrary sql is okay in PostgreSQL
|
198
|
+
end
|
199
|
+
|
200
|
+
def sql_for_function(function)
|
201
|
+
case function
|
202
|
+
when :now
|
203
|
+
"NOW()"
|
204
|
+
end
|
205
|
+
end
|
162
206
|
end
|
163
207
|
end
|
164
208
|
end
|
@@ -1,6 +1,15 @@
|
|
1
1
|
module SchemaPlus
|
2
2
|
module ActiveRecord
|
3
3
|
module ConnectionAdapters
|
4
|
+
module SQLiteColumn
|
5
|
+
def initialize(name, default, sql_type = nil, null = true)
|
6
|
+
if default =~ /DATETIME/
|
7
|
+
@default_expr = "(#{default})"
|
8
|
+
end
|
9
|
+
super(name, default, sql_type, null)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
# SchemaPlus includes an Sqlite3 implementation of the AbstractAdapater
|
5
14
|
# extensions.
|
6
15
|
module Sqlite3Adapter
|
@@ -71,6 +80,16 @@ module SchemaPlus
|
|
71
80
|
foreign_keys
|
72
81
|
end
|
73
82
|
|
83
|
+
def default_expr_valid?(expr)
|
84
|
+
true # arbitrary sql is okay
|
85
|
+
end
|
86
|
+
|
87
|
+
def sql_for_function(function)
|
88
|
+
case function
|
89
|
+
when :now
|
90
|
+
"(DATETIME('now'))"
|
91
|
+
end
|
92
|
+
end
|
74
93
|
end
|
75
94
|
|
76
95
|
end
|
@@ -98,7 +98,13 @@ module SchemaPlus
|
|
98
98
|
def table_with_schema_plus(table, ignore) #:nodoc:
|
99
99
|
stream = StringIO.new
|
100
100
|
table_without_schema_plus(table, stream)
|
101
|
-
|
101
|
+
stream_string = stream.string
|
102
|
+
@connection.columns(table).each do |column|
|
103
|
+
if !column.default_expr.nil?
|
104
|
+
stream_string.gsub!("\"#{column.name}\"", "\"#{column.name}\", :default => { :expr => \"#{column.default_expr}\" }")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
@table_dumps[table] = stream_string
|
102
108
|
end
|
103
109
|
|
104
110
|
def indexes_with_schema_plus(table, stream) #:nodoc:
|
data/lib/schema_plus/version.rb
CHANGED
data/runspecs
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'ostruct'
|
5
|
+
require 'tempfile'
|
5
6
|
|
6
|
-
RUBY_VERSIONS = %W[1.8.7 1.9.2]
|
7
|
+
RUBY_VERSIONS = %W[1.8.7 1.9.2 1.9.3]
|
7
8
|
RAILS_VERSIONS = %W[2.3 3.0 3.1 3.2]
|
8
9
|
DB_ADAPTERS = %W[postgresql mysql mysql2 sqlite3]
|
9
10
|
|
@@ -90,6 +91,11 @@ combos.each_with_index do |combo, n|
|
|
90
91
|
puts "\n\n*** ruby version #{ruby} - rails version #{rails} - db adapter: #{db_adapter} [#{n+1} of #{combos.size}]\n\n#{command}"
|
91
92
|
|
92
93
|
next if o.dry_run
|
93
|
-
|
94
|
+
|
95
|
+
Tempfile.open('runspecs') do |file|
|
96
|
+
system("(#{command}) 2>&1 | tee #{file.path}")
|
97
|
+
file.rewind
|
98
|
+
errs << "ruby #{ruby}, rails #{rails}#{db_adapter && ", db_adapter #{db_adapter}"}" if file.readlines.grep(/^Failed examples/).any?
|
99
|
+
end
|
94
100
|
end
|
95
101
|
puts errs.any? ? "\n*** #{errs.size} failures:\n\t#{errs.join("\n\t")}" : "\n*** #{combos.size > 1 ? 'all versions' : 'spec'} succeeded ***" unless o.dry_run
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe "Column definition" do
|
5
|
+
before(:all) do
|
6
|
+
load_core_schema
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:connection) { ActiveRecord::Base.connection }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
@sql = 'time_taken text'
|
13
|
+
end
|
14
|
+
|
15
|
+
context "just default passed" do
|
16
|
+
before(:each) do
|
17
|
+
connection.add_column_options!(@sql, { :default => "2011-12-11 00:00:00" })
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { @sql}
|
21
|
+
|
22
|
+
it "should use the normal default" do
|
23
|
+
should == "time_taken text DEFAULT '2011-12-11 00:00:00'"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "just default passed in hash" do
|
28
|
+
before(:each) do
|
29
|
+
connection.add_column_options!(@sql, { :default => { :value => "2011-12-11 00:00:00" } })
|
30
|
+
end
|
31
|
+
|
32
|
+
subject { @sql}
|
33
|
+
|
34
|
+
it "should use the normal default" do
|
35
|
+
should == "time_taken text DEFAULT '2011-12-11 00:00:00'"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "default function passed as now" do
|
40
|
+
before(:each) do
|
41
|
+
connection.add_column_options!(@sql, { :default => :now })
|
42
|
+
end
|
43
|
+
|
44
|
+
subject { @sql }
|
45
|
+
|
46
|
+
if SchemaPlusHelpers.postgresql?
|
47
|
+
it "should use NOW() as the default" do
|
48
|
+
should == "time_taken text DEFAULT NOW()"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if SchemaPlusHelpers.sqlite3?
|
53
|
+
it "should use NOW() as the default" do
|
54
|
+
should == "time_taken text DEFAULT (DATETIME('now'))"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
if SchemaPlusHelpers.mysql?
|
59
|
+
it "should use CURRENT_TIMESTAMP as the default" do
|
60
|
+
should == "time_taken text DEFAULT 'now'"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "valid expr passed as default" do
|
66
|
+
subject { connection.add_column_options!(@sql, { :default => { :expr => 'NOW()' } }); @sql }
|
67
|
+
|
68
|
+
if SchemaPlusHelpers.postgresql?
|
69
|
+
it "should use NOW() as the default" do
|
70
|
+
should == "time_taken text DEFAULT NOW()"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
if SchemaPlusHelpers.sqlite3?
|
75
|
+
it "should use NOW() as the default" do
|
76
|
+
should == "time_taken text DEFAULT NOW()"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
if SchemaPlusHelpers.mysql?
|
81
|
+
it "should raise an error" do
|
82
|
+
lambda { subject }.should raise_error
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "invalid expr passed as default" do
|
88
|
+
if SchemaPlusHelpers.mysql?
|
89
|
+
it "should raise an error" do
|
90
|
+
lambda {connection.add_column_options!(@sql, { :default => { :expr => "ARBITRARY_EXPR" } })}.should raise_error ArgumentError
|
91
|
+
end
|
92
|
+
else
|
93
|
+
it "should just accept the SQL" do
|
94
|
+
connection.add_column_options!(@sql, { :default => { :expr => "ARBITRARY_EXPR" } })
|
95
|
+
@sql.should == "time_taken text DEFAULT ARBITRARY_EXPR"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/foreign_key_spec.rb
CHANGED
data/spec/index_spec.rb
CHANGED
@@ -39,7 +39,7 @@ describe "add_index" do
|
|
39
39
|
expect { add_index(:users, :login) }.should_not raise_error
|
40
40
|
index_for(:login).should_not be_nil
|
41
41
|
end
|
42
|
-
if
|
42
|
+
if ActiveRecord::VERSION::STRING >= "3.0"
|
43
43
|
it "should complain if the index is different" do
|
44
44
|
add_index(:users, :login, :unique => true)
|
45
45
|
index_for(:login).should_not be_nil
|
data/spec/migration_spec.rb
CHANGED
@@ -307,6 +307,10 @@ describe ActiveRecord::Migration do
|
|
307
307
|
SchemaPlus.config.foreign_keys.auto_index = false
|
308
308
|
end
|
309
309
|
|
310
|
+
it "should not auto-index if column already has an index"
|
311
|
+
|
312
|
+
it "should remove auto-created index when removing foreign key"
|
313
|
+
|
310
314
|
it "should use default on_update action" do
|
311
315
|
SchemaPlus.config.foreign_keys.on_update = :cascade
|
312
316
|
add_column(:post_id, :integer) do
|
@@ -63,6 +63,12 @@ describe ActiveRecord::Migration do
|
|
63
63
|
change_column :user, :string, :references => nil
|
64
64
|
end
|
65
65
|
|
66
|
+
it "should remove a foreign key" do
|
67
|
+
@model.should reference(:users, :id).on(:user_id)
|
68
|
+
change_column :user_id, :integer, :references => nil
|
69
|
+
@model.should_not reference(:users, :id).on(:user_id)
|
70
|
+
end
|
71
|
+
|
66
72
|
end
|
67
73
|
|
68
74
|
context "when column is removed" do
|
data/spec/schema_dumper_spec.rb
CHANGED
@@ -68,6 +68,50 @@ describe "Schema dump" do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
context "with date default" do
|
72
|
+
if SchemaPlusHelpers.postgresql?
|
73
|
+
it "should dump the default hash expr as now()" do
|
74
|
+
with_additional_column Post, :posted_at, :datetime, :default => :now do
|
75
|
+
dump_posts.should match(to_regexp(%q{t.datetime "posted_at", :default => \{ :expr => "now()" \}}))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should dump the default hash expr as CURRENT_TIMESTAMP" do
|
80
|
+
with_additional_column Post, :posted_at, :datetime, :default => {:expr => 'date \'2001-09-28\''} do
|
81
|
+
dump_posts.should match(to_regexp(%q{t.datetime "posted_at", :default => '2001-09-28 00:00:00'}))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if SchemaPlusHelpers.sqlite3?
|
87
|
+
it "should dump the default hash expr as now" do
|
88
|
+
with_additional_column Post, :posted_at, :datetime, :default => :now do
|
89
|
+
dump_posts.should match(to_regexp(%q{t.datetime "posted_at", :default => \{ :expr => "(DATETIME('now'))" \}}))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should dump the default hash expr string as now" do
|
94
|
+
with_additional_column Post, :posted_at, :datetime, :default => { :expr => "(DATETIME('now'))" } do
|
95
|
+
dump_posts.should match(to_regexp(%q{t.datetime "posted_at", :default => \{ :expr => "(DATETIME('now'))" \}}))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should dump the default value normally" do
|
100
|
+
with_additional_column Post, :posted_at, :string, :default => "now" do
|
101
|
+
dump_posts.should match(to_regexp(%q{t.string "posted_at", :default => "now"}))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
if SchemaPlusHelpers.postgresql?
|
107
|
+
it "should dump the default hash expr as CURRENT_TIMESTAMP" do
|
108
|
+
with_additional_column Post, :posted_at, :datetime, :default => {:expr => 'date \'2001-09-28\''} do
|
109
|
+
dump_posts.should match(to_regexp(%q{t.datetime "posted_at", :default => '2001-09-28 00:00:00'}))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
71
115
|
it "should include foreign_key options" do
|
72
116
|
with_foreign_key Post, :user_id, :users, :id, :on_update => :cascade, :on_delete => :set_null do
|
73
117
|
dump_posts.should match(to_regexp(%q{t.foreign_key ["user_id"], "users", ["id"], :on_update => :cascade, :on_delete => :set_null}))
|
@@ -149,6 +193,19 @@ describe "Schema dump" do
|
|
149
193
|
Regexp.new(Regexp.escape(string))
|
150
194
|
end
|
151
195
|
|
196
|
+
def with_additional_column(model, column_name, column_type, options)
|
197
|
+
table_columns = model.columns.reject{|column| column.name == 'id'}
|
198
|
+
ActiveRecord::Migration.suppress_messages do
|
199
|
+
ActiveRecord::Migration.create_table model.table_name, :force => true do |t|
|
200
|
+
table_columns.each do |column|
|
201
|
+
t.column column.name, column.type, :default => column.default
|
202
|
+
end
|
203
|
+
t.column column_name, column_type, options
|
204
|
+
end
|
205
|
+
end
|
206
|
+
yield
|
207
|
+
end
|
208
|
+
|
152
209
|
def with_foreign_key(model, columns, referenced_table_name, referenced_columns, options = {})
|
153
210
|
table_columns = model.columns.reject{|column| column.name == 'id'}
|
154
211
|
ActiveRecord::Migration.suppress_messages do
|
@@ -172,7 +229,7 @@ describe "Schema dump" do
|
|
172
229
|
end
|
173
230
|
end
|
174
231
|
end
|
175
|
-
|
232
|
+
|
176
233
|
def with_index(model, columns, options = {})
|
177
234
|
ActiveRecord::Migration.suppress_messages do
|
178
235
|
ActiveRecord::Migration.add_index(model.table_name, columns, options)
|
data/spec/schema_spec.rb
CHANGED
@@ -22,12 +22,13 @@ describe ActiveRecord::Schema do
|
|
22
22
|
|
23
23
|
it "should create only explicity added indexes" do
|
24
24
|
define_schema
|
25
|
-
|
25
|
+
expected = SchemaPlusHelpers.mysql? ? 2 : 1
|
26
|
+
connection.tables.collect { |table| connection.indexes(table) }.flatten.should have(expected).items
|
26
27
|
end
|
27
28
|
|
28
29
|
it "should create only explicity added foriegn keys" do
|
29
30
|
define_schema
|
30
|
-
connection.tables.collect { |table| connection.foreign_keys(table) }.flatten.should have(
|
31
|
+
connection.tables.collect { |table| connection.foreign_keys(table) }.flatten.should have(2).items
|
31
32
|
end
|
32
33
|
|
33
34
|
end
|
@@ -41,8 +42,16 @@ describe ActiveRecord::Schema do
|
|
41
42
|
create_table :users, :force => true do
|
42
43
|
end
|
43
44
|
|
45
|
+
create_table :colors, :force => true do
|
46
|
+
end
|
47
|
+
|
48
|
+
create_table :shoes, :force => true do
|
49
|
+
end
|
50
|
+
|
44
51
|
create_table :posts, :force => true do |t|
|
45
52
|
t.integer :user_id, :references => :users, :index => true
|
53
|
+
t.integer :shoe_id, :references => :shoes # should not have an index (except mysql)
|
54
|
+
t.integer :color_id # should not have a foreign key nor index
|
46
55
|
end
|
47
56
|
end
|
48
57
|
end
|
data/spec/views_spec.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
+
class AOnes < ActiveRecord::Base
|
4
|
+
end
|
5
|
+
|
6
|
+
class ABOnes < ActiveRecord::Base
|
7
|
+
end
|
8
|
+
|
3
9
|
describe ActiveRecord do
|
4
10
|
|
5
11
|
let(:schema) { ActiveRecord::Schema }
|
@@ -24,8 +30,8 @@ describe ActiveRecord do
|
|
24
30
|
end
|
25
31
|
|
26
32
|
it "should query correctly" do
|
27
|
-
|
28
|
-
|
33
|
+
AOnes.all.collect(&:s).should == %W[one_one one_two]
|
34
|
+
ABOnes.all.collect(&:s).should == %W[one_one]
|
29
35
|
end
|
30
36
|
|
31
37
|
it "should instrospect" do
|
@@ -118,8 +124,6 @@ describe ActiveRecord do
|
|
118
124
|
connection.execute "insert into items (a, b, s) values (2, 1, 'two_one')"
|
119
125
|
connection.execute "insert into items (a, b, s) values (2, 2, 'two_two')"
|
120
126
|
|
121
|
-
@a_ones = Class.new(ActiveRecord::Base) do set_table_name "a_ones" end
|
122
|
-
@ab_ones = Class.new(ActiveRecord::Base) do set_table_name "ab_ones" end
|
123
127
|
end
|
124
128
|
|
125
129
|
def drop_definitions
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-03-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &70239318248000 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70239318248000
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: valuable
|
28
|
-
requirement: &
|
28
|
+
requirement: &70239318247580 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70239318247580
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rake
|
39
|
-
requirement: &
|
39
|
+
requirement: &70239318247080 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 0.8.7
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70239318247080
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &70239318246660 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70239318246660
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: pg
|
61
|
-
requirement: &
|
61
|
+
requirement: &70239318246200 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70239318246200
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: mysql
|
72
|
-
requirement: &
|
72
|
+
requirement: &70239318245780 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70239318245780
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: sqlite3
|
83
|
-
requirement: &
|
83
|
+
requirement: &70239318245360 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70239318245360
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: simplecov
|
94
|
-
requirement: &
|
94
|
+
requirement: &70239318244940 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *70239318244940
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: simplecov-gem-adapter
|
105
|
-
requirement: &
|
105
|
+
requirement: &70239318244520 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,7 +110,7 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *70239318244520
|
114
114
|
description: ! 'SchemaPlus is an ActiveRecord extension that provides enhanced capabilities
|
115
115
|
for schema definition and querying, including: enhanced and more DRY index capabilities,
|
116
116
|
support and automation for foreign key constraints, and support for views.'
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- lib/schema_plus/version.rb
|
157
157
|
- runspecs
|
158
158
|
- schema_plus.gemspec
|
159
|
+
- spec/column_definition_spec.rb
|
159
160
|
- spec/column_spec.rb
|
160
161
|
- spec/connection_spec.rb
|
161
162
|
- spec/connections/mysql/connection.rb
|
@@ -208,6 +209,7 @@ specification_version: 3
|
|
208
209
|
summary: Enhances ActiveRecord schema mechanism, including more DRY index creation
|
209
210
|
and support for foreign key constraints and views.
|
210
211
|
test_files:
|
212
|
+
- spec/column_definition_spec.rb
|
211
213
|
- spec/column_spec.rb
|
212
214
|
- spec/connection_spec.rb
|
213
215
|
- spec/connections/mysql/connection.rb
|
@@ -234,3 +236,4 @@ test_files:
|
|
234
236
|
- spec/support/matchers/reference.rb
|
235
237
|
- spec/support/reference.rb
|
236
238
|
- spec/views_spec.rb
|
239
|
+
has_rdoc:
|