schema_plus 1.5.3 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +8 -8
- data/CHANGELOG.md +10 -4
- data/README.md +24 -4
- data/Rakefile +1 -1
- data/gemfiles/rails-4.1/Gemfile.base +1 -1
- data/lib/schema_plus/active_record/connection_adapters/abstract_adapter.rb +11 -5
- data/lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb +58 -2
- data/lib/schema_plus/active_record/schema_dumper.rb +10 -0
- data/lib/schema_plus/version.rb +1 -1
- data/runspecs +1 -1
- data/spec/column_default_spec.rb +20 -26
- data/spec/column_spec.rb +22 -24
- data/spec/connections/postgresql/connection.rb +1 -1
- data/spec/enum_spec.rb +132 -0
- data/spec/foreign_key_spec.rb +18 -15
- data/spec/index_definition_spec.rb +97 -102
- data/spec/index_spec.rb +5 -8
- data/spec/migration_spec.rb +288 -303
- data/spec/named_schemas_spec.rb +24 -26
- data/spec/schema_dumper_spec.rb +66 -53
- data/spec/spec_helper.rb +6 -0
- data/spec/views_spec.rb +41 -24
- metadata +24 -22
@@ -68,144 +68,139 @@ describe "Index definition" do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
expect(index.orders).to eq({"login" => :desc, "deleted_at" => :asc})
|
89
|
-
end
|
90
|
-
|
71
|
+
context "when index is ordered", :mysql => :skip do
|
72
|
+
|
73
|
+
quotes = [
|
74
|
+
["unquoted", ''],
|
75
|
+
["double-quoted", '"'],
|
76
|
+
]
|
77
|
+
quotes += [
|
78
|
+
["single-quoted", "'"],
|
79
|
+
["back-quoted", '`']
|
80
|
+
] if SchemaPlusHelpers.sqlite3?
|
81
|
+
|
82
|
+
quotes.each do |quotename, quote|
|
83
|
+
it "index definition includes orders for #{quotename} columns" do
|
84
|
+
migration.execute "CREATE INDEX users_login_index ON users (#{quote}login#{quote} DESC, #{quote}deleted_at#{quote} ASC)"
|
85
|
+
User.reset_column_information
|
86
|
+
index = index_definition(%w[login deleted_at])
|
87
|
+
expect(index.orders).to eq({"login" => :desc, "deleted_at" => :asc})
|
91
88
|
end
|
89
|
+
|
92
90
|
end
|
93
91
|
end
|
94
92
|
|
95
93
|
|
96
|
-
|
94
|
+
context "when case insensitive is added", :postgresql => :only do
|
97
95
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
@index = User.indexes.detect { |i| i.expression =~ /lower\(\(login\)::text\)/i }
|
104
|
-
end
|
105
|
-
|
106
|
-
it "is included in User.indexes" do
|
107
|
-
expect(@index).not_to be_nil
|
108
|
-
end
|
96
|
+
before(:each) do
|
97
|
+
migration.execute "CREATE INDEX users_login_index ON users(LOWER(login))"
|
98
|
+
User.reset_column_information
|
99
|
+
@index = User.indexes.detect { |i| i.expression =~ /lower\(\(login\)::text\)/i }
|
100
|
+
end
|
109
101
|
|
110
|
-
|
111
|
-
|
112
|
-
|
102
|
+
it "is included in User.indexes" do
|
103
|
+
expect(@index).not_to be_nil
|
104
|
+
end
|
113
105
|
|
114
|
-
|
115
|
-
|
116
|
-
|
106
|
+
it "is not case_sensitive" do
|
107
|
+
expect(@index).not_to be_case_sensitive
|
108
|
+
end
|
117
109
|
|
118
|
-
|
119
|
-
|
120
|
-
|
110
|
+
it "its column should not be case sensitive" do
|
111
|
+
expect(User.columns.find{|column| column.name == "login"}).not_to be_case_sensitive
|
112
|
+
end
|
121
113
|
|
122
|
-
|
123
|
-
|
124
|
-
|
114
|
+
it "defines expression" do
|
115
|
+
expect(@index.expression).to eq("lower((login)::text)")
|
116
|
+
end
|
125
117
|
|
118
|
+
it "doesn't define conditions" do
|
119
|
+
expect(@index.conditions).to be_nil
|
126
120
|
end
|
127
121
|
|
122
|
+
end
|
128
123
|
|
129
|
-
context "when index is partial and column is not downcased" do
|
130
|
-
before(:each) do
|
131
|
-
migration.execute "CREATE INDEX users_login_index ON users(login) WHERE deleted_at IS NULL"
|
132
|
-
User.reset_column_information
|
133
|
-
@index = index_definition("login")
|
134
|
-
end
|
135
124
|
|
136
|
-
|
137
|
-
|
138
|
-
|
125
|
+
context "when index is partial and column is not downcased", :postgresql => :only do
|
126
|
+
before(:each) do
|
127
|
+
migration.execute "CREATE INDEX users_login_index ON users(login) WHERE deleted_at IS NULL"
|
128
|
+
User.reset_column_information
|
129
|
+
@index = index_definition("login")
|
130
|
+
end
|
139
131
|
|
140
|
-
|
141
|
-
|
142
|
-
|
132
|
+
it "is included in User.indexes" do
|
133
|
+
expect(User.indexes.select { |index| index.columns == ["login"] }.size).to eq(1)
|
134
|
+
end
|
143
135
|
|
144
|
-
|
145
|
-
|
146
|
-
|
136
|
+
it "is case_sensitive" do
|
137
|
+
expect(@index).to be_case_sensitive
|
138
|
+
end
|
147
139
|
|
148
|
-
|
149
|
-
|
150
|
-
|
140
|
+
it "doesn't define expression" do
|
141
|
+
expect(@index.expression).to be_nil
|
142
|
+
end
|
151
143
|
|
144
|
+
it "defines conditions" do
|
145
|
+
expect(@index.conditions).to eq("(deleted_at IS NULL)")
|
152
146
|
end
|
153
147
|
|
154
|
-
|
155
|
-
before(:each) do
|
156
|
-
migration.execute "CREATE INDEX users_login_index ON users (extract(EPOCH from deleted_at)) WHERE deleted_at IS NULL"
|
157
|
-
User.reset_column_information
|
158
|
-
@index = User.indexes.detect { |i| i.expression.present? }
|
159
|
-
end
|
148
|
+
end
|
160
149
|
|
161
|
-
|
162
|
-
|
163
|
-
|
150
|
+
context "when index contains expression", :postgresql => :only do
|
151
|
+
before(:each) do
|
152
|
+
migration.execute "CREATE INDEX users_login_index ON users (extract(EPOCH from deleted_at)) WHERE deleted_at IS NULL"
|
153
|
+
User.reset_column_information
|
154
|
+
@index = User.indexes.detect { |i| i.expression.present? }
|
155
|
+
end
|
164
156
|
|
165
|
-
|
166
|
-
|
167
|
-
|
157
|
+
it "exists" do
|
158
|
+
expect(@index).not_to be_nil
|
159
|
+
end
|
168
160
|
|
169
|
-
|
170
|
-
|
171
|
-
|
161
|
+
it "doesnt have columns defined" do
|
162
|
+
expect(@index.columns).to be_empty
|
163
|
+
end
|
172
164
|
|
173
|
-
|
174
|
-
|
175
|
-
|
165
|
+
it "is case_sensitive" do
|
166
|
+
expect(@index).to be_case_sensitive
|
167
|
+
end
|
176
168
|
|
177
|
-
|
178
|
-
|
179
|
-
|
169
|
+
it "defines expression" do
|
170
|
+
expect(@index.expression).to eq("date_part('epoch'::text, deleted_at)")
|
171
|
+
end
|
180
172
|
|
173
|
+
it "defines conditions" do
|
174
|
+
expect(@index.conditions).to eq("(deleted_at IS NULL)")
|
181
175
|
end
|
182
176
|
|
183
|
-
|
184
|
-
before(:each) do
|
185
|
-
migration.execute "CREATE INDEX users_login_index ON users USING hash(login)"
|
186
|
-
User.reset_column_information
|
187
|
-
@index = User.indexes.detect { |i| i.name == "users_login_index" }
|
188
|
-
end
|
177
|
+
end
|
189
178
|
|
190
|
-
|
191
|
-
|
192
|
-
|
179
|
+
context "when index has a non-btree type", :postgresql => :only do
|
180
|
+
before(:each) do
|
181
|
+
migration.execute "CREATE INDEX users_login_index ON users USING hash(login)"
|
182
|
+
User.reset_column_information
|
183
|
+
@index = User.indexes.detect { |i| i.name == "users_login_index" }
|
184
|
+
end
|
193
185
|
|
194
|
-
|
195
|
-
|
196
|
-
|
186
|
+
it "exists" do
|
187
|
+
expect(@index).not_to be_nil
|
188
|
+
end
|
197
189
|
|
198
|
-
|
199
|
-
|
200
|
-
|
190
|
+
it "defines kind" do
|
191
|
+
expect(@index.kind).to eq("hash")
|
192
|
+
end
|
201
193
|
|
202
|
-
|
203
|
-
|
204
|
-
|
194
|
+
it "does not define expression" do
|
195
|
+
expect(@index.expression).to be_nil
|
196
|
+
end
|
197
|
+
|
198
|
+
it "does not define order" do
|
199
|
+
expect(@index.orders).to be_blank
|
205
200
|
end
|
201
|
+
end
|
206
202
|
|
207
203
|
|
208
|
-
end # of postgresql specific examples
|
209
204
|
|
210
205
|
protected
|
211
206
|
def index_definition(column_names)
|
data/spec/index_spec.rb
CHANGED
@@ -55,11 +55,9 @@ describe "index" do
|
|
55
55
|
expect(index_for(:login).name).to eq('users_login_index')
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :asc})
|
62
|
-
end
|
58
|
+
it "should assign order", :mysql => :skip do
|
59
|
+
add_index(:users, [:login, :deleted_at], :order => {:login => :desc, :deleted_at => :asc})
|
60
|
+
expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :asc})
|
63
61
|
end
|
64
62
|
|
65
63
|
context "for duplicate index" do
|
@@ -78,7 +76,7 @@ describe "index" do
|
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
81
|
-
|
79
|
+
context "extra features", :postgresql => :only do
|
82
80
|
|
83
81
|
it "should assign conditions" do
|
84
82
|
add_index(:users, :login, :conditions => 'deleted_at IS NULL')
|
@@ -124,8 +122,7 @@ describe "index" do
|
|
124
122
|
expect { add_index(:users, :name => 'users_login_index', :expression => "USING btree (login)", :case_sensitive => false) }.to raise_error(ArgumentError, /use LOWER/i)
|
125
123
|
end
|
126
124
|
|
127
|
-
|
128
|
-
end # of postgresql specific examples
|
125
|
+
end
|
129
126
|
|
130
127
|
protected
|
131
128
|
|