ghost_adapter 0.2.1 → 0.4.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: 74aed2db6347e0839ee599e4cc30d41f8261533d8926aa65a3fb97bdb0518348
4
- data.tar.gz: 12e12bfd052ff336e2b2f9088e18554bdc00e7e0647f65254a33f6b32c9a6fd0
3
+ metadata.gz: 7a5270ce864f3b341d77d8185acd6ffe0f69b5c74d6334c86e9be29bce4bee02
4
+ data.tar.gz: 7647406246ef3276dc83a6f296b9c9a72e2b769ea3ad8f8b17063394540975c1
5
5
  SHA512:
6
- metadata.gz: e0de5d2b1dc0162733d976379a2eaf3f892b1c189fe799619f5c6129bfa7a9e285748ce9076c095d471f8c29d4e194335087ee2becc615781c0e9ac76412b687
7
- data.tar.gz: da399185e546d532a8b501b4a00c97dd1ade0611c438e444024cf8ad891ca77a024fab31de7c1feb1af0c9755749b95a556316cf730c50f22a98fda15f3b8bc5
6
+ metadata.gz: 16fb9da864e52fe07ecab35359ac06d1cd626acbe2640b70793aea63bbc55472cc9b7b3490b5416a5388248232eed282a60db356e900be1c75882ff5181efffe
7
+ data.tar.gz: a7b1f75edd691223e582bda09b10679b819644fdb42e673b0b61d8621250786597810d33f27edce9fa1f21257697dfcf8d5414813c537b3f562d43490c14adb8
@@ -5,25 +5,50 @@ 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
+ - "gemfiles/activerecord-7.0.Gemfile"
28
+ exclude:
29
+ # Ruby 3 is not supported for ActiveRecord < 6.1
30
+ - ruby-version: "3.0"
31
+ gemfile: "gemfiles/activerecord-5.0.Gemfile"
32
+ - ruby-version: "3.0"
33
+ gemfile: "gemfiles/activerecord-5.1.Gemfile"
34
+ - ruby-version: "3.0"
35
+ gemfile: "gemfiles/activerecord-5.2.Gemfile"
36
+ - ruby-version: "3.0"
37
+ gemfile: "gemfiles/activerecord-6.0.Gemfile"
38
+ # Ruby >= 2.7 is required for ActiveRecord >= 7
39
+ - ruby-version: "2.5"
40
+ gemfile: "gemfiles/activerecord-7.0.Gemfile"
41
+ - ruby-version: "2.6"
42
+ gemfile: "gemfiles/activerecord-7.0.Gemfile"
16
43
  steps:
17
44
  - uses: actions/checkout@v2
18
45
  - 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
46
+ uses: ruby/setup-ruby@v1
23
47
  with:
24
48
  ruby-version: ${{ matrix.ruby-version }}
25
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
49
+ - name: Install gems
50
+ run: bundle install --gemfile ${{ matrix.gemfile }}
26
51
  - name: Run rubocop
27
52
  run: bundle exec rake rubocop
28
53
  - name: Run tests
