ghost_adapter 0.2.3 → 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
  SHA256:
3
- metadata.gz: 2a5f29780a337090d7ba06e77f8e1ce6c6976f5869ec0065e8ab0dfb0f1cc04a
4
- data.tar.gz: 2e7bcdb40edcd0cd958c7be99fcc5c31e4a121a8c5c05c70549e6cee3ac63389
3
+ metadata.gz: b3ea686449861456ca4af2d1131a05a2a3b93d902204735d7e4d9b08db5558ce
4
+ data.tar.gz: dd72fcde19d24978fbdc164de6b8484b1ed5af236cb518276328134e116468df
5
5
  SHA512:
6
- metadata.gz: 9dedd0ba573c4abed8d55744cb7f87c6154969d7daa7cc283077c6077d6b690a1ade38e30a8e208fc4584f8b9622d9cf866fbef67bfb1ac8f3f8c3872e8e27f0
7
- data.tar.gz: 0b352f02462f55a3cb362a87526b0cca3b47985eb7659e85ce60d40ba2d93766d3be589afe90f17091ee3e82818c76528738b4223c0c25598e48bae6e5791f09
6
+ metadata.gz: 2e7ee85dcaa85e110c74f375b2ac84722cd14e873e78e4e36ea76308dac4382999e7bbbc0a625840e3aa5859e4b1a88a1536f7842429059469570192b96bfbd5
7
+ data.tar.gz: 465882ed84263542c08736980d20fe01e8442019c85171cc587ae8283bc74b7c56c6750d8d3485dabc4bcc8c6b616b7a6e5b551ca09eb0a0cef77d8e474a273b
@@ -5,25 +5,44 @@ on:
5
5
  branches: [main]
6
6
  pull_request:
7
7
  branches: [main]
8
+ schedule:
9
+ - cron: '45 */6 * * *'
8
10
 
9
11
  jobs:
10
12
  test:
11
13
  runs-on: ubuntu-latest
12
14
  strategy:
13
15
  matrix:
14
- ruby-version: ["2.5", "2.6", "2.7", "3.0"]
15
-
16
+ ruby-version:
17
+ - "2.5"
18
+ - "2.6"
19
+ - "2.7"
20
+ - "3.0"
21
+ gemfile:
22
+ - "gemfiles/activerecord-5.0.Gemfile"
23
+ - "gemfiles/activerecord-5.1.Gemfile"
24
+ - "gemfiles/activerecord-5.2.Gemfile"
25
+ - "gemfiles/activerecord-6.0.Gemfile"
26
+ - "gemfiles/activerecord-6.1.Gemfile"
27
+ exclude:
28
+ # Ruby 3 is not supported for ActiveRecord < 6.1
29
+ - ruby-version: "3.0"
30
+ gemfile: "gemfiles/activerecord-5.0.Gemfile"
31
+ - ruby-version: "3.0"
32
+ gemfile: "gemfiles/activerecord-5.1.Gemfile"
33
+ - ruby-version: "3.0"
34
+ gemfile: "gemfiles/activerecord-5.2.Gemfile"
35
+ - ruby-version: "3.0"
36
+ gemfile: "gemfiles/activerecord-6.0.Gemfile"
16
37
  steps:
17
38
  - uses: actions/checkout@v2
18
39
  - name: Set up Ruby
19
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
20
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
21
- # uses: ruby/setup-ruby@v1
22
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
40
+ uses: ruby/setup-ruby@v1
23
41
  with:
24
42
  ruby-version: ${{ matrix.ruby-version }}
25
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
43
+ - name: Install gems
44
+ run: bundle install --gemfile ${{ matrix.gemfile }}
26
45
  - name: Run rubocop
27
46
  run: bundle exec rake rubocop
28
47
  - name: Run tests
29
- run: bundle exec rake spec
48
+ run: bundle exec --gemfile ${{ matrix.gemfile }} rspec
data/.gitignore CHANGED
@@ -8,3 +8,9 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .byebug_history
11
+
12
+ # for a library or gem, you might want to ignore these files since the code is
13
+ # intended to run in multiple environments; otherwise, check them in:
14
+ **/*Gemfile.lock
15
+ .ruby-version
16
+ .ruby-gemset
data/.rubocop.yml CHANGED
@@ -7,16 +7,36 @@ Style/Documentation:
7
7
  Style/RescueModifier:
8
8
  Enabled: false
9
9
 
10
+ Layout/LineLength:
11
+ Exclude:
12
+ - spec/**/*_spec.rb
13
+
10
14
  Metrics/BlockLength:
11
15
  Exclude:
12
16
  - spec/**/*_spec.rb
13
17
 
18
+ Metrics/ClassLength:
19
+ CountAsOne:
20
+ - 'array'
21
+ - 'hash'
22
+ - 'heredoc'
23
+ Max: 150
24
+
14
25
  Metrics/MethodLength:
