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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d3bfc7477305f922af889109040fc663c5f02a2
4
- data.tar.gz: aa44cff033d8bc35026cc0ac78b821dc0f5cef3b
3
+ metadata.gz: 59c1cc31f6d11ef0482b7592f398503e4de3081b
4
+ data.tar.gz: cb27adde0cb695f05991c39275bb3219fc41bffa
5
5
  SHA512:
6
- metadata.gz: 1211fb491159c60fab14c1829170326944e60aa67af3fae43ccb80e17761be54c203e25b33aac2d21c6305dd32ffa5ebc09a11cfd8a1a7d46be6a3b89386cb22
7
- data.tar.gz: 5a7b893f6e89058df0b8a2f23af5012a6fc0f126775b1c2aabfc1380d5516bb2919bb81be686303a3a2883176075c78c5d29f325486cbf367ce5c818528cfcb9
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
- ## History
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][https://github.com/myabc]
122
+ * Supports AR 5.0. Thanks to [@myabc](https://github.com/myabc)
118
123
 
119
124
 
120
125
  ### v0.2.3
@@ -1,3 +1,3 @@
1
1
  eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gem "activerecord", "~> 5.0.0"
3
+ gem "activerecord", "~> 5.0.1"
@@ -0,0 +1,3 @@
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
+
3
+ gem "activerecord", "~> 5.1.0"
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -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, "#{name} Indexes")
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
- return false unless Array.wrap(self.lengths).compact.sort == Array.wrap(other.lengths).compact.sort
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), false)
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
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module Indexes
3
- VERSION = "0.2.4"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/schema_dev.yml CHANGED
@@ -3,6 +3,7 @@ ruby:
3
3
  activerecord:
4
4
  - 4.2
5
5
  - 5.0
6
+ - 5.1
6
7
  db:
7
8
  - mysql2
8
9
  - sqlite3
@@ -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.1"
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', true
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
@@ -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
- expect(Hash[index.columns.zip(index.lengths.map(&:to_i))]).to eq({ "foo" => 8, "bar" => 12})
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
@@ -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
- 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}/)
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.2.4
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: 2016-08-24 00:00:00.000000000 Z
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.1'
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.1'
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