ghost_adapter 0.1.4 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/{ruby.yml → tests.yml} +1 -1
- data/CHANGELOG.md +13 -0
- data/CONTRIBUTORS.md +1 -0
- data/Gemfile.lock +19 -19
- data/README.md +5 -5
- data/lib/active_record/connection_adapters/mysql2_ghost_adapter.rb +2 -1
- data/lib/ghost_adapter/command.rb +15 -1
- data/lib/ghost_adapter/config.rb +14 -4
- data/lib/ghost_adapter/version.rb +1 -1
- metadata +4 -5
- 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: 2a5f29780a337090d7ba06e77f8e1ce6c6976f5869ec0065e8ab0dfb0f1cc04a
|
4
|
+
data.tar.gz: 2e7bcdb40edcd0cd958c7be99fcc5c31e4a121a8c5c05c70549e6cee3ac63389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dedd0ba573c4abed8d55744cb7f87c6154969d7daa7cc283077c6077d6b690a1ade38e30a8e208fc4584f8b9622d9cf866fbef67bfb1ac8f3f8c3872e8e27f0
|
7
|
+
data.tar.gz: 0b352f02462f55a3cb362a87526b0cca3b47985eb7659e85ce60d40ba2d93766d3be589afe90f17091ee3e82818c76528738b4223c0c25598e48bae6e5791f09
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
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
|
+
|
3
16
|
## 0.1.4
|
4
17
|
|
5
18
|
- Fix bug caused by missing `require 'open3'` that occurs for some ruby versions
|
data/CONTRIBUTORS.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ghost_adapter (0.
|
4
|
+
ghost_adapter (0.2.3)
|
5
5
|
activerecord (>= 5)
|
6
6
|
mysql2 (>= 0.4.0, < 0.6.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (6.1.
|
12
|
-
activesupport (= 6.1.
|
13
|
-
activerecord (6.1.
|
14
|
-
activemodel (= 6.1.
|
15
|
-
activesupport (= 6.1.
|
16
|
-
activesupport (6.1.
|
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
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 1.6, < 2)
|
19
19
|
minitest (>= 5.1)
|
@@ -22,19 +22,19 @@ GEM
|
|
22
22
|
ast (2.4.2)
|
23
23
|
bump (0.10.0)
|
24
24
|
byebug (11.1.3)
|
25
|
-
concurrent-ruby (1.1.
|
25
|
+
concurrent-ruby (1.1.9)
|
26
26
|
diff-lcs (1.4.4)
|
27
|
-
i18n (1.8.
|
27
|
+
i18n (1.8.10)
|
28
28
|
concurrent-ruby (~> 1.0)
|
29
29
|
minitest (5.14.4)
|
30
30
|
mysql2 (0.5.3)
|
31
|
-
parallel (1.
|
32
|
-
parser (3.0.
|
31
|
+
parallel (1.21.0)
|
32
|
+
parser (3.0.2.0)
|
33
33
|
ast (~> 2.4.1)
|
34
34
|
rainbow (3.0.0)
|
35
|
-
rake (13.0.
|
36
|
-
regexp_parser (2.
|
37
|
-
rexml (3.2.
|
35
|
+
rake (13.0.6)
|
36
|
+
regexp_parser (2.1.1)
|
37
|
+
rexml (3.2.5)
|
38
38
|
rspec (3.10.0)
|
39
39
|
rspec-core (~> 3.10.0)
|
40
40
|
rspec-expectations (~> 3.10.0)
|
@@ -48,17 +48,17 @@ GEM
|
|
48
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
49
|
rspec-support (~> 3.10.0)
|
50
50
|
rspec-support (3.10.2)
|
51
|
-
rubocop (1.
|
51
|
+
rubocop (1.21.0)
|
52
52
|
parallel (~> 1.10)
|
53
53
|
parser (>= 3.0.0.0)
|
54
54
|
rainbow (>= 2.2.2, < 4.0)
|
55
55
|
regexp_parser (>= 1.8, < 3.0)
|
56
56
|
rexml
|
57
|
-
rubocop-ast (>= 1.
|
57
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
58
58
|
ruby-progressbar (~> 1.7)
|
59
59
|
unicode-display_width (>= 1.4.0, < 3.0)
|
60
|
-
rubocop-ast (1.
|
61
|
-
parser (>=
|
60
|
+
rubocop-ast (1.11.0)
|
61
|
+
parser (>= 3.0.1.1)
|
62
62
|
ruby-progressbar (1.11.0)
|
63
63
|
tzinfo (2.0.4)
|
64
64
|
concurrent-ruby (~> 1.0)
|
@@ -79,4 +79,4 @@ DEPENDENCIES
|
|
79
79
|
rubocop (~> 1)
|
80
80
|
|
81
81
|
BUNDLED WITH
|
82
|
-
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
|
|
@@ -1,4 +1,5 @@
|
|
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
|
require 'mysql2'
|
@@ -69,7 +70,7 @@ module ActiveRecord
|
|
69
70
|
attr_reader :database, :dry_run
|
70
71
|
|
71
72
|
ALTER_TABLE_PATTERN = /\AALTER\s+TABLE\W*(?<table_name>\w+)\W*(?<query>.*)$/i.freeze
|
72
|
-
QUERY_ALLOWABLE_CHARS = /[^0-9a-z_\s():'"{}]/i.freeze
|
73
|
+
QUERY_ALLOWABLE_CHARS = /[^0-9a-z_\s():'"{},]/i.freeze
|
73
74
|
CREATE_TABLE_PATTERN = /\Acreate\stable/i.freeze
|
74
75
|
DROP_TABLE_PATTERN = /\Acreate\stable/i.freeze
|
75
76
|
INSERT_SCHEMA_MIGRATION_PATTERN = /\Ainsert\sinto\s`schema_migrations`/i.freeze
|
@@ -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
|
@@ -92,21 +93,30 @@ module GhostAdapter
|
|
92
93
|
to_h.compact
|
93
94
|
end
|
94
95
|
|
95
|
-
def as_args
|
96
|
-
|
96
|
+
def as_args(context: {})
|
97
|
+
full_context = context.merge(compact)
|
98
|
+
with_env.map { |key, value| arg(key, value, full_context) }.compact
|
97
99
|
end
|
98
100
|
|
99
101
|
private
|
100
102
|
|
101
|
-
def arg(key, value)
|
103
|
+
def arg(key, value, context)
|
102
104
|
return unless value
|
103
105
|
|
104
106
|
hyphenated_key = key.to_s.gsub('_', '-')
|
105
107
|
if value == true
|
106
108
|
"--#{hyphenated_key}"
|
107
109
|
else
|
108
|
-
|
110
|
+
substituted_value = substitute_value(value, context)
|
111
|
+
"--#{hyphenated_key}=#{substituted_value}"
|
109
112
|
end
|
110
113
|
end
|
114
|
+
|
115
|
+
def substitute_value(value, context)
|
116
|
+
return value unless value.is_a? String
|
117
|
+
return value unless value =~ /<%=.*%>/
|
118
|
+
|
119
|
+
ERB.new(value).result_with_hash(context)
|
120
|
+
end
|
111
121
|
end
|
112
122
|
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.
|
4
|
+
version: 0.2.3
|
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-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -138,10 +138,9 @@ files:
|
|
138
138
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
139
139
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
140
140
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
141
|
-
- ".github/workflows/
|
141
|
+
- ".github/workflows/tests.yml"
|
142
142
|
- ".gitignore"
|
143
143
|
- ".rubocop.yml"
|
144
|
-
- ".travis.yml"
|
145
144
|
- ".vscode/settings.json"
|
146
145
|
- CHANGELOG.md
|
147
146
|
- CODEOWNERS
|
@@ -187,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
186
|
- !ruby/object:Gem::Version
|
188
187
|
version: '0'
|
189
188
|
requirements: []
|
190
|
-
rubygems_version: 3.1.
|
189
|
+
rubygems_version: 3.1.6
|
191
190
|
signing_key:
|
192
191
|
specification_version: 4
|
193
192
|
summary: Run ActiveRecord migrations through gh-ost
|
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 specs
|
24
|
-
script:
|
25
|
-
- bundle exec rake spec
|