29
- run: bundle exec rake spec
54
+ 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,11 +1,26 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.0
4
+ - Add support for ActiveRecord 7 ([#67](https://github.com/WeTransfer/ghost_adapter/pull/67))
5
+
6
+ ## 0.3.0
7
+ - Fix compatibility for ActiveRecord 6.1 ([#61](https://github.com/WeTransfer/ghost_adapter/pull/61))
8
+
9
+ ## 0.2.3
10
+ - Add comma to allowed characters when cleaning SQL queries ([#52](https://github.com/WeTransfer/ghost_adapter/pull/52))
11
+
12
+ ## 0.2.2
13
+
14
+ - Bump rexml from 3.2.4 to 3.2.5 (security fix) ([#35](https://github.com/WeTransfer/ghost_adapter/pull/35))
15
+ - Add azure configuration option now available with gh-ost v1.1.1 ([#36](https://github.com/WeTransfer/ghost_adapter/pull/36))
16
+
3
17
  ## 0.2.1
18
+
4
19
  - Fix bug caused by missing `require 'ghost_adapter'` for non-rails apps ([#34](https://github.com/WeTransfer/ghost_adapter/pull/34))
5
20
 
6
21
  ## 0.2.0
7
22
 
8
- - Add templating to configuration values. See [the docs](./docs/config/templating.md) for more info on how to use this feature.
23
+ - Add templating to configuration values. See [the docs](./docs/config/templating.md) for more info on how to use this feature.
9
24
 
10
25
  ## 0.1.4
11
26
 
data/CONTRIBUTORS.md CHANGED
@@ -1 +1,2 @@
1
1
  - @acroos (Austin C. Roos, austin.roos@wetransfer.com)
2
+ - @grdw (Gerard Westerhof, gerard@wetransfer.com)
data/README.md CHANGED
@@ -5,13 +5,13 @@
5
5
  [![Gem](https://img.shields.io/gem/v/ghost_adapter)](https://rubygems.org/gems/ghost_adapter)
6
6
  ![GitHub Actions Workflow](https://github.com/WeTransfer/ghost_adapter/actions/workflows/tests.yml/badge.svg)
7
7
  [![Hippocratic License](https://img.shields.io/badge/license-Hippocratic-green)](https://github.com/WeTransfer/ghost_adapter/blob/main/LICENSE.md)
8
- [![gh-ost version](https://img.shields.io/badge/gh--ost%20version-1.1.0-blue)](https://github.com/github/gh-ost/releases/latest)
8
+ [![gh-ost version](https://img.shields.io/badge/gh--ost%20version-1.1.1-blue)](https://github.com/github/gh-ost/releases/latest)
9
9
 
10
10
  A tiny, _very configurable_ ActiveRecord adapter built for running [gh-ost](https://github.com/github/gh-ost) migrations. When not running migrations, it'll stay the heck out of the way.
11
11
 
12
12
  ## Installation
13
13
 
14
- First, you'll need to install `gh-ost`. You can find the latest release [here](https://github.com/github/gh-ost/releases/latest). You can check the allowed version range in [the version checker](./lib/ghost_adapter/version_checker.rb#L13) (current range: [>= 1.1, < 2]). Once you've got that installed, install the gem!
14
+ First, you'll need to install `gh-ost`. You can find the latest release [here](https://github.com/github/gh-ost/releases/latest). You can check the allowed version range in [the version checker](./lib/ghost_adapter/version_checker.rb#L13) (current range: [>= 1.1.0, < 2]). Once you've got that installed, install the gem!
15
15
 
16
16
  Add this line to your application's Gemfile:
17
17
 
@@ -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: '../'
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 7.0'
4
+
5
+ gemspec path: '../'
@@ -14,15 +14,16 @@ Gem::Specification.new do |spec|
14
14
 
15
15
  spec.metadata['homepage_uri'] = spec.homepage
16
16
  spec.metadata['source_code_uri'] = spec.homepage
17
+ spec.metadata['rubygems_mfa_required'] = 'true'
17
18
 
18
19
  # Specify which files should be added to the gem when it is released.
19
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
21
  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)/}) }
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|doc|bin)/}) }
22
23
  end
23
24
  spec.require_paths = ['lib']
24
25
 
25
- spec.add_dependency 'activerecord', '>= 5'
26
+ spec.add_dependency 'activerecord', '>= 5', '<= 7.0'
26
27
  spec.add_dependency 'mysql2', '>= 0.4.0', '< 0.6.0'
27
28
 
28
29
  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
@@ -70,7 +103,7 @@ module ActiveRecord
70
103
  attr_reader :database, :dry_run
71
104
 
72
105
  ALTER_TABLE_PATTERN = /\AALTER\s+TABLE\W*(?<table_name>\w+)\W*(?<query>.*)$/i.freeze
73
- QUERY_ALLOWABLE_CHARS = /[^0-9a-z_\s():'"{}]/i.freeze
106
+ QUERY_ALLOWABLE_CHARS = /[^0-9a-z_\s():'"{},]/i.freeze
74
107
  CREATE_TABLE_PATTERN = /\Acreate\stable/i.freeze
75
108
  DROP_TABLE_PATTERN = /\Acreate\stable/i.freeze
76
109
  INSERT_SCHEMA_MIGRATION_PATTERN = /\Ainsert\sinto\s`schema_migrations`/i.freeze
@@ -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
@@ -8,6 +8,7 @@ module GhostAdapter
8
8
  approve_renamed_columns
9
9
  assume_master_host
10
10
  assume_rbr
11
+ azure
11
12
  check_flag
12
13
  chunk_size
13
14
  concurrent_rowcount
@@ -1,3 +1,3 @@
1
1
  module GhostAdapter
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.4.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.1
4
+ version: 0.4.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-04-13 00:00:00.000000000 Z
11
+ date: 2021-12-17 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: '7.0'
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: '7.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: mysql2
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -147,11 +153,15 @@ 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
164
+ - gemfiles/activerecord-7.0.Gemfile
155
165
  - ghost_adapter.gemspec
156
166
  - lib/active_record/connection_adapters/mysql2_ghost_adapter.rb
157
167
  - lib/generators/ghost_adapter/install_generator.rb
@@ -171,6 +181,7 @@ licenses:
171
181
  metadata:
172
182
  homepage_uri: https://github.com/wetransfer/ghost_adapter
173
183
  source_code_uri: https://github.com/wetransfer/ghost_adapter
184
+ rubygems_mfa_required: 'true'
174
185
  post_install_message:
175
186
  rdoc_options: []
176
187
  require_paths:
@@ -186,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
197
  - !ruby/object:Gem::Version
187
198
  version: '0'
188
199
  requirements: []
189
- rubygems_version: 3.1.4
200
+ rubygems_version: 3.1.2
190
201
  signing_key:
191
202
  specification_version: 4
192
203
  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.1)
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.3.1)
12
- activesupport (= 6.1.3.1)
13
- activerecord (6.1.3.1)
14
- activemodel (= 6.1.3.1)
15
- activesupport (= 6.1.3.1)
16
- activesupport (6.1.3.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.8)
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.20.1)
32
- parser (3.0.0.0)
33
- ast (~> 2.4.1)
34
- rainbow (3.0.0)
35
- rake (13.0.3)
36
- regexp_parser (2.0.3)
37
- rexml (3.2.4)
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.8.1)
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.2.0, < 2.0)
58
- ruby-progressbar (~> 1.7)
59
- unicode-display_width (>= 1.4.0, < 3.0)
60
- rubocop-ast (1.4.1)
61
- parser (>= 2.7.1.5)
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__)