schema_plus_pg_indexes 0.1.7 → 0.1.8
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/README.md +1 -0
- data/lib/schema_plus_pg_indexes/middleware/postgresql/dumper.rb +1 -1
- data/lib/schema_plus_pg_indexes/middleware/postgresql/sql.rb +5 -2
- data/lib/schema_plus_pg_indexes/version.rb +1 -1
- data/spec/index_spec.rb +1 -7
- data/spec/schema_dumper_spec.rb +8 -3
- data/spec/spec_helper.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07fa2b71ce5644fe20cbee97ea3f62c18c608edf
|
4
|
+
data.tar.gz: 164420fd746ac63af76cf83348ed307b6d2c7047
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414e5cd0a8822d29a9c414e8eefab09dc6948b5c2ff9b8fba1c961a547f9d76d4efe1267bd658d1e603d80c36ff0e5f532ef137363033db7760b90fbae95f15b
|
7
|
+
data.tar.gz: 0ce973e0818352c72a27f2d98acd47e3d459c002f7fdb8b0f1a0a9b664b58046fb3b36ec2b97922ee81c56c05e05d229c098712a29a5a9d51836bfe5e3992125
|
data/README.md
CHANGED
@@ -61,6 +61,7 @@ schema_plus_pg_indexes is tested on
|
|
61
61
|
|
62
62
|
## History
|
63
63
|
|
64
|
+
* v0.1.8 - Bug fix: expression with operator class (#7)
|
64
65
|
* v0.1.7 - Bug fix: mix of columns & expressions (#5)
|
65
66
|
* v0.1.6 - Bug fix: operator class & multiple columns (#4). Thanks to [@nbudin](https://github.com/nbudin)
|
66
67
|
* v0.1.5 - Bug fix: `t.index` without column in `change_table`
|
@@ -14,7 +14,7 @@ module SchemaPlusPgIndexes
|
|
14
14
|
index_dump.add_option "case_sensitive: false" unless index_def.case_sensitive?
|
15
15
|
index_dump.add_option "expression: #{index_def.expression.inspect}" if index_def.expression and index_def.case_sensitive?
|
16
16
|
unless index_def.operator_classes.blank?
|
17
|
-
if index_def.columns.uniq.length
|
17
|
+
if index_def.columns.uniq.length <= 1 && index_def.operator_classes.values.uniq.length == 1
|
18
18
|
index_dump.add_option "operator_class: #{index_def.operator_classes.values.first.inspect}"
|
19
19
|
else
|
20
20
|
index_dump.add_option "operator_class: {" + index_def.operator_classes.map{|column, val| "#{column.inspect}=>#{val.inspect}"}.join(", ") + "}"
|
@@ -49,13 +49,15 @@ module SchemaPlusPgIndexes
|
|
49
49
|
yield env
|
50
50
|
|
51
51
|
if operator_classes and not operator_classes.is_a? Hash
|
52
|
-
|
52
|
+
val = operator_classes
|
53
|
+
operator_classes = Hash[column_names.map {|name| [name, val]}]
|
54
|
+
operator_classes[nil] = val if expression
|
53
55
|
end
|
54
56
|
|
55
57
|
if operator_classes or case_insensitive
|
56
58
|
option_strings = Hash[column_names.map {|name| [name, '']}]
|
57
59
|
(operator_classes||{}).stringify_keys.each do |column, opclass|
|
58
|
-
option_strings[column] += " #{opclass}" if opclass
|
60
|
+
option_strings[column] += " #{opclass}" if opclass and column.present?
|
59
61
|
end
|
60
62
|
option_strings = connection.send :add_index_sort_order, option_strings, column_names, options
|
61
63
|
|
@@ -72,6 +74,7 @@ module SchemaPlusPgIndexes
|
|
72
74
|
end
|
73
75
|
|
74
76
|
if expression
|
77
|
+
expression = [expression, operator_classes[nil]].compact.join(' ') if operator_classes
|
75
78
|
env.sql.columns = (env.sql.columns.split(/ *, */).reject{|col| expression =~ %r{\b#{col.gsub(/['"]/, '')}\b} } + [expression]).join(', ')
|
76
79
|
end
|
77
80
|
end
|
data/spec/index_spec.rb
CHANGED
@@ -3,19 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe "index" do
|
4
4
|
|
5
5
|
let(:migration) { ::ActiveRecord::Migration }
|
6
|
-
let(:connection) { ::ActiveRecord::Base.connection }
|
7
6
|
|
8
7
|
describe "add_index" do
|
9
8
|
|
10
9
|
class User < ::ActiveRecord::Base ; end
|
11
10
|
|
12
11
|
after(:each) do
|
13
|
-
|
14
|
-
User.indexes.each do |index|
|
15
|
-
migration.remove_index :users, name: index.name, if_exists: true
|
16
|
-
end
|
17
|
-
User.reset_column_information
|
18
|
-
end
|
12
|
+
User.reset_column_information
|
19
13
|
end
|
20
14
|
|
21
15
|
context "extra features" do
|
data/spec/schema_dumper_spec.rb
CHANGED
@@ -99,6 +99,13 @@ describe "Schema dump" do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
it "should define expression with operator_class" do
|
103
|
+
with_index Post, :name => "expr_with_opclass", :expression => "upper(str_short || string_no_default)", :operator_class => 'text_pattern_ops' do
|
104
|
+
expect(dump_posts).to include(%q{t.index name: "expr_with_opclass", expression: "upper(((str_short)::text || (string_no_default)::text))", operator_class: "text_pattern_ops"})
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
102
109
|
it "should define multi-column operator classes " do
|
103
110
|
with_index Post, [:body, :string_no_default], :operator_class => {body: 'text_pattern_ops', string_no_default: 'varchar_pattern_ops' } do
|
104
111
|
expect(dump_posts).to match(/body.*index:.*operator_class: {"body"=>"text_pattern_ops", "string_no_default"=>"varchar_pattern_ops"}/)
|
@@ -142,9 +149,7 @@ describe "Schema dump" do
|
|
142
149
|
def with_index(*args)
|
143
150
|
options = args.extract_options!
|
144
151
|
model, columns = args
|
145
|
-
ActiveRecord::Migration.
|
146
|
-
ActiveRecord::Migration.add_index(model.table_name, columns, options)
|
147
|
-
end
|
152
|
+
ActiveRecord::Migration.add_index(model.table_name, columns, options)
|
148
153
|
model.reset_column_information
|
149
154
|
yield
|
150
155
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -19,6 +19,9 @@ RSpec.configure do |config|
|
|
19
19
|
config.warnings = true
|
20
20
|
config.around(:each) do |example|
|
21
21
|
ActiveRecord::Migration.suppress_messages do
|
22
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
23
|
+
ActiveRecord::Migration.drop_table table, force: :cascade
|
24
|
+
end
|
22
25
|
example.run
|
23
26
|
end
|
24
27
|
end
|
@@ -26,7 +29,7 @@ end
|
|
26
29
|
|
27
30
|
def define_schema(&block)
|
28
31
|
ActiveRecord::Schema.define do
|
29
|
-
connection.tables.each do |table|
|
32
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
30
33
|
drop_table table, force: :cascade
|
31
34
|
end
|
32
35
|
instance_eval &block
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_plus_pg_indexes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ronen barzel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|