26
+ Max: 15
27
+ CountAsOne:
28
+ - 'array'
29
+ - 'hash'
30
+ - 'heredoc'
15
31
  IgnoredMethods:
16
32
  - build_ghost_command
17
33
  - mysql2_ghost_connection
18
34
 
19
35
  Metrics/ModuleLength:
36
+ CountAsOne:
37
+ - 'array'
38
+ - 'hash'
39
+ - 'heredoc'
20
40
  Exclude:
21
41
  - lib/ghost_adapter/config.rb
22
42
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.3.0
4
+ - Fix compatibility for ActiveRecord 6.1 ([#61](https://github.com/WeTransfer/ghost_adapter/pull/61))
5
+
6
+ ## 0.2.3
7
+ - Add comma to allowed characters when cleaning SQL queries ([#52](https://github.com/WeTransfer/ghost_adapter/pull/52))
8
+
3
9
  ## 0.2.2
4
10
 
5
11
  - Bump rexml from 3.2.4 to 3.2.5 (security fix) ([#35](https://github.com/WeTransfer/ghost_adapter/pull/35))
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 5.0.0'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 5.1.0'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 5.2.0'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 6.0.0'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 6.1.0'
4
+
5
+ gemspec path: '../'
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
18
18
  # Specify which files should be added to the gem when it is released.
19
19
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
20
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|doc)/}) }
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|doc|bin)/}) }
22
22
  end
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'activerecord', '>= 5'
25
+ spec.add_dependency 'activerecord', '>= 5', '< 6.2'
26
26
  spec.add_dependency 'mysql2', '>= 0.4.0', '< 0.6.0'
27
27
 
28
28
  spec.add_development_dependency 'bump', '~> 0'
@@ -55,14 +55,47 @@ module ActiveRecord
55
55
  end
56
56
  end
57
57
 
58
- def add_index(table_name, column_name, options = {})
59
- index_name, index_type, index_columns, index_options = add_index_options(table_name, column_name, options)
60
- execute "ALTER TABLE #{quote_table_name(table_name)} ADD #{index_type} INDEX #{quote_column_name(index_name)} (#{index_columns})#{index_options}" # rubocop:disable Layout/LineLength
61
- end
58
+ if Gem.loaded_specs['activerecord'].version >= Gem::Version.new('6.1')
59
+ def add_index(table_name, column_name, **options)
60
+ index, algorithm, if_not_exists = add_index_options(table_name, column_name, **options)
61
+ return if if_not_exists && index_exists?(table_name, column_name, name: index.name)
62
+
63
+ index_type = index.type&.to_s&.upcase || (index.unique ? 'UNIQUE' : nil)
64
+
65
+ sql = build_add_index_sql(
66
+ table_name, quoted_columns(index), index.name,
67
+ index_type: index_type,
68
+ using: index.using,
69
+ algorithm: algorithm
70
+ )
71
+
72
+ execute sql
73
+ end
74
+
75
+ def remove_index(table_name, column_name = nil, **options)
76
+ return if options[:if_exists] && !index_exists?(table_name, column_name, **options)
77
+
78
+ index_name = index_name_for_remove(table_name, column_name, options)
79
+ execute "ALTER TABLE #{quote_table_name(table_name)} DROP INDEX #{quote_column_name(index_name)}"
80
+ end
81
+ else
82
+ def add_index(table_name, column_name, options = {})
83
+ index_name, index_type, index_columns, _index_options = add_index_options(table_name, column_name, options)
62
84
 
63
- def remove_index(table_name, options = {})
64
- index_name = index_name_for_remove(table_name, options)
65
- execute "ALTER TABLE #{quote_table_name(table_name)} DROP INDEX #{quote_column_name(index_name)}"
85
+ sql = build_add_index_sql(
86
+ table_name, index_columns, index_name,
87
+ index_type: index_type&.upcase,
88
+ using: options[:using]
89
+ )
90
+
91
+ execute sql
92
+ end
93
+
94
+ def remove_index(table_name, options = {})
95
+ options = { column: options } unless options.is_a?(Hash)
96
+ index_name = index_name_for_remove(table_name, options)
97
+ execute "ALTER TABLE #{quote_table_name(table_name)} DROP INDEX #{quote_column_name(index_name)}"
98
+ end
66
99
  end
67
100
 
68
101
  private
@@ -111,6 +144,25 @@ module ActiveRecord
111
144
  INSERT_SCHEMA_MIGRATION_PATTERN =~ sql ||
112
145
  DROP_SCHEMA_MIGRATION_PATTERN =~ sql
113
146
  end
