ghost_adapter 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/{ruby.yml → tests.yml} +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -3
- data/lib/ghost_adapter/command.rb +15 -1
- data/lib/ghost_adapter/config.rb +13 -4
- data/lib/ghost_adapter/version.rb +1 -1
- metadata +3 -4
- 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: 70c1ceb8f7c2ca8a3cdf0bd71a2bc0d3c8b7701acf8dd4ee5f1d5c80adef5b7c
|
4
|
+
data.tar.gz: 802ccf5c7a692c6647fdf313fd70e8f0f67d889ecaef8dab4c39f721557057be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bdf26f1667220ff862464a362b62af21dafc065f254adf9a9d41be1cd81a98ddb6b1639af7bfd61cbd05a9a2fb47673bf15f7025e3a13209a530d9b449ed7d5
|
7
|
+
data.tar.gz: 6f1e6a8d0ea9d5b654ae6eec9ea8cdb176a87ff1d668f4ff26f08b27a7af29c97ba2052882f10a8df62de91623962e1bc7b4dcfe300ab05aeb491365e36c27e1
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|

|
4
4
|
|
5
5
|
[](https://rubygems.org/gems/ghost_adapter)
|
6
|
-
|
6
|
+

|
7
7
|
[](https://github.com/WeTransfer/ghost_adapter/blob/main/LICENSE.md)
|
8
8
|
[](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
|
|
@@ -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
@@ -92,21 +92,30 @@ module GhostAdapter
|
|
92
92
|
to_h.compact
|
93
93
|
end
|
94
94
|
|
95
|
-
def as_args
|
96
|
-
|
95
|
+
def as_args(context: {})
|
96
|
+
full_context = context.merge(compact)
|
97
|
+
with_env.map { |key, value| arg(key, value, full_context) }.compact
|
97
98
|
end
|
98
99
|
|
99
100
|
private
|
100
101
|
|
101
|
-
def arg(key, value)
|
102
|
+
def arg(key, value, context)
|
102
103
|
return unless value
|
103
104
|
|
104
105
|
hyphenated_key = key.to_s.gsub('_', '-')
|
105
106
|
if value == true
|
106
107
|
"--#{hyphenated_key}"
|
107
108
|
else
|
108
|
-
|
109
|
+
substituted_value = substitute_value(value, context)
|
110
|
+
"--#{hyphenated_key}=#{substituted_value}"
|
109
111
|
end
|
110
112
|
end
|
113
|
+
|
114
|
+
def substitute_value(value, context)
|
115
|
+
return value unless value.is_a? String
|
116
|
+
return value unless value =~ /<%=.*%>/
|
117
|
+
|
118
|
+
ERB.new(value).result_with_hash(context)
|
119
|
+
end
|
111
120
|
end
|
112
121
|
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.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-
|
11
|
+
date: 2021-04-02 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
|
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
|