schema_plus_indexes 0.2.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/prs.yml +134 -0
  3. data/.gitignore +1 -0
  4. data/.simplecov +20 -0
  5. data/Gemfile +4 -1
  6. data/README.md +24 -8
  7. data/Rakefile +2 -0
  8. data/gemfiles/Gemfile.base +1 -1
  9. data/gemfiles/activerecord-5.2/Gemfile.base +4 -0
  10. data/gemfiles/activerecord-5.2/Gemfile.mysql2 +10 -0
  11. data/gemfiles/activerecord-5.2/Gemfile.postgresql +10 -0
  12. data/gemfiles/{activerecord-4.2 → activerecord-5.2}/Gemfile.sqlite3 +3 -3
  13. data/gemfiles/activerecord-6.0/Gemfile.base +4 -0
  14. data/gemfiles/activerecord-6.0/Gemfile.mysql2 +10 -0
  15. data/gemfiles/activerecord-6.0/Gemfile.postgresql +10 -0
  16. data/gemfiles/{activerecord-5.0 → activerecord-6.0}/Gemfile.sqlite3 +3 -3
  17. data/lib/schema_plus/indexes/active_record/base.rb +4 -2
  18. data/lib/schema_plus/indexes/active_record/connection_adapters/abstract_adapter.rb +2 -0
  19. data/lib/schema_plus/indexes/active_record/connection_adapters/index_definition.rb +12 -10
  20. data/lib/schema_plus/indexes/active_record/connection_adapters/postgresql_adapter.rb +2 -0
  21. data/lib/schema_plus/indexes/active_record/connection_adapters/sqlite3_adapter.rb +2 -0
  22. data/lib/schema_plus/indexes/active_record/migration/command_recorder.rb +2 -0
  23. data/lib/schema_plus/indexes/middleware/dumper.rb +4 -2
  24. data/lib/schema_plus/indexes/middleware/migration.rb +7 -1
  25. data/lib/schema_plus/indexes/middleware/model.rb +2 -0
  26. data/lib/schema_plus/indexes/middleware/schema.rb +2 -0
  27. data/lib/schema_plus/indexes/remove_if_exists.rb +3 -1
  28. data/lib/schema_plus/indexes/version.rb +3 -1
  29. data/lib/schema_plus/indexes.rb +3 -1
  30. data/lib/schema_plus_indexes.rb +2 -0
  31. data/schema_dev.yml +5 -3
  32. data/schema_plus_indexes.gemspec +10 -10
  33. data/spec/command_recorder_spec.rb +2 -0
  34. data/spec/index_definition_spec.rb +3 -1
  35. data/spec/index_spec.rb +9 -2
  36. data/spec/migration_spec.rb +14 -10
  37. data/spec/named_schema_spec.rb +2 -0
  38. data/spec/schema_dumper_spec.rb +4 -1
  39. data/spec/spec_helper.rb +4 -2
  40. data/spec/support/enableable.rb +3 -1
  41. data/spec/support/matchers/have_index.rb +2 -0
  42. metadata +34 -76
  43. data/.travis.yml +0 -21
  44. data/gemfiles/activerecord-4.2/Gemfile.base +0 -3
  45. data/gemfiles/activerecord-4.2/Gemfile.mysql2 +0 -10
  46. data/gemfiles/activerecord-4.2/Gemfile.postgresql +0 -10
  47. data/gemfiles/activerecord-5.0/Gemfile.base +0 -3
  48. data/gemfiles/activerecord-5.0/Gemfile.mysql2 +0 -10
  49. data/gemfiles/activerecord-5.0/Gemfile.postgresql +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2d3bfc7477305f922af889109040fc663c5f02a2
4
- data.tar.gz: aa44cff033d8bc35026cc0ac78b821dc0f5cef3b
2
+ SHA256:
3
+ metadata.gz: decc66bcf6d7441ebc8722b1f6391d13240d897df6f940fc0543f6450cee507b
4
+ data.tar.gz: 429fb39c11a09a551d65fb8f8fd88b9baee2e4508c422cbfbaeddc0b630f3c56
5
5
  SHA512:
