ghost_adapter 0.4.1 → 0.5.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: ea565989a793b275a4124e34beded6b11890dfd5685cdd4416d2cd7467001705
4
- data.tar.gz: 6be8ceeac7032ddcd3659c987cc8f26d126b80de97ffa6b402b0b18389da5d10
3
+ metadata.gz: b98dc5855519562f982afa2e73b0022a1189c56d2b462eea08070fc4b67b80b1
4
+ data.tar.gz: b00a22d2fb5c2e72f8d863a51e66ade75e79511c04cf0f70afebc3aa5fa5d890
5
5
  SHA512:
6
- metadata.gz: d953252f832533164a43886b1e70f42deff950a11ba2fb8849e5fa78a8a81a165f4de56ab19005f48dcece9919e474fa2ba8d2a233af816fa6efc1af1785bc70
7
- data.tar.gz: 2adfa6264b65830d33204f88246507cca0d635e853464799501be16944c30faf8e8373a2f836ad4be44ece0e1f9510cc1cd19ea875f504353b852b91572c4ae7
6
+ metadata.gz: 58bfcb9d8dc770ed0568d2113370fc76978dadf7e13ce54e7fe8515f994328d0b1e38c214a428d4aa9d43e41c34b7b042212e59c7efd6eb84769a6e3fd7d4316
7
+ data.tar.gz: e4d18d03186582228664f3c47626fdaec83b65ef50dc96bdf056feaf2a20e7e51089be036b73740d3f68ac48e979508f398abf9ecb731c510f3721f5247fefa7
data/README.md CHANGED
@@ -62,6 +62,16 @@ If you have used the rails generator, you can set the variable to a falsey value
62
62
  - "truthy" values: `[1, t, true, y, yes]`
63
63
  - "falsey" values: `[0, f, false, n, no]`
64
64
 
65
+ ### Running tests
66
+
67
+ To run the tests for all versions, run this script:
68
+
69
+ ``` shell
70
+ bin/test_all_versions
71
+ ```
72
+
73
+ Make sure to use the appropriate Ruby version! ActiveRecord <6.0 is not compatible with Ruby 3, so specs for those versions will only run successfully in a Ruby 2 environment.
74
+
65
75
  ## Contributing
66
76
 
67
77
  Bug reports and pull requests are welcome on GitHub at https://github.com/wetransfer/ghost_adapter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](./CODE_OF_CONDUCT.md).
@@ -18,9 +18,9 @@ module ActiveRecord
18
18
  end
19
19
 
20
20
  client = Mysql2::Client.new(config)
21
- if GhostAdapter::Internal.ghost_migration_enabeld?
22
- dry_run = ENV['DRY_RUN'] == '1'
23
- GhostAdapter::VersionChecker.validate_executable! unless ENV['SKIP_GHOST_VERSION_CHECK'] == '1'
21
+ if GhostAdapter::Internal.ghost_migration_enabled?
22
+ dry_run = ENV.fetch('DRY_RUN', nil) == '1'
23
+ GhostAdapter::VersionChecker.validate_executable! unless ENV.fetch('SKIP_GHOST_VERSION_CHECK', nil) == '1'
24
24
  ConnectionAdapters::Mysql2GhostAdapter.new(client, logger, nil, config, dry_run: dry_run)
25
25
  else
26
26
  ConnectionAdapters::Mysql2Adapter.new(client, logger, nil, config)
@@ -42,16 +42,29 @@ module ActiveRecord
42
42
  @dry_run = dry_run
43
43
  end
44
44
 
