schema_plus 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/CHANGELOG.md +4 -0
- data/README.md +14 -18
- data/Rakefile +1 -1
- data/lib/schema_plus/active_record/connection_adapters/index_definition.rb +6 -1
- data/lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb +27 -2
- data/lib/schema_plus/active_record/connection_adapters/sqlite3_adapter.rb +16 -2
- data/lib/schema_plus/active_record/schema_dumper.rb +1 -0
- data/lib/schema_plus/version.rb +1 -1
- data/runspecs +9 -3
- data/schema_plus.gemspec +1 -1
- data/spec/index_definition_spec.rb +3 -3
- data/spec/index_spec.rb +11 -0
- data/spec/schema_dumper_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c07ea7e4ac89f46fb3d3d27047c2cc2d2cbd5c0
|
4
|
+
data.tar.gz: 4db11b2d422195c298c344b9b150b7bac21d83a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c2363444635b39dc4f9bc2bc5542d670774da07fd5af5653278d7b2cf94151346594154d8161af5e727e91385f6bd66423cff05b1f6b4dc22d3bc4124929f72
|
7
|
+
data.tar.gz: ba2d12964f4a6ccbd02775ab2795ff94f6a93e9f0fe6a97f9e4c4a2f8c33985e629ba87f6bb47bd937b7bc626e5804c017cd42039458c10386652ab992038c50
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,8 +10,8 @@ For added rails DRYness see also the gems
|
|
10
10
|
[schema_validations](http://rubygems.org/gems/schema_validations)
|
11
11
|
|
12
12
|
[![Gem Version](https://badge.fury.io/rb/schema_plus.png)](http://badge.fury.io/rb/schema_plus)
|
13
|
-
[![Build Status](https://secure.travis-ci.org/
|
14
|
-
[![Dependency Status](https://gemnasium.com/
|
13
|
+
[![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_plus.png)](http://travis-ci.org/SchemaPlus/schema_plus)
|
14
|
+
[![Dependency Status](https://gemnasium.com/SchemaPlus/schema_plus.png)](https://gemnasium.com/SchemaPlus/schema_plus)
|
15
15
|
|
16
16
|
## Compatibility
|
17
17
|
|
@@ -19,8 +19,8 @@ SchemaPlus supports all combinations of:
|
|
19
19
|
|
20
20
|
* Rails/ActiveRecord 3.2, 4.0, and 4.1
|
21
21
|
* PostgreSQL, MySQL (using mysql2 gem; mysql gem only supported with Rails
|
22
|
-
3.2), or SQLite3 (using sqlite3 >= 3.7.7
|
23
|
-
* MRI Ruby 1.9.3
|
22
|
+
3.2), or SQLite3 (using sqlite3 >= 3.7.7 for foreign key support, >= 3.8 for partial indexes)
|
23
|
+
* MRI Ruby >= 1.9.3
|
24
24
|
|
25
25
|
And also supports:
|
26
26
|
|
@@ -92,12 +92,15 @@ which is equivalent to
|
|
92
92
|
t.string :product_code, index: { unique: true }
|
93
93
|
|
94
94
|
If you're using PostgreSQL, SchemaPlus provides support for conditions,
|
95
|
-
expressions, index methods, and case-insensitive indexes:
|
95
|
+
expressions, index methods, operator classes, and case-insensitive indexes:
|
96
96
|
|
97
97
|
t.string :last_name, index: { conditions: 'deleted_at IS NULL' }
|
98
98
|
t.string :last_name, index: { expression: 'upper(last_name)' }
|
99
99
|
t.string :last_name, index: { kind: 'hash' }
|
100
|
-
t.string :last_name, index: {
|
100
|
+
t.string :last_name, index: { operator_class: 'varchar_pattern_ops' }
|
101
|
+
t.string :last_name, index: { with: :address, operator_class: {last_name: 'varchar_pattern_ops', address: 'text_pattern_ops' }
|
102
|
+
t.string :last_name, index: { case_sensitive: false } # shorthand for expression: 'lower(last_name)'
|
103
|
+
|
101
104
|
|
102
105
|
These features are available also in `ActiveRecord::Migration.add_index`. See
|
103
106
|
doc for [SchemaPlus::ActiveRecord::ConnectionAdapters::PostgresqlAdapter](http://rubydoc.info/gems/schema_plus/SchemaPlus/ActiveRecord/ConnectionAdapters/PostgresqlAdapter) and
|
@@ -180,7 +183,7 @@ Foreign keys can cause issues for Rails utilities that delete or load data
|
|
180
183
|
because referential integrity imposes a sequencing requirement that those
|
181
184
|
utilities may not take into consideration. Monkey-patching may be required
|
182
185
|
to address some of these issues. The Wiki article [Making yaml_db work with
|
183
|
-
foreign key constraints in PostgreSQL](https://github.com/
|
186
|
+
foreign key constraints in PostgreSQL](https://github.com/SchemaPlus/schema_plus/wiki/Making-yaml_db-work-with-foreign-key-constraints-in-PostgreSQL)
|
184
187
|
has some information that may be of assistance in resolving these issues.
|
185
188
|
|
186
189
|
### Tables
|
@@ -322,21 +325,21 @@ of foreign key constraints, you can re-enable it:
|
|
322
325
|
|
323
326
|
* SchemaPlus was created in 2011 by [@mlomnicki](https://github.com/mlomnicki) and [@ronen](https://github.com/ronen)
|
324
327
|
|
325
|
-
* And [lots of contributors](https://github.com/
|
328
|
+
* And [lots of contributors](https://github.com/SchemaPlus/schema_plus/graphs/contributors) since then
|
326
329
|
|
327
330
|
## Development & Testing
|
328
331
|
|
329
332
|
Are you interested in contributing to schema_plus? Thanks!
|
330
333
|
|
331
|
-
Schema_plus has a full set of rspec tests. [travis-ci](http://travis-ci.org/
|
334
|
+
Schema_plus has a full set of rspec tests. [travis-ci](http://travis-ci.org/SchemaPlus/schema_plus) runs the tests on the full matrix of supported versions of ruby, rails, and db adapters. But you can also test all or some part of the matrix locally before you push your changes. Here's what you need to know:
|
332
335
|
|
333
336
|
#### Required environment:
|
334
337
|
|
335
|
-
* You must have
|
338
|
+
* You must have one of [chruby](https://github.com/postmodern/chruby),) [rbenv](https://github.com/sstephenson/rbenv) or [rvm](http://rvm.io) installed and working. Within it, have available whichever ruby versions you want to test. The default set is MRI 1.9.3, 2.1.3, and jruby
|
336
339
|
|
337
340
|
* Of course you must have installed whichever databases you want to test. The default set is: PostgreSQL, MySQL, and SQLite3.
|
338
341
|
|
339
|
-
* For PostgreSQL and MySQL the tests need a db user with permissions to create and access databases: The default username used by the specs is '
|
342
|
+
* For PostgreSQL and MySQL the tests need a db user with permissions to create and access databases: The default username used by the specs is 'schema_plus' for both PostgreSQL and MySQL; you can change them via:
|
340
343
|
|
341
344
|
$ export POSTGRESQL_DB_USER = pgusername
|
342
345
|
$ export MYSQL_DB_USER = mysqlusername
|
@@ -377,10 +380,3 @@ By default it runs on a matrix of postgresql, mysql2, and sqlite3, for all rubie
|
|
377
380
|
$ ./runspecs --quick --rspec -- spec/migration_spec.rb -e 'default name'
|
378
381
|
|
379
382
|
Contributions to making the testing process itself easier and better will also be gratefully accepted!
|
380
|
-
|
381
|
-
|
382
|
-
-
|
383
|
-
|
384
|
-
|
385
|
-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/lomba/schema_plus/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
386
|
-
|
data/Rakefile
CHANGED
@@ -37,7 +37,7 @@ end
|
|
37
37
|
|
38
38
|
DATABASES = %w[schema_plus_test]
|
39
39
|
[
|
40
|
-
{ namespace: :postgresql, uservar: 'POSTGRESQL_DB_USER', defaultuser: '
|
40
|
+
{ namespace: :postgresql, uservar: 'POSTGRESQL_DB_USER', defaultuser: 'schema_plus', create: "createdb -U '%{user}' %{dbname}", drop: "dropdb -U '%{user}' %{dbname}" },
|
41
41
|
{ namespace: :mysql, uservar: 'MYSQL_DB_USER', defaultuser: 'schema_plus', create: "mysqladmin -u '%{user}' create %{dbname}", drop: "mysqladmin -u '%{user}' -f drop %{dbname}" }
|
42
42
|
].each do |db|
|
43
43
|
namespace db[:namespace] do
|
@@ -10,9 +10,10 @@ module SchemaPlus
|
|
10
10
|
base.alias_method_chain :initialize, :schema_plus
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
attr_accessor :conditions
|
14
14
|
attr_reader :expression
|
15
15
|
attr_reader :kind
|
16
|
+
attr_reader :operator_classes
|
16
17
|
|
17
18
|
def case_sensitive?
|
18
19
|
@case_sensitive
|
@@ -27,9 +28,11 @@ module SchemaPlus
|
|
27
28
|
@expression = options[:expression]
|
28
29
|
@kind = options[:kind]
|
29
30
|
@case_sensitive = options.include?(:case_sensitive) ? options[:case_sensitive] : true
|
31
|
+
@operator_classes = options[:operator_classes] || {}
|
30
32
|
else # backwards compatibility
|
31
33
|
initialize_without_schema_plus(*args)
|
32
34
|
@case_sensitive = true
|
35
|
+
@operator_classes = {}
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
@@ -43,6 +46,7 @@ module SchemaPlus
|
|
43
46
|
opts[:expression] = expression unless expression.nil?
|
44
47
|
opts[:kind] = kind unless kind.nil?
|
45
48
|
opts[:case_sensitive] = case_sensitive? unless @case_sensitive.nil?
|
49
|
+
opts[:operator_classes] = @operator_classes unless @operator_classes.nil?
|
46
50
|
opts
|
47
51
|
end
|
48
52
|
|
@@ -56,6 +60,7 @@ module SchemaPlus
|
|
56
60
|
return false unless self.conditions == other.conditions
|
57
61
|
return false unless self.expression == other.expression
|
58
62
|
return false unless self.kind == other.kind
|
63
|
+
return false unless self.operator_classes == other.operator_classes
|
59
64
|
return false unless !!self.case_sensitive? == !!other.case_sensitive?
|
60
65
|
true
|
61
66
|
end
|
@@ -73,6 +73,7 @@ module SchemaPlus
|
|
73
73
|
# * +:conditions+ - SQL conditions for the WHERE clause of the index
|
74
74
|
# * +:expression+ - SQL expression to index. column_name can be nil or ommitted, in which case :name must be provided
|
75
75
|
# * +:kind+ - index method for Postgresql to use
|
76
|
+
# * +:operator_class+ - an operator class name or a hash mapping column name to operator class name
|
76
77
|
# * +:case_sensitive - setting to +false+ is a shorthand for :expression => 'LOWER(column_name)'
|
77
78
|
#
|
78
79
|
# The <tt>:case_sensitive => false</tt> option ties in with Rails built-in support for case-insensitive searching:
|
@@ -95,6 +96,10 @@ module SchemaPlus
|
|
95
96
|
index_name = options[:name] || index_name(table_name, column_names)
|
96
97
|
conditions = options[:conditions]
|
97
98
|
kind = options[:kind]
|
99
|
+
operator_classes = options[:operator_class]
|
100
|
+
if operator_classes and not operator_classes.is_a? Hash
|
101
|
+
operator_classes = Hash[column_names.map {|name| [name, operator_classes]}]
|
102
|
+
end
|
98
103
|
|
99
104
|
if expression = options[:expression] then
|
100
105
|
raise ArgumentError, "Cannot specify :case_sensitive => false with an expression. Use LOWER(column_name)" if options[:case_sensitive] == false
|
@@ -106,6 +111,9 @@ module SchemaPlus
|
|
106
111
|
sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} #{expression}"
|
107
112
|
else
|
108
113
|
option_strings = Hash[column_names.map {|name| [name, '']}]
|
114
|
+
(operator_classes||{}).each do |column, opclass|
|
115
|
+
option_strings[column] += " #{opclass}" if opclass
|
116
|
+
end
|
109
117
|
option_strings = add_index_sort_order(option_strings, column_names, options)
|
110
118
|
|
111
119
|
if options[:case_sensitive] == false
|
@@ -141,7 +149,8 @@ module SchemaPlus
|
|
141
149
|
result = query(<<-SQL, name)
|
142
150
|
|
143
151
|
SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid,
|
144
|
-
m.amname, pg_get_expr(d.indpred, t.oid) as conditions, pg_get_expr(d.indexprs, t.oid) as expression
|
152
|
+
m.amname, pg_get_expr(d.indpred, t.oid) as conditions, pg_get_expr(d.indexprs, t.oid) as expression,
|
153
|
+
d.indclass
|
145
154
|
FROM pg_class t
|
146
155
|
INNER JOIN pg_index d ON t.oid = d.indrelid
|
147
156
|
INNER JOIN pg_class i ON d.indexrelid = i.oid
|
@@ -153,9 +162,10 @@ module SchemaPlus
|
|
153
162
|
ORDER BY i.relname
|
154
163
|
SQL
|
155
164
|
|
156
|
-
result.map do |(index_name, is_unique, indkey, inddef, oid, kind, conditions, expression)|
|
165
|
+
result.map do |(index_name, is_unique, indkey, inddef, oid, kind, conditions, expression, indclass)|
|
157
166
|
unique = (is_unique == 't' || is_unique == true) # The test against true is for JDBC which is returning a boolean and not a String.
|
158
167
|
index_keys = indkey.split(" ")
|
168
|
+
opclasses = indclass.split(" ")
|
159
169
|
|
160
170
|
rows = query(<<-SQL, "Columns for index #{index_name} on #{table_name}")
|
161
171
|
SELECT CAST(a.attnum as VARCHAR), a.attname, t.typname
|
@@ -189,6 +199,20 @@ module SchemaPlus
|
|
189
199
|
end
|
190
200
|
end
|
191
201
|
|
202
|
+
opclass_name = {}
|
203
|
+
rows = query(<<-SQL, "Op classes for index #{index_name} on #{table_name}")
|
204
|
+
SELECT oid, opcname FROM pg_opclass
|
205
|
+
WHERE (NOT opcdefault) AND oid IN (#{opclasses.join(',')})
|
206
|
+
SQL
|
207
|
+
rows.each do |oid, opcname|
|
208
|
+
opclass_name[oid.to_s] = opcname
|
209
|
+
end
|
210
|
+
operator_classes = {}
|
211
|
+
index_keys.zip(opclasses).each do |index_key, opclass|
|
212
|
+
operator_classes[columns[index_key]] = opclass_name[opclass]
|
213
|
+
end
|
214
|
+
operator_classes.delete_if{|k,v| v.nil?}
|
215
|
+
|
192
216
|
# add info on sort order for columns (only desc order is explicitly specified, asc is the default)
|
193
217
|
desc_order_columns = inddef.scan(/(\w+) DESC/).flatten
|
194
218
|
orders = desc_order_columns.any? ? Hash[column_names.map {|column| [column, desc_order_columns.include?(column) ? :desc : :asc]}] : {}
|
@@ -200,6 +224,7 @@ module SchemaPlus
|
|
200
224
|
:conditions => conditions,
|
201
225
|
:case_sensitive => case_sensitive,
|
202
226
|
:kind => kind.downcase == "btree" ? nil : kind,
|
227
|
+
:operator_classes => operator_classes,
|
203
228
|
:expression => expression)
|
204
229
|
end
|
205
230
|
end
|
@@ -34,13 +34,27 @@ module SchemaPlus
|
|
34
34
|
execute('PRAGMA FOREIGN_KEYS = ON')
|
35
35
|
end
|
36
36
|
|
37
|
+
def supports_partial_indexes? #:nodoc:
|
38
|
+
# unfortunately with the current setup there's no easy way to
|
39
|
+
# test multiple SQLite3 versions. Currently travis-ci uses
|
40
|
+
# SQLite3 version 3.7 but local development on OS X uses 3.8.
|
41
|
+
SQLite3.libversion >= 3008000
|
42
|
+
end
|
43
|
+
|
37
44
|
def indexes_with_schema_plus(table_name, name = nil)
|
38
45
|
indexes = indexes_without_schema_plus(table_name, name)
|
39
46
|
exec_query("SELECT name, sql FROM sqlite_master WHERE type = 'index'").map do |row|
|
40
|
-
|
41
|
-
|
47
|
+
sql = row['sql']
|
48
|
+
index = nil
|
49
|
+
getindex = -> { index ||= indexes.detect { |i| i.name == row['name'] } }
|
50
|
+
if (desc_columns = sql.scan(/['"`]?(\w+)['"`]? DESC\b/).flatten).any?
|
51
|
+
getindex.call()
|
42
52
|
index.orders = Hash[index.columns.map {|column| [column, desc_columns.include?(column) ? :desc : :asc]}]
|
43
53
|
end
|
54
|
+
if (conditions = sql.match(/\bWHERE\s+(.*)/i))
|
55
|
+
getindex.call()
|
56
|
+
index.conditions = conditions[1]
|
57
|
+
end
|
44
58
|
end
|
45
59
|
indexes
|
46
60
|
end
|
@@ -139,6 +139,7 @@ module SchemaPlus
|
|
139
139
|
index_lengths = index.lengths.compact if index.lengths.is_a?(Array)
|
140
140
|
dump << ", :length => #{Hash[*index.columns.zip(index.lengths).flatten].inspect}" if index_lengths.present?
|
141
141
|
dump << ", :order => {" + index.orders.map{|column, val| "#{column.inspect} => #{val.inspect}"}.join(", ") + "}" unless index.orders.blank?
|
142
|
+
dump << ", :operator_class => {" + index.operator_classes.map{|column, val| "#{column.inspect} => #{val.inspect}"}.join(", ") + "}" unless index.operator_classes.blank?
|
142
143
|
else
|
143
144
|
dump << ", :expression => #{index.expression.inspect}"
|
144
145
|
end
|
data/lib/schema_plus/version.rb
CHANGED
data/runspecs
CHANGED
@@ -5,7 +5,7 @@ require 'ostruct'
|
|
5
5
|
require 'shellwords'
|
6
6
|
require 'tempfile'
|
7
7
|
|
8
|
-
RUBY_VERSIONS = %W[jruby 1.9.3 2.
|
8
|
+
RUBY_VERSIONS = %W[jruby 1.9.3 2.1.3]
|
9
9
|
RAILS_VERSIONS = %W[3.2 4.0 4.1]
|
10
10
|
DB_ADAPTERS = %W[postgresql mysql mysql2 sqlite3]
|
11
11
|
|
@@ -77,7 +77,13 @@ combos = o.ruby_versions.product(o.rails_versions, o.db_adapters).map{|product|
|
|
77
77
|
end
|
78
78
|
}
|
79
79
|
|
80
|
-
|
80
|
+
case
|
81
|
+
when system("which -s chruby-exec")
|
82
|
+
def ruby_version_selector(ruby)
|
83
|
+
"SHELL=`which bash` chruby-exec #{ruby} --"
|
84
|
+
end
|
85
|
+
|
86
|
+
when system("which -s rvm")
|
81
87
|
# using rvm
|
82
88
|
def ruby_version_selector(ruby)
|
83
89
|
"rvm #{ruby} do"
|
@@ -120,7 +126,7 @@ combos.each_with_index do |combo, n|
|
|
120
126
|
"bundle exec rake #{db_adapter}:spec"
|
121
127
|
end
|
122
128
|
|
123
|
-
command = %Q{BUNDLE_GEMFILE="#{File.join(GEMFILES_DIR, "rails-#{rails}", "Gemfile.#{db_adapter}")}" #{ruby_version_selector(ruby)} #{cmd} #{Shellwords.join(ARGV)}}
|
129
|
+
command = %Q{/usr/bin/env BUNDLE_GEMFILE="#{File.join(GEMFILES_DIR, "rails-#{rails}", "Gemfile.#{db_adapter}")}" #{ruby_version_selector(ruby)} #{cmd} #{Shellwords.join(ARGV)}}
|
124
130
|
|
125
131
|
puts "\n\n*** ruby version #{ruby} - rails version #{rails} - db adapter: #{db_adapter} [#{n+1} of #{combos.size}]\n\n#{command}"
|
126
132
|
|
data/schema_plus.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.required_ruby_version = ">= 1.9.2"
|
10
10
|
s.authors = ["Ronen Barzel", "Michal Lomnicki"]
|
11
11
|
s.email = ["ronen@barzel.org", "michal.lomnicki@gmail.com"]
|
12
|
-
s.homepage = "https://github.com/
|
12
|
+
s.homepage = "https://github.com/SchemaPlus/schema_plus"
|
13
13
|
s.summary = "Enhances ActiveRecord schema mechanism, including more DRY index creation and support for foreign key constraints and views."
|
14
14
|
s.description = "SchemaPlus is an ActiveRecord extension that provides enhanced capabilities for schema definition and querying, including: enhanced and more DRY index capabilities, support and automation for foreign key constraints, and support for views."
|
15
15
|
s.license = 'MIT'
|
@@ -122,7 +122,7 @@ describe "Index definition" do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
|
125
|
-
context "when index is partial
|
125
|
+
context "when index is partial" do
|
126
126
|
before(:each) do
|
127
127
|
migration.execute "CREATE INDEX users_login_index ON users(login) WHERE deleted_at IS NULL"
|
128
128
|
User.reset_column_information
|
@@ -142,10 +142,10 @@ describe "Index definition" do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it "defines conditions" do
|
145
|
-
expect(@index.conditions).to
|
145
|
+
expect(@index.conditions).to match %r{[(]?deleted_at IS NULL[)]?}
|
146
146
|
end
|
147
147
|
|
148
|
-
end
|
148
|
+
end if ::ActiveRecord::Migration.supports_partial_indexes?
|
149
149
|
|
150
150
|
context "when index contains expression", :postgresql => :only do
|
151
151
|
before(:each) do
|
data/spec/index_spec.rb
CHANGED
@@ -13,6 +13,7 @@ describe "index" do
|
|
13
13
|
define_schema(:auto_create => false) do
|
14
14
|
create_table :users, :force => true do |t|
|
15
15
|
t.string :login
|
16
|
+
t.text :address
|
16
17
|
t.datetime :deleted_at
|
17
18
|
end
|
18
19
|
|
@@ -104,6 +105,16 @@ describe "index" do
|
|
104
105
|
expect(index_for(:login).kind).to eq('hash')
|
105
106
|
end
|
106
107
|
|
108
|
+
it "should assign operator_class" do
|
109
|
+
add_index(:users, :login, :operator_class => 'varchar_pattern_ops')
|
110
|
+
expect(index_for(:login).operator_classes).to eq({"login" => 'varchar_pattern_ops'})
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should assign multiple operator_classes" do
|
114
|
+
add_index(:users, [:login, :address], :operator_class => {:login => 'varchar_pattern_ops', :address => 'text_pattern_ops'})
|
115
|
+
expect(index_for([:login, :address]).operator_classes).to eq({"login" => 'varchar_pattern_ops', "address" => 'text_pattern_ops'})
|
116
|
+
end
|
117
|
+
|
107
118
|
it "should allow to specify actual expression only" do
|
108
119
|
add_index(:users, :expression => "upper(login)", :name => 'users_login_index')
|
109
120
|
@index = User.indexes.detect { |i| i.name == 'users_login_index' }
|
data/spec/schema_dumper_spec.rb
CHANGED
@@ -214,6 +214,12 @@ describe "Schema dump" do
|
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
|
+
it "should define operator_class" do
|
218
|
+
with_index Post, :body, :operator_class => 'text_pattern_ops' do
|
219
|
+
expect(dump_posts).to match(to_regexp(%q{t.index ["body"], :name => "index_posts_on_body", :operator_class => {"body" => "text_pattern_ops"}}))
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
217
223
|
it "should dump unique: true with expression (Issue #142)" do
|
218
224
|
with_index Post, :name => "posts_user_body_index", :unique => true, :expression => "BTRIM(LOWER(body))" do
|
219
225
|
expect(dump_posts).to match(%r{#{to_regexp(%q{t.index :name => "posts_user_body_index", :unique => true, :expression => "btrim(lower(body))"})}$})
|
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: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronen Barzel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -192,7 +192,7 @@ files:
|
|
192
192
|
- spec/support/matchers/have_index.rb
|
193
193
|
- spec/support/matchers/reference.rb
|
194
194
|
- spec/views_spec.rb
|
195
|
-
homepage: https://github.com/
|
195
|
+
homepage: https://github.com/SchemaPlus/schema_plus
|
196
196
|
licenses:
|
197
197
|
- MIT
|
198
198
|
metadata: {}
|