6
- metadata.gz: 1211fb491159c60fab14c1829170326944e60aa67af3fae43ccb80e17761be54c203e25b33aac2d21c6305dd32ffa5ebc09a11cfd8a1a7d46be6a3b89386cb22
7
- data.tar.gz: 5a7b893f6e89058df0b8a2f23af5012a6fc0f126775b1c2aabfc1380d5516bb2919bb81be686303a3a2883176075c78c5d29f325486cbf367ce5c818528cfcb9
6
+ metadata.gz: 1579a9a36aaee5fc3445f5c239bf6a245ae88bd4628b96af588ec0c83cec1e2e7dca6b8bc895ca574038ab9d895cc62b193b1fcbfc3208d98d706c0ffb3b23f9
7
+ data.tar.gz: e896e9910e9773aba80263462ad1c03c9b9517c376797ac6afa17f37d66a0e1a34c2b976eb9a81284b6e2a640cb9259e479bc848baed9b4c171998c3bc584a8b
@@ -0,0 +1,134 @@
1
+ # This file was auto-generated by the schema_dev tool, based on the data in
2
+ # ./schema_dev.yml
3
+ # Please do not edit this file; any changes will be overwritten next time
4
+ # schema_dev gets run.
5
+ ---
6
+ name: CI PR Builds
7
+ 'on':
8
+ push:
9
+ branches:
10
+ - master
11
+ pull_request:
12
+ concurrency:
13
+ group: ci-${{ github.ref }}
14
+ cancel-in-progress: true
15
+ jobs:
16
+ test:
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ ruby:
22
+ - '2.5'
23
+ - '2.7'
24
+ - '3.0'
25
+ activerecord:
26
+ - '5.2'
27
+ - '6.0'
28
+ db:
29
+ - mysql2
30
+ - sqlite3
31
+ - skip
32
+ dbversion:
33
+ - skip
34
+ exclude:
35
+ - ruby: '3.0'
36
+ activerecord: '5.2'
37
+ - db: skip
38
+ dbversion: skip
39
+ include:
40
+ - ruby: '2.5'
41
+ activerecord: '5.2'
42
+ db: postgresql
43
+ dbversion: '9.6'
44
+ - ruby: '2.5'
45
+ activerecord: '6.0'
46
+ db: postgresql
47
+ dbversion: '9.6'
48
+ - ruby: '2.7'
49
+ activerecord: '5.2'
50
+ db: postgresql
51
+ dbversion: '9.6'
52
+ - ruby: '2.7'
53
+ activerecord: '6.0'
54
+ db: postgresql
55
+ dbversion: '9.6'
56
+ - ruby: '3.0'
57
+ activerecord: '6.0'
58
+ db: postgresql
59
+ dbversion: '9.6'
60
+ env:
61
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
62
+ MYSQL_DB_HOST: 127.0.0.1
63
+ MYSQL_DB_USER: root
64
+ MYSQL_DB_PASS: database
65
+ POSTGRESQL_DB_HOST: 127.0.0.1
66
+ POSTGRESQL_DB_USER: schema_plus_test
67
+ POSTGRESQL_DB_PASS: database
68
+ steps:
69
+ - uses: actions/checkout@v2
70
+ - name: Set up Ruby
71
+ uses: ruby/setup-ruby@v1
72
+ with:
73
+ ruby-version: "${{ matrix.ruby }}"
74
+ bundler-cache: true
75
+ - name: Run bundle update
76
+ run: bundle update
77
+ - name: Start Mysql
78
+ if: matrix.db == 'mysql2'
79
+ run: |
80
+ docker run --rm --detach \
81
+ -e MYSQL_ROOT_PASSWORD=$MYSQL_DB_PASS \
82
+ -p 3306:3306 \
83
+ --health-cmd "mysqladmin ping --host=127.0.0.1 --password=$MYSQL_DB_PASS --silent" \
84
+ --health-interval 5s \
85
+ --health-timeout 5s \
86
+ --health-retries 5 \
87
+ --name database mysql:5.6
88
+ - name: Start Postgresql
89
+ if: matrix.db == 'postgresql'
90
+ run: |
91
+ docker run --rm --detach \
92
+ -e POSTGRES_USER=$POSTGRESQL_DB_USER \
93
+ -e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \
94
+ -p 5432:5432 \
95
+ --health-cmd "pg_isready -q" \
96
+ --health-interval 5s \
97
+ --health-timeout 5s \
98
+ --health-retries 5 \
99
+ --name database postgres:${{ matrix.dbversion }}
100
+ - name: Wait for database to start
101
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
102
+ run: |
103
+ COUNT=0
104
+ ATTEMPTS=20
105
+ until [[ $COUNT -eq $ATTEMPTS ]]; do
106
+ [ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
107
+ echo $(( COUNT++ )) > /dev/null
108
+ sleep 2
109
+ done
110
+ - name: Create testing database
111
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
112
+ run: bundle exec rake create_ci_database
113
+ - name: Run tests
114
+ run: bundle exec rake spec
115
+ - name: Shutdown database
116
+ if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
117
+ run: docker stop database
118
+ - name: Coveralls Parallel
119
+ if: "${{ !env.ACT }}"
120
+ uses: coverallsapp/github-action@master
121
+ with:
122
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
123
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
124
+ parallel: true
125
+ finish:
126
+ needs: test
127
+ runs-on: ubuntu-latest
128
+ steps:
129
+ - name: Coveralls Finished
130
+ if: "${{ !env.ACT }}"
131
+ uses: coverallsapp/github-action@master
132
+ with:
133
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
134
+ parallel-finished: true
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  /tmp
3
3
  /pkg
4
4
  /Gemfile.local
5
+ /.idea
5
6
 
6
7
  *.lock
7
8
  *.log
data/.simplecov ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.configure do
4
+ enable_coverage :branch
5
+ add_filter '/spec/'
6
+
7
+ add_group 'Binaries', '/bin/'
8
+ add_group 'Libraries', '/lib/'
9
+
10
+ if ENV['CI']
11
+ require 'simplecov-lcov'
12
+
13
+ SimpleCov::Formatter::LcovFormatter.config do |c|
14
+ c.report_with_single_file = true
15
+ c.single_report_path = 'coverage/lcov.info'
16
+ end
17
+
18
+ formatter SimpleCov::Formatter::LcovFormatter
19
+ end
20
+ end
data/Gemfile CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "http://rubygems.org"
2
4
 
3
5
  gemspec
4
6
 
5
- File.exist?(gemfile_local = File.expand_path('../Gemfile.local', __FILE__)) and eval File.read(gemfile_local), binding, gemfile_local
7
+ gemfile_local = File.expand_path '../Gemfile.local', __FILE__
8
+ eval File.read(gemfile_local), binding, gemfile_local if File.exist? gemfile_local
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/schema_plus_indexes.svg)](http://badge.fury.io/rb/schema_plus_indexes)
2
- [![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_plus_indexes.svg)](http://travis-ci.org/SchemaPlus/schema_plus_indexes)
3
- [![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_plus_indexes.svg)](https://coveralls.io/r/SchemaPlus/schema_plus_indexes)
2
+ [![Build Status](https://github.com/SchemaPlus/schema_plus_indexes/actions/workflows/prs.yml/badge.svg)](https://github.com/SchemaPlus/schema_plus_indexes/actions)
3
+ [![Coverage Status](https://coveralls.io/repos/github/SchemaPlus/schema_plus_indexes/badge.svg)](https://coveralls.io/github/SchemaPlus/schema_plus_indexes)
4
4
 
5
5
  # SchemaPlus::Indexes
6
6
 
@@ -105,16 +105,33 @@ schema_plus_indexes is tested on
105
105
 
106
106
  <!-- SCHEMA_DEV: MATRIX - begin -->
107
107
  <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
108
- * ruby **2.3.1** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql**
109
- * ruby **2.3.1** with activerecord **5.0**, using **mysql2**, **sqlite3** or **postgresql**
108
+ * ruby **2.5** with activerecord **5.2**, using **mysql2**, **sqlite3** or **postgresql:9.6**
109
+ * ruby **2.5** with activerecord **6.0**, using **mysql2**, **sqlite3** or **postgresql:9.6**
110
+ * ruby **2.7** with activerecord **5.2**, using **mysql2**, **sqlite3** or **postgresql:9.6**
111
+ * ruby **2.7** with activerecord **6.0**, using **mysql2**, **sqlite3** or **postgresql:9.6**
112
+ * ruby **3.0** with activerecord **6.0**, using **mysql2**, **sqlite3** or **postgresql:9.6**
110
113
 
111
114
  <!-- SCHEMA_DEV: MATRIX - end -->
112
115
 
113
- ## History
116
+ ## Release Notes
117
+
118
+ ### v1.0.0
119
+
120
+ * Drop AR < 5.2 and add 6.0 support
121
+ * Drop Ruby < 2.5 and add Ruby 3.0 support
122
+ * Remove its-it GEM
123
+
124
+ ### v0.3.1
125
+
126
+ * Support AR 5.2. Thanks to [@jeremyyap](https://github.com/jeremyyap)
127
+
128
+ ### v0.3.0
129
+
130
+ * Supports AR 5.1. Thanks to [@iagopiimenta](https://github.com/iagopiimenta)
114
131
 
115
132
  ### v0.2.4
116
133
 
117
- * Supports AR 5.0. Thanks to [@myabc][https://github.com/myabc]
134
+ * Supports AR 5.0. Thanks to [@myabc](https://github.com/myabc)
118
135
 
119
136
 
120
137
  ### v0.2.3
@@ -149,7 +166,7 @@ Some things to know about to help you develop and test:
149
166
  * **schema_dev**: SchemaPlus::Indexes uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
150
167
  facilitate running rspec tests on the matrix of ruby, activerecord, and database
151
168
  versions that the gem supports, both locally and on
152
- [travis-ci](http://travis-ci.org/SchemaPlus/schema_plus_indexes)
169
+ [github actions](https://github.com/SchemaPlus/schema_plus_indexes/actions)
153
170
 
154
171
  To to run rspec locally on the full matrix, do:
155
172
 
@@ -161,7 +178,6 @@ Some things to know about to help you develop and test:
161
178
  The matrix of configurations is specified in `schema_dev.yml` in
162
179
  the project root.
163
180
 
164
-
165
181
  <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
166
182
  <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - begin -->
167
183
  <!-- These lines are auto-inserted from a schema_dev template -->
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- gemspec :path => File.expand_path('..', __FILE__)
2
+ gemspec path: File.expand_path('..', __FILE__)
3
3
 
4
4
  File.exist?(gemfile_local = File.expand_path('../Gemfile.local', __FILE__)) and eval File.read(gemfile_local), binding, gemfile_local
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 5.2.0.beta0", "< 5.3"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
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
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -1,5 +1,5 @@
1
- require "pathname"
2
- eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
3
 
4
4
  platform :ruby do
5
5
  gem "sqlite3"
@@ -7,4 +7,4 @@ end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
- end
10
+ end
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 6.0", "< 6.1"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
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
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -1,5 +1,5 @@
1
- require "pathname"
2
- eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
3
 
4
4
  platform :ruby do
5
5
  gem "sqlite3"
@@ -7,4 +7,4 @@ end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
- end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module ActiveRecord
3
5
  module Base
@@ -6,10 +8,10 @@ module SchemaPlus::Indexes
6
8
  public
7
9
 
8
10
  # Returns a list of IndexDefinition objects, for each index
9
- # defind on this model's table.
11
+ # defined on this model's table.
10
12
  #
11
13
  def indexes
12
- @indexes ||= connection.indexes(table_name, "#{name} Indexes")
14
+ @indexes ||= connection.indexes(table_name)
13
15
  end
14
16
 
15
17
  # (reset_index_information gets called by by Middleware::Model::ResetColumnInformation)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module ActiveRecord
3
5
  module ConnectionAdapters
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module ActiveRecord
3
5
  module ConnectionAdapters
4
6
 
5
7
  module IndexDefinition
8
+ attr_accessor :orders
9
+
10
+ def initialize(*args, **kwargs) #:nodoc:
11
+ super
6
12
 
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
14
- end
15
13
  unless orders.blank?
16
14
  # fill out orders with :asc when undefined. make sure hash ordering
17
15
  # follows column ordering.
18
- self.orders = Hash[columns.map{|column| [column, orders[column] || :asc]}]
16
+ if self.orders.is_a?(Hash)
17
+ self.orders = Hash[columns.map{|column| [column, orders[column] || :asc]}]
18
+ else
19
+ self.orders = Hash[columns.map{|column| [column, orders || :asc]}]
20
+ end
19
21
  end
20
22
  end
21
23
 
@@ -25,7 +27,7 @@ module SchemaPlus::Indexes
25
27
  return false unless self.name == other.name
26
28
  return false unless Array.wrap(self.columns).collect(&:to_s).sort == Array.wrap(other.columns).collect(&:to_s).sort
27
29
  return false unless !!self.unique == !!other.unique
28
- return false unless Array.wrap(self.lengths).compact.sort == Array.wrap(other.lengths).compact.sort
30
+ return false if (self.lengths || {}) != (other.lengths || {}) # treat nil same as empty hash
29
31
  return false unless self.where == other.where
30
32
  return false unless (self.using||:btree) == (other.using||:btree)
31
33
  true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module ActiveRecord
3
5
  module ConnectionAdapters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module ActiveRecord
3
5
  module ConnectionAdapters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module ActiveRecord
3
5
  module Migration
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module Middleware
3
5
  module Dumper
@@ -11,12 +13,12 @@ module SchemaPlus::Indexes
11
13
  env.table.columns.each do |column|
12
14
 
13
15
  # first check for a single-column index
14
- if (index = env.table.indexes.find(&its.columns == [column.name]))
16
+ if (index = env.table.indexes.find{ |it| it.columns == [column.name] })
15
17
  column.options[:index] = index_options(env, column, index)
16
18
  env.table.indexes.delete(index)
17
19
 
18
20
  # then check for the first of a multi-column index
19
- elsif (index = env.table.indexes.find(&its.columns.first == column.name))
21
+ elsif (index = env.table.indexes.find { |it| it.columns.first == column.name })
20
22
  column.options[:index] = index_options(env, column, index)
21
23
  env.table.indexes.delete(index)
22
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module Middleware
3
5
  module Migration
@@ -44,9 +46,13 @@ module SchemaPlus::Indexes
44
46
  yield env
45
47
  rescue => e
46
48
  raise unless e.message.match(/["']([^"']+)["'].*already exists/)
49
+
47
50
  name = $1
48
51
  existing = env.caller.indexes(env.table_name).find{|i| i.name == name}
49
- attempted = ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(env.table_name, env.column_names, env.options.merge(:name => name))
52
+ attempted = ::ActiveRecord::ConnectionAdapters::IndexDefinition.new(
53
+ env.table_name, name, env.options[:unique], env.column_names,
54
+ **env.options.except(:unique)
55
+ )
50
56
  raise if attempted != existing
51
57
  ::ActiveRecord::Base.logger.warn "[schema_plus_indexes] Index name #{name.inspect}' on table #{env.table_name.inspect} already exists. Skipping."
52
58
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module Middleware
3
5
  module Model
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module Middleware
3
5
  module Schema
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::Indexes
2
4
  module RemoveIfExists
3
5
  # Extends rails' remove_index to include this options:
@@ -6,7 +8,7 @@ module SchemaPlus::Indexes
6
8
  options = args.extract_options!
7
9
  if_exists = options.delete(:if_exists)
8
10
  args << options if options.any?
9
- return if if_exists && !index_name_exists?(table_name, options[:name] || index_name(table_name, *args), false)
11
+ return if if_exists && !index_name_exists?(table_name, options[:name] || index_name(table_name, *args))
10
12
  super table_name, *args
11
13
  end
12
14
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus
2
4
  module Indexes
3
- VERSION = "0.2.4"
5
+ VERSION = "1.0.0"
4
6
  end
5
7
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'schema_plus/core'
2
- require 'its-it'
4
+ require 'active_record'
3
5
 
4
6
  require_relative 'indexes/remove_if_exists'
5
7
  require_relative 'indexes/active_record/base'
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'schema_plus/indexes'
data/schema_dev.yml CHANGED
@@ -1,8 +1,10 @@
1
1
  ruby:
2
- - 2.3.1
2
+ - 2.5
3
+ - 2.7
4
+ - 3.0
3
5
  activerecord:
4
- - 4.2
5
- - 5.0
6
+ - 5.2
7
+ - 6.0
6
8
  db:
7
9
  - mysql2
8
10
  - sqlite3
@@ -1,4 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'schema_plus/indexes/version'
@@ -17,14 +18,13 @@ Gem::Specification.new do |gem|
17
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
19
  gem.require_paths = ["lib"]
19
20
 
20
- gem.add_dependency "activerecord", ">= 4.2", "< 5.1"
21
- gem.add_dependency "schema_plus_core"
22
- gem.add_dependency "its-it", "~> 1.2"
21
+ gem.required_ruby_version = ">= 2.5.0"
22
+
23
+ gem.add_dependency "activerecord", ">= 5.2", "< 6.1"
24
+ gem.add_dependency "schema_plus_core", "~> 3.0"
23
25
 
24
- gem.add_development_dependency "bundler", "~> 1.7"
25
- gem.add_development_dependency "rake", "~> 10.0"
26
- gem.add_development_dependency "rspec", "~> 3.0.0"
27
- gem.add_development_dependency "schema_dev", "~> 3.6"
28
- gem.add_development_dependency "simplecov"
29
- gem.add_development_dependency "simplecov-gem-profile"
26
+ gem.add_development_dependency "bundler"
27
+ gem.add_development_dependency "rake", "~> 13.0"
28
+ gem.add_development_dependency "rspec", "~> 3.0"
29
+ gem.add_development_dependency "schema_dev", "~> 4.1"
30
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module AddIndexBefore
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
 
@@ -24,7 +26,7 @@ describe "Index definition" do
24
26
  end
25
27
 
26
28
  after(:each) do
27
- migration.remove_index :users, :name => 'users_login_index' if migration.index_name_exists? :users, 'users_login_index', true
29
+ migration.remove_index :users, :name => 'users_login_index' if migration.index_name_exists?(:users, 'users_login_index')
28
30
  end
29
31
 
30
32
  context "when index is multicolumn" do
data/spec/index_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe "index" do
@@ -53,6 +55,11 @@ describe "index" do
53
55
  expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :asc})
54
56
  end
55
57
 
58
+ it "should assign order (all same direction)", :mysql => :skip do
59
+ add_index(:users, [:login, :deleted_at], :order => {:login => :desc, :deleted_at => :desc})
60
+ expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :desc})
61
+ end
62
+
56
63
  context "for duplicate index" do
57
64
  it "should not complain if the index is the same" do
58
65
  add_index(:users, :login)
@@ -64,7 +71,7 @@ describe "index" do
64
71
  it "should complain if the index is different" do
65
72
  add_index(:users, :login, :unique => true)
66
73
  expect(index_for(:login)).not_to be_nil
67
- expect { add_index(:users, :login) }.to raise_error
74
+ expect { add_index(:users, :login) }.to raise_error(ArgumentError, /already exists/)
68
75
  expect(index_for(:login)).not_to be_nil
69
76
  end
70
77
  end
@@ -150,7 +157,7 @@ describe "index" do
150
157
  it "raises exception if doesn't exist" do
151
158
  expect {
152
159
  remove_index :users, :login
153
- }.to raise_error
160
+ }.to raise_error(ArgumentError)
154
161
  end
155
162
 
156
163
  it "doesn't raise exception with :if_exists" do
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  describe ActiveRecord::Migration do
@@ -62,7 +63,12 @@ describe ActiveRecord::Migration do
62
63
  t.string :bar, :index => { :with => :foo, :length => { :foo => 8, :bar => 12 }}
63
64
  end
64
65
  index = @model.indexes.first
65
- expect(Hash[index.columns.zip(index.lengths.map(&:to_i))]).to eq({ "foo" => 8, "bar" => 12})
66
+
67
+ if index.lengths.is_a? Hash # as of AR 5.1
68
+ expect(index.lengths).to eq({ "foo" => 8, "bar" => 12})
69
+ else
70
+ expect(Hash[index.columns.zip(index.lengths.map(&:to_i))]).to eq({ "foo" => 8, "bar" => 12})
71
+ end
66
72
  end
67
73
 
68
74
  it "should create an index if specified explicitly" do
@@ -157,9 +163,9 @@ describe ActiveRecord::Migration do
157
163
 
158
164
  protected
159
165
 
160
- def add_column(column_name, *args)
166
+ def add_column(column_name, type, **args)
161
167
  table = @model.table_name
162
- ActiveRecord::Migration.add_column(table, column_name, *args)
168
+ ActiveRecord::Migration.add_column(table, column_name, type, **args)
163
169
  @model.reset_column_information
164
170
  yield if block_given?
165
171
  ActiveRecord::Migration.remove_column(table, column_name)
@@ -167,16 +173,14 @@ describe ActiveRecord::Migration do
167
173
 
168
174
  end
169
175
 
170
-
171
- def recreate_table(model, opts={}, &block)
172
- ActiveRecord::Migration.create_table model.table_name, opts.merge(:force => true), &block
176
+ def recreate_table(model, **opts, &block)
177
+ ActiveRecord::Migration.create_table model.table_name, **opts.merge(:force => true), &block
173
178
  model.reset_column_information
174
179
  end
175
180
 
176
- def change_table(model, opts={}, &block)
177
- ActiveRecord::Migration.change_table model.table_name, opts, &block
181
+ def change_table(model, **opts, &block)
182
+ ActiveRecord::Migration.change_table model.table_name, **opts, &block
178
183
  model.reset_column_information
179
184
  end
180
185
 
181
186
  end
182
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe "with multiple schemas" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'stringio'
3
5
 
@@ -67,7 +69,8 @@ describe "Schema dump" do
67
69
 
68
70
  it "should include index order", :mysql => :skip do
69
71
  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}/)
72
+ # allow :order hash to key on strings (AR 5.0) or symbols (AR 5.1)
73
+ 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
74
  end
72
75
  end
73
76
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
- require 'simplecov-gem-profile'
3
- SimpleCov.start "gem"
4
+
5
+ SimpleCov.start
4
6
 
5
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Enableable
2
4
 
3
5
  def enabled_middleware(root, env)
4
- middleware = self.singleton_class.ancestors.find(&it.to_s.start_with?("#{root}::Middleware"))
6
+ middleware = self.singleton_class.ancestors.find { |it| it.to_s.start_with?("#{root}::Middleware") }
5
7
  return nil unless middleware.enabled?(env)
6
8
  middleware.disable if middleware.once?(env)
7
9
  middleware
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SchemaPlus::IndexesMatchers
2
4
 
3
5
  class HaveIndex
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: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-24 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,154 +16,113 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.1'
22
+ version: '6.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.2'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.1'
32
+ version: '6.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: schema_plus_core
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
- type: :runtime
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
- - !ruby/object:Gem::Dependency
48
- name: its-it
49
35
  requirement: !ruby/object:Gem::Requirement
50
36
  requirements:
51
37
  - - "~>"
52
38
  - !ruby/object:Gem::Version
53
- version: '1.2'
39
+ version: '3.0'
54
40
  type: :runtime
55
41
  prerelease: false
56
42
  version_requirements: !ruby/object:Gem::Requirement
57
43
  requirements:
58
44
  - - "~>"
59
45
  - !ruby/object:Gem::Version
60
- version: '1.2'
46
+ version: '3.0'
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: bundler
63
49
  requirement: !ruby/object:Gem::Requirement
64
50
  requirements:
65
- - - "~>"
51
+ - - ">="
66
52
  - !ruby/object:Gem::Version
67
- version: '1.7'
53
+ version: '0'
68
54
  type: :development
69
55
  prerelease: false
70
56
  version_requirements: !ruby/object:Gem::Requirement
71
57
  requirements:
72
- - - "~>"
58
+ - - ">="
73
59
  - !ruby/object:Gem::Version
74
- version: '1.7'
60
+ version: '0'
75
61
  - !ruby/object:Gem::Dependency
76
62
  name: rake
77
63
  requirement: !ruby/object:Gem::Requirement
78
64
  requirements:
79
65
  - - "~>"
80
66
  - !ruby/object:Gem::Version
81
- version: '10.0'
67
+ version: '13.0'
82
68
  type: :development
83
69
  prerelease: false
84
70
  version_requirements: !ruby/object:Gem::Requirement
85
71
  requirements:
86
72
  - - "~>"
87
73
  - !ruby/object:Gem::Version
88
- version: '10.0'
74
+ version: '13.0'
89
75
  - !ruby/object:Gem::Dependency
90
76
  name: rspec
91
77
  requirement: !ruby/object:Gem::Requirement
92
78
  requirements:
93
79
  - - "~>"
94
80
  - !ruby/object:Gem::Version
95
- version: 3.0.0
81
+ version: '3.0'
96
82
  type: :development
97
83
  prerelease: false
98
84
  version_requirements: !ruby/object:Gem::Requirement
99
85
  requirements:
100
86
  - - "~>"
101
87
  - !ruby/object:Gem::Version
102
- version: 3.0.0
88
+ version: '3.0'
103
89
  - !ruby/object:Gem::Dependency
104
90
  name: schema_dev
105
91
  requirement: !ruby/object:Gem::Requirement
106
92
  requirements:
107
93
  - - "~>"
108
94
  - !ruby/object:Gem::Version
109
- version: '3.6'
95
+ version: '4.1'
110
96
  type: :development
111
97
  prerelease: false
112
98
  version_requirements: !ruby/object:Gem::Requirement
113
99
  requirements:
114
100
  - - "~>"
115
101
  - !ruby/object:Gem::Version
116
- version: '3.6'
117
- - !ruby/object:Gem::Dependency
118
- name: simplecov
119
- requirement: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: '0'
124
- type: :development
125
- prerelease: false
126
- version_requirements: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: '0'
131
- - !ruby/object:Gem::Dependency
132
- name: simplecov-gem-profile
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: '0'
138
- type: :development
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: '0'
145
- description:
102
+ version: '4.1'
103
+ description:
146
104
  email:
147
105
  - ronen@barzel.org
148
106
  executables: []
149
107
  extensions: []
150
108
  extra_rdoc_files: []
151
109
  files:
110
+ - ".github/workflows/prs.yml"
152
111
  - ".gitignore"
153
- - ".travis.yml"
112
+ - ".simplecov"
154
113
  - Gemfile
155
114
  - LICENSE.txt
156
115
  - README.md
157
116
  - Rakefile
158
117
  - gemfiles/Gemfile.base
159
- - gemfiles/activerecord-4.2/Gemfile.base
160
- - gemfiles/activerecord-4.2/Gemfile.mysql2
161
- - gemfiles/activerecord-4.2/Gemfile.postgresql
162
- - gemfiles/activerecord-4.2/Gemfile.sqlite3
163
- - gemfiles/activerecord-5.0/Gemfile.base
164
- - gemfiles/activerecord-5.0/Gemfile.mysql2
165
- - gemfiles/activerecord-5.0/Gemfile.postgresql
166
- - gemfiles/activerecord-5.0/Gemfile.sqlite3
118
+ - gemfiles/activerecord-5.2/Gemfile.base
119
+ - gemfiles/activerecord-5.2/Gemfile.mysql2
120
+ - gemfiles/activerecord-5.2/Gemfile.postgresql
121
+ - gemfiles/activerecord-5.2/Gemfile.sqlite3
122
+ - gemfiles/activerecord-6.0/Gemfile.base
123
+ - gemfiles/activerecord-6.0/Gemfile.mysql2
124
+ - gemfiles/activerecord-6.0/Gemfile.postgresql
125
+ - gemfiles/activerecord-6.0/Gemfile.sqlite3
167
126
  - lib/schema_plus/indexes.rb
168
127
  - lib/schema_plus/indexes/active_record/base.rb
169
128
  - lib/schema_plus/indexes/active_record/connection_adapters/abstract_adapter.rb
@@ -193,7 +152,7 @@ homepage: https://github.com/SchemaPlus/schema_plus_indexes
193
152
  licenses:
194
153
  - MIT
195
154
  metadata: {}
196
- post_install_message:
155
+ post_install_message:
197
156
  rdoc_options: []
198
157
  require_paths:
199
158
  - lib
@@ -201,16 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
160
  requirements:
202
161
  - - ">="
203
162
  - !ruby/object:Gem::Version
204
- version: '0'
163
+ version: 2.5.0
205
164
  required_rubygems_version: !ruby/object:Gem::Requirement
206
165
  requirements:
207
166
  - - ">="
208
167
  - !ruby/object:Gem::Version
209
168
  version: '0'
210
169
  requirements: []
211
- rubyforge_project:
212
- rubygems_version: 2.5.1
213
- signing_key:
170
+ rubygems_version: 3.0.8
171
+ signing_key:
214
172
  specification_version: 4
215
173
  summary: Adds shorthands and conveniences to ActiveRecord's handling of indexes
216
174
  test_files:
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- # This file was auto-generated by the schema_dev tool, based on the data in
2
- # ./schema_dev.yml
3
- # Please do not edit this file; any changes will be overwritten next time
4
- # schema_dev gets run.
5
- ---
6
- sudo: false
7
- rvm:
8
- - 2.3.1
9
- gemfile:
10
- - gemfiles/activerecord-4.2/Gemfile.mysql2
11
- - gemfiles/activerecord-4.2/Gemfile.postgresql
12
- - gemfiles/activerecord-4.2/Gemfile.sqlite3
13
- - gemfiles/activerecord-5.0/Gemfile.mysql2
14
- - gemfiles/activerecord-5.0/Gemfile.postgresql
15
- - gemfiles/activerecord-5.0/Gemfile.sqlite3
16
- env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
17
- addons:
18
- postgresql: '9.4'
19
- before_script: bundle exec rake create_databases
20
- after_script: bundle exec rake drop_databases
21
- script: bundle exec rake travis
@@ -1,3 +0,0 @@
1
- eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
-
3
- gem "activerecord", "~> 4.2.6"
@@ -1,10 +0,0 @@
1
- require "pathname"
2
- eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
-
4
- platform :ruby do
5
- gem "mysql2", '>= 0.3.18', '< 0.5'
6
- end
7
-
8
- platform :jruby do
9
- gem 'activerecord-jdbcmysql-adapter'
10
- end
@@ -1,10 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
-
3
- gem "activerecord", "~> 5.0.0"
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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