ghost_adapter 0.1.4 → 0.2.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: 1cabaf83939ee711ed1679803274084bedf6598c2711d69bfeee19cb404a0add
4
- data.tar.gz: e42e338f2c2afc2ea448fc9e14fb5132781b9afedcf1c097131e39a935efcb15
3
+ metadata.gz: 70c1ceb8f7c2ca8a3cdf0bd71a2bc0d3c8b7701acf8dd4ee5f1d5c80adef5b7c
4
+ data.tar.gz: 802ccf5c7a692c6647fdf313fd70e8f0f67d889ecaef8dab4c39f721557057be
5
5
  SHA512:
6
- metadata.gz: 80eb4f5803734e3a599c165df1b22fa6892db6fd685d6aa59fc445a072376fad3e8e4fb8535dce94c44af9aced1ec34594a33270b4c0457b0826a11c8e9f6263
7
- data.tar.gz: d2ef0fa71b5a429e1cddbe99c1432f047ac4842636f6cb58551416ff88f05d8a7d6ff3b1303c3a2769fb68aee95850b749f9b9831154f15bb2b4e66e2dba19a9
6
+ metadata.gz: 5bdf26f1667220ff862464a362b62af21dafc065f254adf9a9d41be1cd81a98ddb6b1639af7bfd61cbd05a9a2fb47673bf15f7025e3a13209a530d9b449ed7d5
7
+ data.tar.gz: 6f1e6a8d0ea9d5b654ae6eec9ea8cdb176a87ff1d668f4ff26f08b27a7af29c97ba2052882f10a8df62de91623962e1bc7b4dcfe300ab05aeb491365e36c27e1
@@ -1,4 +1,4 @@
1
- name: Ruby
1
+ name: Tests
2
2
 
3
3
  on:
4
4
  push:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.0
4
+
5
+ - Add templating to configuration values. See [the docs](./docs/config/templating.md) for more info on how to use this feature.
6
+
3
7
  ## 0.1.4
4
8
 
5
9
  - Fix bug caused by missing `require 'open3'` that occurs for some ruby versions
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ghost_adapter (0.1.4)
4
+ ghost_adapter (0.2.0)
5
5
  activerecord (>= 5)
6
6
  mysql2 (>= 0.4.0, < 0.6.0)
7
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
- [![Build Status](https://travis-ci.com/WeTransfer/ghost_adapter.svg?branch=main)](https://travis-ci.com/WeTransfer/ghost_adapter)
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 identical behavior to the Mysql2Adapter. No need to be executing a bunch of extra logic per query when you're only getting any value for migrations.
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
- *GhostAdapter.config.as_args,
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
@@ -92,21 +92,30 @@ module GhostAdapter
92
92
  to_h.compact
93
93
  end
94
94
 
95
- def as_args
96
- with_env.map { |key, value| arg(key, value) }.compact
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
- "--#{hyphenated_key}=#{value}"
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
@@ -1,3 +1,3 @@
1
1
  module GhostAdapter
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.2.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.1.4
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-03-29 00:00:00.000000000 Z
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/ruby.yml"
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