schema_plus_indexes 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 59c1cc31f6d11ef0482b7592f398503e4de3081b
4
- data.tar.gz: cb27adde0cb695f05991c39275bb3219fc41bffa
2
+ SHA256:
3
+ metadata.gz: 01e90c31ef7cb567d005ad99b6c5532096e1d1128f2427686f7b4024ea49c156
4
+ data.tar.gz: 240e9d3ca09e91d1b0a3c04946876427310b19ec243c491a40b672de41287d0b
5
5
  SHA512:
6
- metadata.gz: d51dd7ccb1d59af210e3ab66a1e32dc138586e54547b88cfad701c001d3401ce2c1b7c9b781484286a8ddd13059112a801285aa50ab5bc9ae3a5431c27e89b93
7
- data.tar.gz: 6d7744f9e799a81d8e23bdc7793b9563070c33dc9b7f2b9d09e1d8661b8d52b0278c94f512ca891b1951cbca4c94970f2feb9b4f265724a163784262543f6998
6
+ metadata.gz: a404889345f7a83ee71d6b9f25582ae78d492b919f447834c6934bffafe535bf2ecee76da798423fc549f56e3e1399554fe71bcf821c28a2a3876ac5605ac568
7
+ data.tar.gz: 575d9ef92201129e21f1f789c88edf42f29a5dd65d26a5c296e56477a43ce12f5d738ed4d0096b199321732ec42fc71b255410cf62b501535578e12243615fb8
@@ -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.2.5
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
 
@@ -2,9 +2,9 @@ require "pathname"
2
2
  eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
3
 
4
4
  platform :ruby do
5
- gem "pg"
5
+ gem "pg", "< 1"
6
6
  end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcpostgresql-adapter'
10
- end
10
+ end
@@ -2,9 +2,9 @@ require "pathname"
2
2
  eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
3
 
4
4
  platform :ruby do
5
- gem "pg"
5
+ gem "pg", "< 1"
6
6
  end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcpostgresql-adapter'
10
- end
10
+ end
@@ -2,9 +2,9 @@ require "pathname"
2
2
  eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
3
 
4
4
  platform :ruby do
5
- gem "pg"
5
+ gem "pg", "< 1"
6
6
  end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcpostgresql-adapter'
10
- end
10
+ end
@@ -0,0 +1,3 @@
1
+ eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
+
3
+ gem "activerecord", ">= 5.2.0.beta0", "< 5.3"
@@ -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
@@ -1,5 +1,6 @@
1
1
  require 'schema_plus/core'
2
2
  require 'its-it'
3
+ require 'active_record'
3
4
 
4
5
  require_relative 'indexes/remove_if_exists'
5
6
  require_relative 'indexes/active_record/base'
@@ -6,7 +6,7 @@ module SchemaPlus::Indexes
6
6
  public
7
7
 
8
8
  # Returns a list of IndexDefinition objects, for each index
9
- # defind on this model's table.
9
+ # defined on this model's table.
10
10
  #
11
11
  def indexes
12
12
  @indexes ||= connection.indexes(table_name)
@@ -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
- def initialize(*args) #:nodoc:
8
- # same args as add_index(table_name, column_names, options)
9
- if args.length == 3 and Hash === args.last
10
- table_name, column_names, options = args + [{}]
11
- super table_name, options[:name], options[:unique], column_names, options[:length], options[:orders], options[:where], options[:type], options[:using]
12
- else # backwards compatibility
13
- super
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
- unless orders.blank?
16
- # fill out orders with :asc when undefined. make sure hash ordering
17
- # follows column ordering.
18
- self.orders = Hash[columns.map{|column| [column, orders[column] || :asc]}]
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
- def remove_index(table_name, *args)
6
- options = args.extract_options!
7
- if_exists = options.delete(:if_exists)
8
- args << options if options.any?
9
- return if if_exists && !index_name_exists?(table_name, options[:name] || index_name(table_name, *args), nil)
10
- super table_name, *args
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
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module Indexes
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ activerecord:
4
4
  - 4.2
5
5
  - 5.0
6
6
  - 5.1
7
+ - 5.2
7
8
  db:
8
9
  - mysql2
9
10
  - sqlite3
@@ -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.2"
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.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
- after(:each) do
27
- migration.remove_index :users, :name => 'users_login_index' if migration.index_name_exists? :users, 'users_login_index', nil
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
@@ -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.0
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: 2017-07-24 00:00:00.000000000 Z
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.2'
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.2'
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.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.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.5.1
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