45
- def execute(sql, name = nil)
46
- # Only ALTER TABLE statements are automatically skipped by gh-ost
47
- # We need to manually skip CREATE TABLE, DROP TABLE, and
48
- # INSERT/DELETE (to schema migrations) for dry runs
49
- return if dry_run && should_skip_for_dry_run?(sql)
50
-
51
- if (table, query = parse_sql(sql))
52
- GhostAdapter::Migrator.execute(table, query, database, dry_run)
53
- else
54
- super(sql, name)
45
+ if Gem.loaded_specs['activerecord'].version >= Gem::Version.new('7.0')
46
+ def execute(sql, name = nil, async: false)
47
+ # Only ALTER TABLE statements are automatically skipped by gh-ost
48
+ # We need to manually skip CREATE TABLE, DROP TABLE, and
49
+ # INSERT/DELETE (to schema migrations) for dry runs
50
+ return if dry_run && should_skip_for_dry_run?(sql)
51
+
52
+ if (table, query = parse_sql(sql))
53
+ GhostAdapter::Migrator.execute(table, query, database, dry_run)
54
+ else
55
+ super(sql, name, async: async)
56
+ end
57
+ end
58
+ else
59
+ def execute(sql, name = nil)
60
+ # See comment above -- some tables need to be skipped manually for dry runs
61
+ return if dry_run && should_skip_for_dry_run?(sql)
62
+
63
+ if (table, query = parse_sql(sql))
64
+ GhostAdapter::Migrator.execute(table, query, database, dry_run)
65
+ else
66
+ super(sql, name)
67
+ end
55
68
  end
56
69
  end
57
70
 
@@ -80,7 +93,7 @@ module ActiveRecord
80
93
  end
81
94
  else
82
95
  def add_index(table_name, column_name, options = {})
83
- index_name, index_type, index_columns, _index_options = add_index_options(table_name, column_name, options)
96
+ index_name, index_type, index_columns, _index_options = add_index_options(table_name, column_name, **options)
84
97
 
85
98
  sql = build_add_index_sql(
86
99
  table_name, index_columns, index_name,
@@ -103,7 +116,7 @@ module ActiveRecord
103
116
  attr_reader :database, :dry_run
104
117
 
105
118
  ALTER_TABLE_PATTERN = /\AALTER\s+TABLE\W*(?<table_name>\w+)\W*(?<query>.*)$/i.freeze
106
- QUERY_ALLOWABLE_CHARS = /[^0-9a-z_\s():'"{},]/i.freeze
119
+ QUERY_ALLOWABLE_CHARS = /[^0-9a-z_\s():'"{},`]/i.freeze
107
120
  CREATE_TABLE_PATTERN = /\Acreate\stable/i.freeze
108
121
  DROP_TABLE_PATTERN = /\Acreate\stable/i.freeze
109
122
  INSERT_SCHEMA_MIGRATION_PATTERN = /\Ainsert\sinto\s`schema_migrations`/i.freeze
@@ -1,3 +1,3 @@
1
1
  module GhostAdapter
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
data/lib/ghost_adapter.rb CHANGED
@@ -5,7 +5,7 @@ require 'active_record/connection_adapters/mysql2_ghost_adapter'
5
5
 
6
6
  require 'ghost_adapter/config'
7
7
 
8
- require 'ghost_adapter/railtie' if defined? ::Rails::Railtie
8
+ require 'ghost_adapter/railtie' if defined? Rails::Railtie
9
9
 
10
10
  module GhostAdapter
11
11
  def self.config
@@ -43,8 +43,8 @@ module GhostAdapter
43
43
  @@ghost_migration_enabled = true # rubocop:disable Style/ClassVars
44
44
  end
45
45
 
46
- def self.ghost_migration_enabeld?
47
- env_val = ENV['GHOST_MIGRATE']&.downcase
46
+ def self.ghost_migration_enabled?
47
+ env_val = ENV.fetch('GHOST_MIGRATE', 'false').downcase
48
48
  return false if %w[0 n no f false].include?(env_val)
49
49
 
50
50
  !!@@ghost_migration_enabled || %w[1 y yes t true].include?(env_val)
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.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin C Roos
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2023-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -182,7 +182,7 @@ metadata:
182
182
  homepage_uri: https://github.com/wetransfer/ghost_adapter
183
183
  source_code_uri: https://github.com/wetransfer/ghost_adapter
184
184
  rubygems_mfa_required: 'true'
185
- post_install_message:
185
+ post_install_message:
186
186
  rdoc_options: []
187
187
  require_paths:
188
188
  - lib
@@ -197,8 +197,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  - !ruby/object:Gem::Version
198
198
  version: '0'
199
199
  requirements: []
200
- rubygems_version: 3.2.32
201
- signing_key:
200
+ rubygems_version: 3.1.6
201
+ signing_key:
202
202
  specification_version: 4
203
203
  summary: Run ActiveRecord migrations through gh-ost
204
204
  test_files: []