ghost_adapter 0.1.1 → 0.2.1
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 +20 -0
- data/Gemfile.lock +27 -11
- data/README.md +3 -3
- data/Rakefile +3 -9
- data/ghost_adapter.gemspec +2 -1
- data/lib/active_record/connection_adapters/mysql2_ghost_adapter.rb +11 -2
- data/lib/ghost_adapter.rb +5 -0
- data/lib/ghost_adapter/command.rb +15 -1
- data/lib/ghost_adapter/config.rb +28 -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 +30 -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: 74aed2db6347e0839ee599e4cc30d41f8261533d8926aa65a3fb97bdb0518348
|
4
|
+
data.tar.gz: 12e12bfd052ff336e2b2f9088e18554bdc00e7e0647f65254a33f6b32c9a6fd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0de5d2b1dc0162733d976379a2eaf3f892b1c189fe799619f5c6129bfa7a9e285748ce9076c095d471f8c29d4e194335087ee2becc615781c0e9ac76412b687
|
7
|
+
data.tar.gz: da399185e546d532a8b501b4a00c97dd1ade0611c438e444024cf8ad891ca77a024fab31de7c1feb1af0c9755749b95a556316cf730c50f22a98fda15f3b8bc5
|
@@ -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
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## 0.2.1
|
4
|
+
- Fix bug caused by missing `require 'ghost_adapter'` for non-rails apps ([#34](https://github.com/WeTransfer/ghost_adapter/pull/34))
|
5
|
+
|
6
|
+
## 0.2.0
|
7
|
+
|
8
|
+
- Add templating to configuration values. See [the docs](./docs/config/templating.md) for more info on how to use this feature.
|
9
|
+
|
10
|
+
## 0.1.4
|
11
|
+
|
12
|
+
- Fix bug caused by missing `require 'open3'` that occurs for some ruby versions
|
13
|
+
|
14
|
+
## 0.1.3
|
15
|
+
|
16
|
+
- Fix bug [#26](https://github.com/WeTransfer/ghost_adapter/issues/26) causing environment configuration to be overwritten by some other configuration methods.
|
17
|
+
|
18
|
+
## 0.1.2
|
19
|
+
|
20
|
+
- 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.1)
|
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.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)
|
16
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
18
|
i18n (>= 1.6, < 2)
|
18
19
|
minitest (>= 5.1)
|
@@ -22,9 +23,11 @@ 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)
|
@@ -32,6 +35,19 @@ GEM
|
|
32
35
|
rake (13.0.3)
|
33
36
|
regexp_parser (2.0.3)
|
34
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)
|
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,7 +3,7 @@
|
|
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
8
|
[![gh-ost version](https://img.shields.io/badge/gh--ost%20version-1.1.0-blue)](https://github.com/github/gh-ost/releases/latest)
|
9
9
|
|
@@ -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
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'active_record/connection_adapters/mysql2_adapter'
|
2
|
+
require 'ghost_adapter'
|
2
3
|
require 'ghost_adapter/migrator'
|
3
4
|
require 'ghost_adapter/version_checker'
|
4
|
-
|
5
|
-
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
|
6
5
|
require 'mysql2'
|
7
6
|
|
8
7
|
module ActiveRecord
|
@@ -56,6 +55,16 @@ module ActiveRecord
|
|
56
55
|
end
|
57
56
|
end
|
58
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
|
62
|
+
|
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)}"
|
66
|
+
end
|
67
|
+
|
59
68
|
private
|
60
69
|
|
61
70
|
attr_reader :database, :dry_run
|
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
@@ -78,32 +78,44 @@ module GhostAdapter
|
|
78
78
|
user
|
79
79
|
verbose].freeze
|
80
80
|
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
81
|
def merge!(other_config)
|
88
82
|
other_config.compact.each { |k, v| self[k] = v }
|
89
83
|
self
|
90
84
|
end
|
91
85
|
|
86
|
+
def with_env
|
87
|
+
env_config = EnvParser.new(ENV).config
|
88
|
+
compact.merge(env_config)
|
89
|
+
end
|
90
|
+
|
92
91
|
def compact
|
93
92
|
to_h.compact
|
94
93
|
end
|
95
94
|
|
96
|
-
def as_args
|
97
|
-
|
98
|
-
|
95
|
+
def as_args(context: {})
|
96
|
+
full_context = context.merge(compact)
|
97
|
+
with_env.map { |key, value| arg(key, value, full_context) }.compact
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def arg(key, value, context)
|
103
|
+
return unless value
|
104
|
+
|
105
|
+
hyphenated_key = key.to_s.gsub('_', '-')
|
106
|
+
if value == true
|
107
|
+
"--#{hyphenated_key}"
|
108
|
+
else
|
109
|
+
substituted_value = substitute_value(value, context)
|
110
|
+
"--#{hyphenated_key}=#{substituted_value}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def substitute_value(value, context)
|
115
|
+
return value unless value.is_a? String
|
116
|
+
return value unless value =~ /<%=.*%>/
|
99
117
|
|
100
|
-
|
101
|
-
if value == true
|
102
|
-
"--#{hyphenated_key}"
|
103
|
-
else
|
104
|
-
"--#{hyphenated_key}=#{value}"
|
105
|
-
end
|
106
|
-
end.compact
|
118
|
+
ERB.new(value).result_with_hash(context)
|
107
119
|
end
|
108
120
|
end
|
109
121
|
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.1
|
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-04-13 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,10 +138,11 @@ 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"
|
145
|
+
- CHANGELOG.md
|
125
146
|
- CODEOWNERS
|
126
147
|
- CODE_OF_CONDUCT.md
|
127
148
|
- CONTRIBUTORS.md
|
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
|