schema_plus_indexes 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -0
- data/README.md +6 -1
- data/gemfiles/activerecord-4.2/Gemfile.postgresql +2 -2
- data/gemfiles/activerecord-5.0/Gemfile.postgresql +2 -2
- data/gemfiles/activerecord-5.1/Gemfile.postgresql +2 -2
- data/gemfiles/activerecord-5.2/Gemfile.base +3 -0
- data/gemfiles/activerecord-5.2/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-5.2/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-5.2/Gemfile.sqlite3 +10 -0
- data/lib/schema_plus/indexes.rb +1 -0
- data/lib/schema_plus/indexes/active_record/base.rb +1 -1
- data/lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb +34 -11
- data/lib/schema_plus/indexes/remove_if_exists.rb +16 -6
- data/lib/schema_plus/indexes/version.rb +1 -1
- data/schema_dev.yml +1 -0
- data/schema_plus_indexes.gemspec +2 -2
- data/spec/index_definition_spec.rb +8 -2
- data/spec/index_spec.rb +7 -2
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 01e90c31ef7cb567d005ad99b6c5532096e1d1128f2427686f7b4024ea49c156
|
4
|
+
data.tar.gz: 240e9d3ca09e91d1b0a3c04946876427310b19ec243c491a40b672de41287d0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a404889345f7a83ee71d6b9f25582ae78d492b919f447834c6934bffafe535bf2ecee76da798423fc549f56e3e1399554fe71bcf821c28a2a3876ac5605ac568
|
7
|
+
data.tar.gz: 575d9ef92201129e21f1f789c88edf42f29a5dd65d26a5c296e56477a43ce12f5d738ed4d0096b199321732ec42fc71b255410cf62b501535578e12243615fb8
|
data/.travis.yml
CHANGED
@@ -16,6 +16,9 @@ gemfile:
|
|
16
16
|
- gemfiles/activerecord-5.1/Gemfile.mysql2
|
17
17
|
- gemfiles/activerecord-5.1/Gemfile.postgresql
|
18
18
|
- gemfiles/activerecord-5.1/Gemfile.sqlite3
|
19
|
+
- gemfiles/activerecord-5.2/Gemfile.mysql2
|
20
|
+
- gemfiles/activerecord-5.2/Gemfile.postgresql
|
21
|
+
- gemfiles/activerecord-5.2/Gemfile.sqlite3
|
19
22
|
env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
|
20
23
|
addons:
|
21
24
|
postgresql: '9.4'
|
data/README.md
CHANGED
@@ -108,12 +108,17 @@ schema_plus_indexes is tested on
|
|
108
108
|
* ruby **2.3.1** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql**
|
109
109
|
* ruby **2.3.1** with activerecord **5.0**, using **mysql2**, **sqlite3** or **postgresql**
|
110
110
|
* ruby **2.3.1** with activerecord **5.1**, using **mysql2**, **sqlite3** or **postgresql**
|
111
|
+
* ruby **2.3.1** with activerecord **5.2**, using **mysql2**, **sqlite3** or **postgresql**
|
111
112
|
|
112
113
|
<!-- SCHEMA_DEV: MATRIX - end -->
|
113
114
|
|
114
115
|
## Release Notes
|
115
116
|
|
116
|
-
### v0.
|
117
|
+
### v0.3.1
|
118
|
+
|
119
|
+
* Support AR 5.2. Thanks to [@jeremyyap](https://github.com/jeremyyap)
|
120
|
+
|
121
|
+
### v0.3.0
|
117
122
|
|
118
123
|
* Supports AR 5.1. Thanks to [@iagopiimenta](https://github.com/iagopiimenta)
|
119
124
|
|
data/lib/schema_plus/indexes.rb
CHANGED
@@ -3,19 +3,42 @@ module SchemaPlus::Indexes
|
|
3
3
|
module ConnectionAdapters
|
4
4
|
|
5
5
|
module IndexDefinition
|
6
|
+
if Gem::Version.new(::ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.2')
|
7
|
+
attr_accessor :orders
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
def initialize(*args) #:nodoc:
|
10
|
+
# same args as add_index(table_name, column_names, options)
|
11
|
+
if args.length == 3 and Hash === args.last
|
12
|
+
table_name, column_names, options = args + [{}]
|
13
|
+
|
14
|
+
super table_name, options[:name], options[:unique], column_names, options.except(:name, :unique)
|
15
|
+
else # backwards compatibility
|
16
|
+
super
|
17
|
+
end
|
18
|
+
unless orders.blank?
|
19
|
+
# fill out orders with :asc when undefined. make sure hash ordering
|
20
|
+
# follows column ordering.
|
21
|
+
if self.orders.is_a?(Hash)
|
22
|
+
self.orders = Hash[columns.map{|column| [column, orders[column] || :asc]}]
|
23
|
+
else
|
24
|
+
self.orders = Hash[columns.map{|column| [column, orders || :asc]}]
|
25
|
+
end
|
26
|
+
end
|
14
27
|
end
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
|
28
|
+
else
|
29
|
+
def initialize(*args) #:nodoc:
|
30
|
+
# same args as add_index(table_name, column_names, options)
|
31
|
+
if args.length == 3 and Hash === args.last
|
32
|
+
table_name, column_names, options = args + [{}]
|
33
|
+
super table_name, options[:name], options[:unique], column_names, options[:length], options[:orders], options[:where], options[:type], options[:using]
|
34
|
+
else # backwards compatibility
|
35
|
+
super
|
36
|
+
end
|
37
|
+
unless orders.blank?
|
38
|
+
# fill out orders with :asc when undefined. make sure hash ordering
|
39
|
+
# follows column ordering.
|
40
|
+
self.orders = Hash[columns.map{|column| [column, orders[column] || :asc]}]
|
41
|
+
end
|
19
42
|
end
|
20
43
|
end
|
21
44
|
|
@@ -2,12 +2,22 @@ module SchemaPlus::Indexes
|
|
2
2
|
module RemoveIfExists
|
3
3
|
# Extends rails' remove_index to include this options:
|
4
4
|
# :if_exists
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
if Gem::Version.new(::ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.1')
|
6
|
+
def remove_index(table_name, *args)
|
7
|
+
options = args.extract_options!
|
8
|
+
if_exists = options.delete(:if_exists)
|
9
|
+
args << options if options.any?
|
10
|
+
return if if_exists && !index_name_exists?(table_name, options[:name] || index_name(table_name, *args))
|
11
|
+
super table_name, *args
|
12
|
+
end
|
13
|
+
else
|
14
|
+
def remove_index(table_name, *args)
|
15
|
+
options = args.extract_options!
|
16
|
+
if_exists = options.delete(:if_exists)
|
17
|
+
args << options if options.any?
|
18
|
+
return if if_exists && !index_name_exists?(table_name, options[:name] || index_name(table_name, *args), nil)
|
19
|
+
super table_name, *args
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
13
23
|
end
|
data/schema_dev.yml
CHANGED
data/schema_plus_indexes.gemspec
CHANGED
@@ -17,13 +17,13 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency "activerecord", ">= 4.2", "< 5.
|
20
|
+
gem.add_dependency "activerecord", ">= 4.2", "< 5.3"
|
21
21
|
gem.add_dependency "schema_plus_core"
|
22
22
|
gem.add_dependency "its-it", "~> 1.2"
|
23
23
|
|
24
24
|
gem.add_development_dependency "bundler", "~> 1.7"
|
25
25
|
gem.add_development_dependency "rake", "~> 10.0"
|
26
|
-
gem.add_development_dependency "rspec", "~> 3.0
|
26
|
+
gem.add_development_dependency "rspec", "~> 3.0"
|
27
27
|
gem.add_development_dependency "schema_dev", "~> 3.6"
|
28
28
|
gem.add_development_dependency "simplecov"
|
29
29
|
gem.add_development_dependency "simplecov-gem-profile"
|
@@ -23,8 +23,14 @@ describe "Index definition" do
|
|
23
23
|
class Post < ::ActiveRecord::Base ; end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.1')
|
27
|
+
after(:each) do
|
28
|
+
migration.remove_index :users, :name => 'users_login_index' if migration.index_name_exists?(:users, 'users_login_index')
|
29
|
+
end
|
30
|
+
else
|
31
|
+
after(:each) do
|
32
|
+
migration.remove_index :users, :name => 'users_login_index' if migration.index_name_exists?(:users, 'users_login_index', nil)
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
context "when index is multicolumn" do
|
data/spec/index_spec.rb
CHANGED
@@ -53,6 +53,11 @@ describe "index" do
|
|
53
53
|
expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :asc})
|
54
54
|
end
|
55
55
|
|
56
|
+
it "should assign order (all same direction)", :mysql => :skip do
|
57
|
+
add_index(:users, [:login, :deleted_at], :order => {:login => :desc, :deleted_at => :desc})
|
58
|
+
expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :desc})
|
59
|
+
end
|
60
|
+
|
56
61
|
context "for duplicate index" do
|
57
62
|
it "should not complain if the index is the same" do
|
58
63
|
add_index(:users, :login)
|
@@ -64,7 +69,7 @@ describe "index" do
|
|
64
69
|
it "should complain if the index is different" do
|
65
70
|
add_index(:users, :login, :unique => true)
|
66
71
|
expect(index_for(:login)).not_to be_nil
|
67
|
-
expect { add_index(:users, :login) }.to raise_error
|
72
|
+
expect { add_index(:users, :login) }.to raise_error(ArgumentError, /already exists/)
|
68
73
|
expect(index_for(:login)).not_to be_nil
|
69
74
|
end
|
70
75
|
end
|
@@ -150,7 +155,7 @@ describe "index" do
|
|
150
155
|
it "raises exception if doesn't exist" do
|
151
156
|
expect {
|
152
157
|
remove_index :users, :login
|
153
|
-
}.to raise_error
|
158
|
+
}.to raise_error(ArgumentError)
|
154
159
|
end
|
155
160
|
|
156
161
|
it "doesn't raise exception with :if_exists" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_plus_indexes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ronen barzel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '5.
|
22
|
+
version: '5.3'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '5.
|
32
|
+
version: '5.3'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: schema_plus_core
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: 3.0
|
95
|
+
version: '3.0'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 3.0
|
102
|
+
version: '3.0'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: schema_dev
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,6 +168,10 @@ files:
|
|
168
168
|
- gemfiles/activerecord-5.1/Gemfile.mysql2
|
169
169
|
- gemfiles/activerecord-5.1/Gemfile.postgresql
|
170
170
|
- gemfiles/activerecord-5.1/Gemfile.sqlite3
|
171
|
+
- gemfiles/activerecord-5.2/Gemfile.base
|
172
|
+
- gemfiles/activerecord-5.2/Gemfile.mysql2
|
173
|
+
- gemfiles/activerecord-5.2/Gemfile.postgresql
|
174
|
+
- gemfiles/activerecord-5.2/Gemfile.sqlite3
|
171
175
|
- lib/schema_plus/indexes.rb
|
172
176
|
- lib/schema_plus/indexes/active_record/base.rb
|
173
177
|
- lib/schema_plus/indexes/active_record/connection_adapters/abstract_adapter.rb
|
@@ -213,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
217
|
version: '0'
|
214
218
|
requirements: []
|
215
219
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.
|
220
|
+
rubygems_version: 2.7.8
|
217
221
|
signing_key:
|
218
222
|
specification_version: 4
|
219
223
|
summary: Adds shorthands and conveniences to ActiveRecord's handling of indexes
|