schema_plus_pg_indexes 0.1.9 → 0.1.10
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/gemfiles/activerecord-4.2/Gemfile.base +1 -1
- data/lib/schema_plus_pg_indexes/middleware/postgresql/dumper.rb +5 -5
- data/lib/schema_plus_pg_indexes/version.rb +1 -1
- data/schema_plus_pg_indexes.gemspec +2 -1
- data/spec/schema_dumper_spec.rb +15 -15
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d010d734ff72f02495576fa113afcfa6382f78fb
|
4
|
+
data.tar.gz: ea0f894d22af03ff5f74dd7b567d2d53360e7761
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8817842bf9b32af012479c19ddb7e872dceacc99ce20a9382469854d145c30e2fe6a81ec30fee987dbc3f4957f92011a2fa719bdb04c9962f387d6c16da2f16a
|
7
|
+
data.tar.gz: af6ade8cfd3eaaee33202b8ab361fdd18fbcafcf9d6b3263c3efbe45c82cd7a8e20b7994b242dc39eed20e82825c67079a507f7cd34bde919057f1fcec2d627f
|
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.10 - Upgrade to schmea_plus_core 1.0
|
64
65
|
* v0.1.9 - Bug fix: multiple expression indexes (#8)
|
65
66
|
* v0.1.8 - Bug fix: expression with operator class (#7)
|
66
67
|
* v0.1.7 - Bug fix: mix of columns & expressions (#5)
|
@@ -11,13 +11,13 @@ module SchemaPlusPgIndexes
|
|
11
11
|
|
12
12
|
env.table.indexes.each do |index_dump|
|
13
13
|
index_def = index_defs.find(&its.name == index_dump.name)
|
14
|
-
index_dump.
|
15
|
-
index_dump.
|
14
|
+
index_dump.options[:case_sensitive] = false unless index_def.case_sensitive?
|
15
|
+
index_dump.options[:expression] = index_def.expression if index_def.expression and index_def.case_sensitive?
|
16
16
|
unless index_def.operator_classes.blank?
|
17
17
|
if index_def.columns.uniq.length <= 1 && index_def.operator_classes.values.uniq.length == 1
|
18
|
-
index_dump.
|
18
|
+
index_dump.options[:operator_class] = index_def.operator_classes.values.first
|
19
19
|
else
|
20
|
-
index_dump.
|
20
|
+
index_dump.options[:operator_class] = index_def.operator_classes
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -31,7 +31,7 @@ module SchemaPlusPgIndexes
|
|
31
31
|
index_defs = Dumper.get_index_definitions(env, env.table)
|
32
32
|
|
33
33
|
env.table.indexes.select(&its.columns.blank?).each do |index|
|
34
|
-
env.table.statements << "t.index name:
|
34
|
+
env.table.statements << "t.index #{{name: index.name}.merge(index.options).to_s.sub(/^{(.*)}$/, '\1')}"
|
35
35
|
env.table.indexes.delete(index)
|
36
36
|
end
|
37
37
|
end
|
@@ -19,11 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_dependency "activerecord", "~> 4.2"
|
21
21
|
spec.add_dependency "schema_plus_indexes", "~> 0.1", ">= 0.1.3"
|
22
|
+
spec.add_dependency "schema_plus_core", "~> 1.0"
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
26
|
spec.add_development_dependency "rspec", "~> 3.0.0"
|
26
|
-
spec.add_development_dependency "schema_dev", "~> 3.
|
27
|
+
spec.add_development_dependency "schema_dev", "~> 3.6"
|
27
28
|
spec.add_development_dependency "simplecov"
|
28
29
|
spec.add_development_dependency "simplecov-gem-profile"
|
29
30
|
end
|
data/spec/schema_dumper_spec.rb
CHANGED
@@ -48,20 +48,20 @@ describe "Schema dump" do
|
|
48
48
|
|
49
49
|
it "should define case insensitive index" do
|
50
50
|
with_index Post, [:body, :string_no_default], :case_sensitive => false do
|
51
|
-
expect(dump_posts).to match(/"body"
|
51
|
+
expect(dump_posts).to match(/"body".*:index=>{.*:with=>.*string_no_default.*:case_sensitive=>false/)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should define index with type cast" do
|
56
56
|
with_index Post, [:integer_col], :name => "index_with_type_cast", :expression => "LOWER(integer_col::text)" do
|
57
|
-
expect(dump_posts).to include(%q{t.index name
|
57
|
+
expect(dump_posts).to include(%q{t.index :name=>"index_with_type_cast", :expression=>"lower((integer_col)::text)"})
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
|
62
62
|
it "should define case insensitive index with mixed ids and strings" do
|
63
63
|
with_index Post, [:user_id, :str_short, :short_id, :body], :case_sensitive => false do
|
64
|
-
expect(dump_posts).to match(/user_id
|
64
|
+
expect(dump_posts).to match(/user_id.*:index=>{.* :with=>\["str_short", "short_id", "body"\], :case_sensitive=>false}/)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -69,77 +69,77 @@ describe "Schema dump" do
|
|
69
69
|
col_name = "#{col_type}_col"
|
70
70
|
it "should define case insensitive index that includes an #{col_type}" do
|
71
71
|
with_index Post, [:user_id, :str_short, col_name, :body], :case_sensitive => false do
|
72
|
-
expect(dump_posts).to match(/user_id
|
72
|
+
expect(dump_posts).to match(/user_id.*:index=>{.* :with=>\["str_short", "#{col_name}", "body"\], :case_sensitive=>false}/)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should define where" do
|
78
78
|
with_index Post, :user_id, :name => "posts_user_id_index", :where => "user_id IS NOT NULL" do
|
79
|
-
expect(dump_posts).to match(/user_id
|
79
|
+
expect(dump_posts).to match(/user_id.*:index=>{.*:where=>"\(user_id IS NOT NULL\)"}/)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should define expression" do
|
84
84
|
with_index Post, :name => "posts_freaky_index", :expression => "USING hash (least(id, user_id))" do
|
85
|
-
expect(dump_posts).to include(%q{t.index name
|
85
|
+
expect(dump_posts).to include(%q{t.index :name=>"posts_freaky_index", :using=>:hash, :expression=>"LEAST(id, user_id)"})
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should define multi-column with expression" do
|
90
90
|
with_index Post, :body, :expression => "(least(id, user_id))" do
|
91
|
-
expect(dump_posts).to match(/body.*index
|
91
|
+
expect(dump_posts).to match(/body.*index.*:expression=>"LEAST\(id, user_id\)"/)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
|
96
96
|
it "should define operator_class" do
|
97
97
|
with_index Post, :body, :operator_class => 'text_pattern_ops' do
|
98
|
-
expect(dump_posts).to match(/body
|
98
|
+
expect(dump_posts).to match(/body.*:index=>.*:operator_class=>"text_pattern_ops"/)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should define expression with operator_class" do
|
103
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
|
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
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
|
109
109
|
it "should define multi-column operator classes " do
|
110
110
|
with_index Post, [:body, :string_no_default], :operator_class => {body: 'text_pattern_ops', string_no_default: 'varchar_pattern_ops' } do
|
111
|
-
expect(dump_posts).to match(/body
|
111
|
+
expect(dump_posts).to match(/body.*:index=>.*:operator_class=>{"body"=>"text_pattern_ops", "string_no_default"=>"varchar_pattern_ops"}/)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should define multi-column operator classes even if one column has no operator" do
|
116
116
|
with_index Post, [:body, :string_no_default], :operator_class => {string_no_default: 'varchar_pattern_ops'} do
|
117
|
-
expect(dump_posts).to match(/body
|
117
|
+
expect(dump_posts).to match(/body.*:index=>.*:operator_class=>{"string_no_default"=>"varchar_pattern_ops"}/)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'should dump proper operator_class with case_sensitive => false' do
|
122
122
|
with_index Post, :body, :operator_class => 'text_pattern_ops', :case_sensitive => false do
|
123
|
-
expect(dump_posts).to match(/body
|
123
|
+
expect(dump_posts).to match(/body.*:index=>.*:name=>"index_posts_on_body", :case_sensitive=>false, :operator_class=>"text_pattern_ops"/)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should dump unique: true with expression (Issue #142)" do
|
128
128
|
with_index Post, :name => "posts_user_body_index", :unique => true, :expression => "BTRIM(LOWER(body))" do
|
129
|
-
expect(dump_posts).to include(%q{t.index name
|
129
|
+
expect(dump_posts).to include(%q{t.index :name=>"posts_user_body_index", :unique=>true, :expression=>"btrim(lower(body))"})
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
133
|
|
134
134
|
it "should not define :case_sensitive => false with non-trivial expression" do
|
135
135
|
with_index Post, :name => "posts_user_body_index", :expression => "BTRIM(LOWER(body))" do
|
136
|
-
expect(dump_posts).to include(%q{t.index name
|
136
|
+
expect(dump_posts).to include(%q{t.index :name=>"posts_user_body_index", :expression=>"btrim(lower(body))"})
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should define using" do
|
141
141
|
with_index Post, :name => "posts_body_index", :expression => "USING hash (body)" do
|
142
|
-
expect(dump_posts).to match(/body
|
142
|
+
expect(dump_posts).to match(/body.*:index=>.*:using=>:hash/)
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ronen barzel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 0.1.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: schema_plus_core
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.0'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: bundler
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,14 +106,14 @@ dependencies:
|
|
92
106
|
requirements:
|
93
107
|
- - "~>"
|
94
108
|
- !ruby/object:Gem::Version
|
95
|
-
version: '3.
|
109
|
+
version: '3.6'
|
96
110
|
type: :development
|
97
111
|
prerelease: false
|
98
112
|
version_requirements: !ruby/object:Gem::Requirement
|
99
113
|
requirements:
|
100
114
|
- - "~>"
|
101
115
|
- !ruby/object:Gem::Version
|
102
|
-
version: '3.
|
116
|
+
version: '3.6'
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
118
|
name: simplecov
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|