schema_plus_indexes 0.2.4 → 0.3.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 +3 -0
- data/README.md +7 -2
- data/gemfiles/activerecord-5.0/Gemfile.base +1 -1
- data/gemfiles/activerecord-5.1/Gemfile.base +3 -0
- data/gemfiles/activerecord-5.1/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-5.1/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-5.1/Gemfile.sqlite3 +10 -0
- data/lib/schema_plus/indexes/active_record/base.rb +1 -1
- data/lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb +5 -1
- data/lib/schema_plus/indexes/middleware/migration.rb +1 -0
- data/lib/schema_plus/indexes/remove_if_exists.rb +1 -1
- data/lib/schema_plus/indexes/version.rb +1 -1
- data/schema_dev.yml +1 -0
- data/schema_plus_indexes.gemspec +1 -1
- data/spec/index_definition_spec.rb +1 -1
- data/spec/migration_spec.rb +6 -1
- data/spec/schema_dumper_spec.rb +2 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59c1cc31f6d11ef0482b7592f398503e4de3081b
|
4
|
+
data.tar.gz: cb27adde0cb695f05991c39275bb3219fc41bffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d51dd7ccb1d59af210e3ab66a1e32dc138586e54547b88cfad701c001d3401ce2c1b7c9b781484286a8ddd13059112a801285aa50ab5bc9ae3a5431c27e89b93
|
7
|
+
data.tar.gz: 6d7744f9e799a81d8e23bdc7793b9563070c33dc9b7f2b9d09e1d8661b8d52b0278c94f512ca891b1951cbca4c94970f2feb9b4f265724a163784262543f6998
|
data/.travis.yml
CHANGED
@@ -13,6 +13,9 @@ gemfile:
|
|
13
13
|
- gemfiles/activerecord-5.0/Gemfile.mysql2
|
14
14
|
- gemfiles/activerecord-5.0/Gemfile.postgresql
|
15
15
|
- gemfiles/activerecord-5.0/Gemfile.sqlite3
|
16
|
+
- gemfiles/activerecord-5.1/Gemfile.mysql2
|
17
|
+
- gemfiles/activerecord-5.1/Gemfile.postgresql
|
18
|
+
- gemfiles/activerecord-5.1/Gemfile.sqlite3
|
16
19
|
env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
|
17
20
|
addons:
|
18
21
|
postgresql: '9.4'
|
data/README.md
CHANGED
@@ -107,14 +107,19 @@ schema_plus_indexes is tested on
|
|
107
107
|
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
|
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
|
+
* ruby **2.3.1** with activerecord **5.1**, using **mysql2**, **sqlite3** or **postgresql**
|
110
111
|
|
111
112
|
<!-- SCHEMA_DEV: MATRIX - end -->
|
112
113
|
|
113
|
-
##
|
114
|
+
## Release Notes
|
115
|
+
|
116
|
+
### v0.2.5
|
117
|
+
|
118
|
+
* Supports AR 5.1. Thanks to [@iagopiimenta](https://github.com/iagopiimenta)
|
114
119
|
|
115
120
|
### v0.2.4
|
116
121
|
|
117
|
-
* Supports AR 5.0. Thanks to [@myabc]
|
122
|
+
* Supports AR 5.0. Thanks to [@myabc](https://github.com/myabc)
|
118
123
|
|
119
124
|
|
120
125
|
### v0.2.3
|
@@ -9,7 +9,7 @@ module SchemaPlus::Indexes
|
|
9
9
|
# defind on this model's table.
|
10
10
|
#
|
11
11
|
def indexes
|
12
|
-
@indexes ||= connection.indexes(table_name
|
12
|
+
@indexes ||= connection.indexes(table_name)
|
13
13
|
end
|
14
14
|
|
15
15
|
# (reset_index_information gets called by by Middleware::Model::ResetColumnInformation)
|
@@ -25,7 +25,11 @@ module SchemaPlus::Indexes
|
|
25
25
|
return false unless self.name == other.name
|
26
26
|
return false unless Array.wrap(self.columns).collect(&:to_s).sort == Array.wrap(other.columns).collect(&:to_s).sort
|
27
27
|
return false unless !!self.unique == !!other.unique
|
28
|
-
|
28
|
+
if self.lengths.is_a?(Hash) or other.lengths.is_a?(Hash)
|
29
|
+
return false if (self.lengths || {}) != (other.lengths || {}) # treat nil same as empty hash
|
30
|
+
else
|
31
|
+
return false if Array.wrap(self.lengths).compact.sort != Array.wrap(other.lengths).compact.sort
|
32
|
+
end
|
29
33
|
return false unless self.where == other.where
|
30
34
|
return false unless (self.using||:btree) == (other.using||:btree)
|
31
35
|
true
|
@@ -44,6 +44,7 @@ module SchemaPlus::Indexes
|
|
44
44
|
yield env
|
45
45
|
rescue => e
|
46
46
|
raise unless e.message.match(/["']([^"']+)["'].*already exists/)
|
47
|
+
|
47
48
|
name = $1
|
48
49
|
existing = env.caller.indexes(env.table_name).find{|i| i.name == name}
|
49
50
|
attempted = ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(env.table_name, env.column_names, env.options.merge(:name => name))
|
@@ -6,7 +6,7 @@ module SchemaPlus::Indexes
|
|
6
6
|
options = args.extract_options!
|
7
7
|
if_exists = options.delete(:if_exists)
|
8
8
|
args << options if options.any?
|
9
|
-
return if if_exists && !index_name_exists?(table_name, options[:name] || index_name(table_name, *args),
|
9
|
+
return if if_exists && !index_name_exists?(table_name, options[:name] || index_name(table_name, *args), nil)
|
10
10
|
super table_name, *args
|
11
11
|
end
|
12
12
|
end
|
data/schema_dev.yml
CHANGED
data/schema_plus_indexes.gemspec
CHANGED
@@ -17,7 +17,7 @@ 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.2"
|
21
21
|
gem.add_dependency "schema_plus_core"
|
22
22
|
gem.add_dependency "its-it", "~> 1.2"
|
23
23
|
|
@@ -24,7 +24,7 @@ describe "Index definition" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
after(:each) do
|
27
|
-
migration.remove_index :users, :name => 'users_login_index' if migration.index_name_exists? :users, 'users_login_index',
|
27
|
+
migration.remove_index :users, :name => 'users_login_index' if migration.index_name_exists? :users, 'users_login_index', nil
|
28
28
|
end
|
29
29
|
|
30
30
|
context "when index is multicolumn" do
|
data/spec/migration_spec.rb
CHANGED
@@ -62,7 +62,12 @@ describe ActiveRecord::Migration do
|
|
62
62
|
t.string :bar, :index => { :with => :foo, :length => { :foo => 8, :bar => 12 }}
|
63
63
|
end
|
64
64
|
index = @model.indexes.first
|
65
|
-
|
65
|
+
|
66
|
+
if index.lengths.is_a? Hash # as of AR 5.1
|
67
|
+
expect(index.lengths).to eq({ "foo" => 8, "bar" => 12})
|
68
|
+
else
|
69
|
+
expect(Hash[index.columns.zip(index.lengths.map(&:to_i))]).to eq({ "foo" => 8, "bar" => 12})
|
70
|
+
end
|
66
71
|
end
|
67
72
|
|
68
73
|
it "should create an index if specified explicitly" do
|
data/spec/schema_dumper_spec.rb
CHANGED
@@ -67,7 +67,8 @@ describe "Schema dump" do
|
|
67
67
|
|
68
68
|
it "should include index order", :mysql => :skip do
|
69
69
|
with_index Post, [:user_id, :first_comment_id, :short_id], :order => { :user_id => :asc, :first_comment_id => :desc } do
|
70
|
-
|
70
|
+
# allow :order hash to key on strings (AR 5.0) or symbols (AR 5.1)
|
71
|
+
expect(dump_posts).to match(/"user_id".*:index=>{.*:with=>\["first_comment_id", "short_id"\],.*:order=>{[:"]user_id"?=>:asc, [:"]first_comment_id"?=>:desc, [:"]short_id"?=>:asc}/)
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
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.
|
4
|
+
version: 0.3.0
|
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: 2017-07-24 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.2'
|
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.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: schema_plus_core
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +164,10 @@ files:
|
|
164
164
|
- gemfiles/activerecord-5.0/Gemfile.mysql2
|
165
165
|
- gemfiles/activerecord-5.0/Gemfile.postgresql
|
166
166
|
- gemfiles/activerecord-5.0/Gemfile.sqlite3
|
167
|
+
- gemfiles/activerecord-5.1/Gemfile.base
|
168
|
+
- gemfiles/activerecord-5.1/Gemfile.mysql2
|
169
|
+
- gemfiles/activerecord-5.1/Gemfile.postgresql
|
170
|
+
- gemfiles/activerecord-5.1/Gemfile.sqlite3
|
167
171
|
- lib/schema_plus/indexes.rb
|
168
172
|
- lib/schema_plus/indexes/active_record/base.rb
|
169
173
|
- lib/schema_plus/indexes/active_record/connection_adapters/abstract_adapter.rb
|