ghost_adapter 0.1.2 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +29 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +22 -0
- data/Gemfile.lock +28 -12
- data/README.md +5 -5
- data/Rakefile +3 -9
- data/ghost_adapter.gemspec +2 -1
- data/lib/active_record/connection_adapters/mysql2_ghost_adapter.rb +1 -2
- data/lib/ghost_adapter.rb +5 -0
- data/lib/ghost_adapter/command.rb +15 -1
- data/lib/ghost_adapter/config.rb +29 -16
- data/lib/ghost_adapter/env_parser.rb +4 -1
- data/lib/ghost_adapter/version.rb +1 -1
- data/lib/ghost_adapter/version_checker.rb +2 -0
- metadata +29 -9
- data/.travis.yml +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3ff416d6745fa79685e3f81fd82da3c54e94599f997eb6b069e48bb67e36cc0
|
4
|
+
data.tar.gz: 77a45f893d2f4e2ae02f4a16e54654a8b6f9c897af1f2b562565bee06263e3a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 896134509fe6a1689123c59f88b2ab7cef83b2658adb528b193e78bbaf844b6177d7bb4ccb2e86d3f2c8bfac6725b07d3878fdeb004434a0faaed680f656295a
|
7
|
+
data.tar.gz: 9a774e2e39dd80ada82532b1cd5ef5bd175d53534f013f3ca5534d999a28daf8df926d78bb504cbfe2a448db2de5c71a3c9cf2f5a0ea4a35eb44944a64202b4e
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [main]
|
6
|
+
pull_request:
|
7
|
+
branches: [main]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ["2.5", "2.6", "2.7", "3.0"]
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- 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
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby-version }}
|
25
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
26
|
+
- name: Run rubocop
|
27
|
+
run: bundle exec rake rubocop
|
28
|
+
- name: Run tests
|
29
|
+
run: bundle exec rake spec
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,26 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.2.2
|
4
|
+
|
5
|
+
- Bump rexml from 3.2.4 to 3.2.5 (security fix) ([#35](https://github.com/WeTransfer/ghost_adapter/pull/35))
|
6
|
+
- Add azure configuration option now available with gh-ost v1.1.1 ([#36](https://github.com/WeTransfer/ghost_adapter/pull/36))
|
7
|
+
|
8
|
+
## 0.2.1
|
9
|
+
|
10
|
+
- Fix bug caused by missing `require 'ghost_adapter'` for non-rails apps ([#34](https://github.com/WeTransfer/ghost_adapter/pull/34))
|
11
|
+
|
12
|
+
## 0.2.0
|
13
|
+
|
14
|
+
- Add templating to configuration values. See [the docs](./docs/config/templating.md) for more info on how to use this feature.
|
15
|
+
|
16
|
+
## 0.1.4
|
17
|
+
|
18
|
+
- Fix bug caused by missing `require 'open3'` that occurs for some ruby versions
|
19
|
+
|
20
|
+
## 0.1.3
|
21
|
+
|
22
|
+
- Fix bug [#26](https://github.com/WeTransfer/ghost_adapter/issues/26) causing environment configuration to be overwritten by some other configuration methods.
|
23
|
+
|
3
24
|
## 0.1.2
|
25
|
+
|
4
26
|
- Fix bug [#28](https://github.com/WeTransfer/ghost_adapter/issues/28) that resulted in add_index and remove_index calls to not run through `gh-ost`
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ghost_adapter (0.
|
4
|
+
ghost_adapter (0.2.2)
|
5
5
|
activerecord (>= 5)
|
6
|
+
mysql2 (>= 0.4.0, < 0.6.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
activemodel (6.1.3)
|
11
|
-
activesupport (= 6.1.3)
|
12
|
-
activerecord (6.1.3)
|
13
|
-
activemodel (= 6.1.3)
|
14
|
-
activesupport (= 6.1.3)
|
15
|
-
activesupport (6.1.3)
|
11
|
+
activemodel (6.1.3.2)
|
12
|
+
activesupport (= 6.1.3.2)
|
13
|
+
activerecord (6.1.3.2)
|
14
|
+
activemodel (= 6.1.3.2)
|
15
|
+
activesupport (= 6.1.3.2)
|
16
|
+
activesupport (6.1.3.2)
|
16
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
18
|
i18n (>= 1.6, < 2)
|
18
19
|
minitest (>= 5.1)
|
@@ -22,16 +23,31 @@ GEM
|
|
22
23
|
bump (0.10.0)
|
23
24
|
byebug (11.1.3)
|
24
25
|
concurrent-ruby (1.1.8)
|
25
|
-
|
26
|
+
diff-lcs (1.4.4)
|
27
|
+
i18n (1.8.10)
|
26
28
|
concurrent-ruby (~> 1.0)
|
27
|
-
minitest (5.14.
|
29
|
+
minitest (5.14.4)
|
30
|
+
mysql2 (0.5.3)
|
28
31
|
parallel (1.20.1)
|
29
32
|
parser (3.0.0.0)
|
30
33
|
ast (~> 2.4.1)
|
31
34
|
rainbow (3.0.0)
|
32
35
|
rake (13.0.3)
|
33
36
|
regexp_parser (2.0.3)
|
34
|
-
rexml (3.2.
|
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)
|
35
51
|
rubocop (1.8.1)
|
36
52
|
parallel (~> 1.10)
|
37
53
|
parser (>= 3.0.0.0)
|
@@ -58,9 +74,9 @@ DEPENDENCIES
|
|
58
74
|
bundler (~> 2)
|
59
75
|
byebug (~> 11.1)
|
60
76
|
ghost_adapter!
|
61
|
-
minitest (~> 5.14)
|
62
77
|
rake (~> 13.0)
|
78
|
+
rspec (~> 3)
|
63
79
|
rubocop (~> 1)
|
64
80
|
|
65
81
|
BUNDLED WITH
|
66
|
-
2.2.
|
82
|
+
2.2.7
|
data/README.md
CHANGED
@@ -3,15 +3,15 @@
|
|
3
3
|
![ghost](./doc/images/ghost.png)
|
4
4
|
|
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.
|
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
|
|
@@ -31,7 +31,7 @@ Configure your ActiveRecord connection to use `mysql2_ghost` as the adapter in w
|
|
31
31
|
|
32
32
|
For a standard rails project, in `config/database.yml` set `adapter: mysql2_ghost`.
|
33
33
|
|
34
|
-
For usage with `DATABASE_URL`, only a _very tiny_ modification is necessary. The URL should be like: `mysql2-ghost://` (notice the `-` instead of `_`). This is because the scheme of a URI must either alphanumeric or one of [`-`, `.`, `+`] ([more details](https://tools.ietf.org/html/rfc3986#section-3.1))
|
34
|
+
For usage with `DATABASE_URL`, only a _very tiny_ modification is necessary. The URL should be like: `mysql2-ghost://` (notice the `-` instead of `_`). This is because the scheme of a URI must be either alphanumeric or one of [`-`, `.`, `+`] ([more details](https://tools.ietf.org/html/rfc3986#section-3.1))
|
35
35
|
|
36
36
|
### Configuration
|
37
37
|
|
@@ -41,7 +41,7 @@ Read more about configuration methods in [the docs](./doc/configuration.md).
|
|
41
41
|
|
42
42
|
### Running Migrations
|
43
43
|
|
44
|
-
Since most database activity isn't a migration, we default to
|
44
|
+
Since most database activity isn't a migration, we default to just using the `Mysql2Adapter`. No need to be executing a bunch of extra logic per query when you're only getting any value for migrations.
|
45
45
|
|
46
46
|
To enable the ghost adapter, you have two options. First (recommended) is to use the provided rails generator:
|
47
47
|
|
data/Rakefile
CHANGED
@@ -1,14 +1,8 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
-
require '
|
3
|
-
|
4
|
-
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs << 'test'
|
6
|
-
t.libs << 'lib'
|
7
|
-
t.test_files = FileList['test/**/*_test.rb']
|
8
|
-
end
|
9
|
-
|
2
|
+
require 'rspec/core/rake_task'
|
10
3
|
require 'rubocop/rake_task'
|
11
4
|
|
12
5
|
RuboCop::RakeTask.new
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
7
|
|
14
|
-
task default: %i[
|
8
|
+
task default: %i[spec rubocop]
|
data/ghost_adapter.gemspec
CHANGED
@@ -23,11 +23,12 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
25
|
spec.add_dependency 'activerecord', '>= 5'
|
26
|
+
spec.add_dependency 'mysql2', '>= 0.4.0', '< 0.6.0'
|
26
27
|
|
27
28
|
spec.add_development_dependency 'bump', '~> 0'
|
28
29
|
spec.add_development_dependency 'bundler', '~> 2'
|
29
30
|
spec.add_development_dependency 'byebug', '~> 11.1'
|
30
|
-
spec.add_development_dependency 'minitest', '~> 5.14'
|
31
31
|
spec.add_development_dependency 'rake', '~> 13.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
32
33
|
spec.add_development_dependency 'rubocop', '~> 1'
|
33
34
|
end
|
data/lib/ghost_adapter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
1
3
|
module GhostAdapter
|
2
4
|
class Command
|
3
5
|
def initialize(alter:, table:, database: nil, dry_run: false)
|
@@ -12,7 +14,7 @@ module GhostAdapter
|
|
12
14
|
[
|
13
15
|
EXECUTABLE,
|
14
16
|
*base_args,
|
15
|
-
*
|
17
|
+
*config_args,
|
16
18
|
*execute_arg
|
17
19
|
]
|
18
20
|
end
|
@@ -37,6 +39,18 @@ module GhostAdapter
|
|
37
39
|
]
|
38
40
|
end
|
39
41
|
|
42
|
+
def config_args
|
43
|
+
context = {
|
44
|
+
pid: $PID,
|
45
|
+
table: table,
|
46
|
+
database: database,
|
47
|
+
timestamp: Time.now.utc.to_i,
|
48
|
+
unique_id: SecureRandom.uuid
|
49
|
+
}
|
50
|
+
|
51
|
+
GhostAdapter.config.as_args(context: context)
|
52
|
+
end
|
53
|
+
|
40
54
|
def execute_arg
|
41
55
|
dry_run ? [] : ['--execute']
|
42
56
|
end
|
data/lib/ghost_adapter/config.rb
CHANGED
@@ -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
|
@@ -78,32 +79,44 @@ module GhostAdapter
|
|
78
79
|
user
|
79
80
|
verbose].freeze
|
80
81
|
Config = Struct.new(*CONFIG_KEYS, keyword_init: true) do
|
81
|
-
def initialize(options = {})
|
82
|
-
env_config = EnvParser.new(ENV).config
|
83
|
-
config_options = options.merge(env_config)
|
84
|
-
super(config_options)
|
85
|
-
end
|
86
|
-
|
87
82
|
def merge!(other_config)
|
88
83
|
other_config.compact.each { |k, v| self[k] = v }
|
89
84
|
self
|
90
85
|
end
|
91
86
|
|
87
|
+
def with_env
|
88
|
+
env_config = EnvParser.new(ENV).config
|
89
|
+
compact.merge(env_config)
|
90
|
+
end
|
91
|
+
|
92
92
|
def compact
|
93
93
|
to_h.compact
|
94
94
|
end
|
95
95
|
|
96
|
-
def as_args
|
97
|
-
|
98
|
-
|
96
|
+
def as_args(context: {})
|
97
|
+
full_context = context.merge(compact)
|
98
|
+
with_env.map { |key, value| arg(key, value, full_context) }.compact
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def arg(key, value, context)
|
104
|
+
return unless value
|
105
|
+
|
106
|
+
hyphenated_key = key.to_s.gsub('_', '-')
|
107
|
+
if value == true
|
108
|
+
"--#{hyphenated_key}"
|
109
|
+
else
|
110
|
+
substituted_value = substitute_value(value, context)
|
111
|
+
"--#{hyphenated_key}=#{substituted_value}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def substitute_value(value, context)
|
116
|
+
return value unless value.is_a? String
|
117
|
+
return value unless value =~ /<%=.*%>/
|
99
118
|
|
100
|
-
|
101
|
-
if value == true
|
102
|
-
"--#{hyphenated_key}"
|
103
|
-
else
|
104
|
-
"--#{hyphenated_key}=#{value}"
|
105
|
-
end
|
106
|
-
end.compact
|
119
|
+
ERB.new(value).result_with_hash(context)
|
107
120
|
end
|
108
121
|
end
|
109
122
|
end
|
@@ -7,6 +7,9 @@ module GhostAdapter
|
|
7
7
|
next unless ghost_key?(key)
|
8
8
|
|
9
9
|
config_key = convert_env_key(key)
|
10
|
+
|
11
|
+
next unless GhostAdapter::CONFIG_KEYS.include?(config_key)
|
12
|
+
|
10
13
|
config_value = convert_env_value(value)
|
11
14
|
|
12
15
|
[config_key, config_value]
|
@@ -20,7 +23,7 @@ module GhostAdapter
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def convert_env_key(key)
|
23
|
-
key.gsub('GHOST_', '').downcase
|
26
|
+
key.gsub('GHOST_', '').downcase.to_sym
|
24
27
|
end
|
25
28
|
|
26
29
|
def convert_env_value(value)
|
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.
|
4
|
+
version: 0.2.2
|
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-
|
11
|
+
date: 2021-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,6 +24,26 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mysql2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.6.0
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.4.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.6.0
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: bump
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,33 +87,33 @@ dependencies:
|
|
67
87
|
- !ruby/object:Gem::Version
|
68
88
|
version: '11.1'
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
90
|
+
name: rake
|
71
91
|
requirement: !ruby/object:Gem::Requirement
|
72
92
|
requirements:
|
73
93
|
- - "~>"
|
74
94
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
95
|
+
version: '13.0'
|
76
96
|
type: :development
|
77
97
|
prerelease: false
|
78
98
|
version_requirements: !ruby/object:Gem::Requirement
|
79
99
|
requirements:
|
80
100
|
- - "~>"
|
81
101
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
102
|
+
version: '13.0'
|
83
103
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
104
|
+
name: rspec
|
85
105
|
requirement: !ruby/object:Gem::Requirement
|
86
106
|
requirements:
|
87
107
|
- - "~>"
|
88
108
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
109
|
+
version: '3'
|
90
110
|
type: :development
|
91
111
|
prerelease: false
|
92
112
|
version_requirements: !ruby/object:Gem::Requirement
|
93
113
|
requirements:
|
94
114
|
- - "~>"
|
95
115
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
116
|
+
version: '3'
|
97
117
|
- !ruby/object:Gem::Dependency
|
98
118
|
name: rubocop
|
99
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,9 +138,9 @@ files:
|
|
118
138
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
119
139
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
120
140
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
141
|
+
- ".github/workflows/tests.yml"
|
121
142
|
- ".gitignore"
|
122
143
|
- ".rubocop.yml"
|
123
|
-
- ".travis.yml"
|
124
144
|
- ".vscode/settings.json"
|
125
145
|
- CHANGELOG.md
|
126
146
|
- CODEOWNERS
|
data/.travis.yml
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm: 2.7
|
3
|
-
|
4
|
-
cache:
|
5
|
-
bundler: true
|
6
|
-
|
7
|
-
before_install:
|
8
|
-
- bundle install --jobs=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
9
|
-
|
10
|
-
stages:
|
11
|
-
- name: Rubocop
|
12
|
-
if: type = pull_request OR branch = main
|
13
|
-
- name: Tests
|
14
|
-
if: type = pull_request OR branch = main
|
15
|
-
|
16
|
-
jobs:
|
17
|
-
include:
|
18
|
-
- stage: Rubocop
|
19
|
-
name: Run rubocop
|
20
|
-
script:
|
21
|
-
- bundle exec rake rubocop
|
22
|
-
- stage: Tests
|
23
|
-
name: Run minitest
|
24
|
-
script:
|
25
|
-
- bundle exec rake test
|