147
+
148
+ def build_add_index_sql(table_name, column_names, index_name, # rubocop:disable Metrics/ParameterLists
149
+ index_type: nil, using: nil, algorithm: nil)
150
+ sql = %w[ALTER TABLE]
151
+ sql << quote_table_name(table_name)
152
+ sql << 'ADD'
153
+ sql << index_type
154
+ sql << 'INDEX'
155
+ sql << quote_column_name(index_name)
156
+ sql << "USING #{using}" if using
157
+ sql << "(#{column_names})"
158
+ sql << algorithm
159
+
160
+ sql.compact.join(' ').gsub(/\s+/, ' ')
161
+ end
162
+
163
+ def quoted_columns(index)
164
+ index.columns.is_a?(String) ? index.columns : quoted_columns_for_index(index.columns, index.column_options)
165
+ end
114
166
  end
115
167
  end
116
168
  end
@@ -1,3 +1,3 @@
1
1
  module GhostAdapter
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghost_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin C Roos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-15 00:00:00.000000000 Z
11
+ date: 2021-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '5'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: mysql2
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -147,11 +153,14 @@ files:
147
153
  - CODE_OF_CONDUCT.md
148
154
  - CONTRIBUTORS.md
149
155
  - Gemfile
150
- - Gemfile.lock
151
156
  - LICENSE.md
152
157
  - README.md
153
158
  - Rakefile
154
- - bin/console
159
+ - gemfiles/activerecord-5.0.Gemfile
160
+ - gemfiles/activerecord-5.1.Gemfile
161
+ - gemfiles/activerecord-5.2.Gemfile
162
+ - gemfiles/activerecord-6.0.Gemfile
163
+ - gemfiles/activerecord-6.1.Gemfile
155
164
  - ghost_adapter.gemspec
156
165
  - lib/active_record/connection_adapters/mysql2_ghost_adapter.rb
157
166
  - lib/generators/ghost_adapter/install_generator.rb
@@ -186,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
195
  - !ruby/object:Gem::Version
187
196
  version: '0'
188
197
  requirements: []
189
- rubygems_version: 3.1.6
198
+ rubygems_version: 3.1.2
190
199
  signing_key:
191
200
  specification_version: 4
192
201
  summary: Run ActiveRecord migrations through gh-ost
data/Gemfile.lock DELETED
@@ -1,82 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ghost_adapter (0.2.3)
5
- activerecord (>= 5)
6
- mysql2 (>= 0.4.0, < 0.6.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (6.1.4.1)
12
- activesupport (= 6.1.4.1)
13
- activerecord (6.1.4.1)
14
- activemodel (= 6.1.4.1)
15
- activesupport (= 6.1.4.1)
16
- activesupport (6.1.4.1)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 1.6, < 2)
19
- minitest (>= 5.1)
20
- tzinfo (~> 2.0)
21
- zeitwerk (~> 2.3)
22
- ast (2.4.2)
23
- bump (0.10.0)
24
- byebug (11.1.3)
25
- concurrent-ruby (1.1.9)
26
- diff-lcs (1.4.4)
27
- i18n (1.8.10)
28
- concurrent-ruby (~> 1.0)
29
- minitest (5.14.4)
30
- mysql2 (0.5.3)
31
- parallel (1.21.0)
32
- parser (3.0.2.0)
33
- ast (~> 2.4.1)
34
- rainbow (3.0.0)
35
- rake (13.0.6)
36
- regexp_parser (2.1.1)
37
- rexml (3.2.5)
38
- rspec (3.10.0)
39
- rspec-core (~> 3.10.0)
40
- rspec-expectations (~> 3.10.0)
41
- rspec-mocks (~> 3.10.0)
42
- rspec-core (3.10.1)
43
- rspec-support (~> 3.10.0)
44
- rspec-expectations (3.10.1)
45
- diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.10.0)
47
- rspec-mocks (3.10.2)
48
- diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.10.0)
50
- rspec-support (3.10.2)
51
- rubocop (1.21.0)
52
- parallel (~> 1.10)
53
- parser (>= 3.0.0.0)
54
- rainbow (>= 2.2.2, < 4.0)
55
- regexp_parser (>= 1.8, < 3.0)
56
- rexml
57
- rubocop-ast (>= 1.9.1, < 2.0)
58
- ruby-progressbar (~> 1.7)
59
- unicode-display_width (>= 1.4.0, < 3.0)
60
- rubocop-ast (1.11.0)
61
- parser (>= 3.0.1.1)
62
- ruby-progressbar (1.11.0)
63
- tzinfo (2.0.4)
64
- concurrent-ruby (~> 1.0)
65
- unicode-display_width (2.0.0)
66
- zeitwerk (2.4.2)
67
-
68
- PLATFORMS
69
- ruby
70
- x86_64-darwin-19
71
-
72
- DEPENDENCIES
73
- bump (~> 0)
74
- bundler (~> 2)
75
- byebug (~> 11.1)
76
- ghost_adapter!
77
- rake (~> 13.0)
78
- rspec (~> 3)
79
- rubocop (~> 1)
80
-
81
- BUNDLED WITH
82
- 2.2.7
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'ghost_adapter'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start(__FILE__)