departure 8.1.0 → 8.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +3 -1
  3. data/.pryrc +6 -6
  4. data/.standard.yml +9 -0
  5. data/AGENTS.md +9 -7
  6. data/Appraisals +11 -9
  7. data/CHANGELOG.md +4 -0
  8. data/Gemfile +8 -9
  9. data/Gemfile.lock +25 -11
  10. data/README.md +1 -1
  11. data/RELEASING.md +5 -4
  12. data/Rakefile +10 -10
  13. data/configuration.rb +3 -3
  14. data/departure.gemspec +22 -24
  15. data/gemfiles/rails_7_2.gemfile +12 -12
  16. data/gemfiles/rails_7_2.gemfile.lock +28 -11
  17. data/gemfiles/rails_8_0.gemfile +12 -12
  18. data/gemfiles/rails_8_0.gemfile.lock +28 -11
  19. data/gemfiles/rails_8_1.gemfile +11 -12
  20. data/gemfiles/rails_8_1.gemfile.lock +25 -11
  21. data/lib/active_record/connection_adapters/departure_adapter_behavior.rb +88 -0
  22. data/lib/active_record/connection_adapters/for_alter.rb +4 -4
  23. data/lib/active_record/connection_adapters/patch_connection_handling.rb +2 -2
  24. data/lib/active_record/connection_adapters/rails_7_2_departure_adapter.rb +17 -58
  25. data/lib/active_record/connection_adapters/rails_7_2_trilogy_adapter.rb +53 -0
  26. data/lib/active_record/connection_adapters/rails_8_0_departure_adapter.rb +26 -66
  27. data/lib/active_record/connection_adapters/rails_8_0_trilogy_adapter.rb +21 -0
  28. data/lib/active_record/connection_adapters/rails_8_1_mysql2_adapter.rb +7 -7
  29. data/lib/active_record/connection_adapters/rails_8_1_trilogy_adapter.rb +7 -7
  30. data/lib/departure/alter_argument.rb +6 -6
  31. data/lib/departure/cli_generator.rb +12 -12
  32. data/lib/departure/command.rb +1 -1
  33. data/lib/departure/configuration.rb +3 -3
  34. data/lib/departure/connection_details.rb +7 -7
  35. data/lib/departure/db_client.rb +5 -5
  36. data/lib/departure/dsn.rb +2 -2
  37. data/lib/departure/errors.rb +2 -2
  38. data/lib/departure/log_sanitizers/password_sanitizer.rb +1 -1
  39. data/lib/departure/logger.rb +2 -2
  40. data/lib/departure/option.rb +4 -4
  41. data/lib/departure/rails_adapter.rb +126 -102
  42. data/lib/departure/rails_patches/active_record_migrator_with_advisory_lock_patch.rb +2 -2
  43. data/lib/departure/railtie.rb +5 -5
  44. data/lib/departure/runner.rb +3 -3
  45. data/lib/departure/user_options.rb +1 -1
  46. data/lib/departure/version.rb +1 -1
  47. data/lib/departure.rb +18 -18
  48. data/lib/lhm/adapter.rb +12 -12
  49. data/lib/lhm/column_with_sql.rb +8 -8
  50. data/lib/lhm.rb +1 -1
  51. data/test_database.rb +10 -10
  52. metadata +5 -4
  53. data/.rubocop.yml +0 -66
  54. data/.rubocop_todo.yml +0 -238
  55. data/lib/active_record/connection_adapters/rails_8_1_adapter_behavior.rb +0 -64
@@ -1,5 +1,5 @@
1
- require 'open3'
2
- require 'forwardable'
1
+ require "open3"
2
+ require "forwardable"
3
3
 
4
4
  # Runner is deprecated and used in rails 8.0 and below
5
5
  # We will slowly reduce the responsibility of departure to be delegating
@@ -11,7 +11,7 @@ module Departure
11
11
  class Runner
12
12
  extend ::Forwardable
13
13
 
14
- def_delegators :raw_connection, :execute, :escape, :close, :affected_rows
14
+ def_delegators :raw_connection, :escape, :close
15
15
 
16
16
  # Constructor
17
17
  #
@@ -6,7 +6,7 @@ module Departure
6
6
  # Constructor
7
7
  #
8
8
  # @param arguments [String]
9
- def initialize(arguments = ENV['PERCONA_ARGS'])
9
+ def initialize(arguments = ENV["PERCONA_ARGS"])
10
10
  @arguments = arguments
11
11
  end
12
12
 
@@ -1,3 +1,3 @@
1
1
  module Departure
2
- VERSION = '8.1.0'.freeze
2
+ VERSION = "8.2.0".freeze
3
3
  end
data/lib/departure.rb CHANGED
@@ -1,24 +1,24 @@
1
- require 'active_record'
2
- require 'active_support/all'
1
+ require "active_record"
2
+ require "active_support/all"
3
3
 
4
- require 'active_record/connection_adapters/for_alter'
4
+ require "active_record/connection_adapters/for_alter"
5
5
 
6
- require 'departure/version'
7
- require 'departure/log_sanitizers/password_sanitizer'
8
- require 'departure/db_client'
9
- require 'departure/runner'
10
- require 'departure/cli_generator'
11
- require 'departure/logger'
12
- require 'departure/null_logger'
13
- require 'departure/logger_factory'
14
- require 'departure/configuration'
15
- require 'departure/errors'
16
- require 'departure/command'
17
- require 'departure/connection_base'
18
- require 'departure/migration'
19
- require 'departure/rails_adapter'
6
+ require "departure/version"
7
+ require "departure/log_sanitizers/password_sanitizer"
8
+ require "departure/db_client"
9
+ require "departure/runner"
10
+ require "departure/cli_generator"
11
+ require "departure/logger"
12
+ require "departure/null_logger"
13
+ require "departure/logger_factory"
14
+ require "departure/configuration"
15
+ require "departure/errors"
16
+ require "departure/command"
17
+ require "departure/connection_base"
18
+ require "departure/migration"
19
+ require "departure/rails_adapter"
20
20
 
21
- require 'departure/railtie' if defined?(Rails)
21
+ require "departure/railtie" if defined?(Rails)
22
22
 
23
23
  # We need the OS not to buffer the IO to see pt-osc's output while migrating
24
24
  $stdout.sync = true
data/lib/lhm/adapter.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'lhm/column_with_sql'
2
- require 'lhm/column_with_type'
1
+ require "lhm/column_with_sql"
2
+ require "lhm/column_with_type"
3
3
 
4
4
  module Lhm
5
5
  # Translates Lhm DSL to ActiveRecord's one, so Lhm migrations will now go
@@ -37,7 +37,7 @@ module Lhm
37
37
  # @param columns [Array<String>, Array<Symbol>, String, Symbol]
38
38
  # @param index_name [String]
39
39
  def add_index(columns, index_name = nil)
40
- options = { name: index_name } if index_name
40
+ options = {name: index_name} if index_name
41
41
  migration.add_index(table_name, columns, options || {})
42
42
  end
43
43
 
@@ -47,10 +47,10 @@ module Lhm
47
47
  # @param index_name [String]
48
48
  def remove_index(columns, index_name = nil)
49
49
  options = if index_name
50
- { name: index_name }
51
- else
52
- { column: columns }
53
- end
50
+ {name: index_name}
51
+ else
52
+ {column: columns}
53
+ end
54
54
  migration.remove_index(table_name, options)
55
55
  end
56
56
 
@@ -76,7 +76,7 @@ module Lhm
76
76
  # @param columns [Array<String>, Array<Symbol>, String, Symbol]
77
77
  # @param index_name [String]
78
78
  def add_unique_index(columns, index_name = nil)
79
- options = { unique: true }
79
+ options = {unique: true}
80
80
  options.merge!(name: index_name) if index_name # rubocop:disable Performance/RedundantMerge
81
81
 
82
82
  migration.add_index(table_name, columns, options)
@@ -93,10 +93,10 @@ module Lhm
93
93
  # @param definition [String]
94
94
  def column(name, definition)
95
95
  @column ||= if definition.is_a?(Symbol)
96
- ColumnWithType.new(name, definition)
97
- else
98
- ColumnWithSql.new(name, definition)
99
- end
96
+ ColumnWithType.new(name, definition)
97
+ else
98
+ ColumnWithSql.new(name, definition)
99
+ end
100
100
  end
101
101
 
102
102
  def column_attributes(name, definition)
@@ -1,4 +1,4 @@
1
- require 'forwardable'
1
+ require "forwardable"
2
2
 
3
3
  module Lhm
4
4
  # Abstracts the details of a table column definition when specified with a MySQL
@@ -38,7 +38,7 @@ module Lhm
38
38
  #
39
39
  # @return [Hash]
40
40
  def column_options
41
- { limit: column.limit, default: column.default, null: column.null }
41
+ {limit: column.limit, default: column.default, null: column.null}
42
42
  end
43
43
 
44
44
  # Returns the column instance with the provided data
@@ -67,14 +67,14 @@ module Lhm
67
67
  # @return [String, NilClass]
68
68
  def default_value
69
69
  match = if definition.match?(/timestamp|datetime/i)
70
- /default '?(.+[^'])'?/i.match(definition)
71
- else
72
- /default '?(\w+)'?/i.match(definition)
73
- end
70
+ /default '?(.+[^'])'?/i.match(definition)
71
+ else
72
+ /default '?(\w+)'?/i.match(definition)
73
+ end
74
74
 
75
75
  return unless match
76
76
 
77
- match[1].downcase != 'null' ? match[1] : nil
77
+ (match[1].downcase != "null") ? match[1] : nil
78
78
  end
79
79
 
80
80
  # Checks whether the column accepts NULL as specified in the definition
@@ -84,7 +84,7 @@ module Lhm
84
84
  match = /((NOT)? NULL)/i.match(definition)
85
85
  return true unless match
86
86
 
87
- match[2]&.downcase == 'not' ? false : true
87
+ !(match[2]&.downcase == "not")
88
88
  end
89
89
  end
90
90
  end
data/lib/lhm.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'lhm/adapter'
1
+ require "lhm/adapter"
2
2
 
3
3
  # Defines the same global namespace as LHM's gem does to mimic its API
4
4
  # while providing a different behaviour. We delegate all LHM's methods to
data/test_database.rb CHANGED
@@ -1,6 +1,6 @@
1
- require 'active_record'
2
- require 'active_record/connection_adapters/mysql2_adapter'
3
- require 'departure'
1
+ require "active_record"
2
+ require "active_record/connection_adapters/mysql2_adapter"
3
+ require "departure"
4
4
 
5
5
  # Setups the test database with the schema_migrations table that ActiveRecord
6
6
  # requires for the migrations, plus a table for the Comment model used throught
@@ -12,7 +12,7 @@ class TestDatabase
12
12
  # @param config [Hash]
13
13
  def initialize(config)
14
14
  @config = config
15
- @database = config['database']
15
+ @database = config["database"]
16
16
  end
17
17
 
18
18
  # Creates the test database, the schema_migrations and the comments tables.
@@ -34,8 +34,8 @@ class TestDatabase
34
34
  def drop_and_create_schema_migrations_table
35
35
  sql = [
36
36
  "USE #{@database}",
37
- 'DROP TABLE IF EXISTS schema_migrations',
38
- 'CREATE TABLE schema_migrations ( version varchar(255) COLLATE utf8_unicode_ci NOT NULL, UNIQUE KEY unique_schema_migrations (version)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci'
37
+ "DROP TABLE IF EXISTS schema_migrations",
38
+ "CREATE TABLE schema_migrations ( version varchar(255) COLLATE utf8_unicode_ci NOT NULL, UNIQUE KEY unique_schema_migrations (version)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"
39
39
  ]
40
40
 
41
41
  run_commands(sql)
@@ -57,17 +57,17 @@ class TestDatabase
57
57
  def drop_and_create_comments_table
58
58
  sql = [
59
59
  "USE #{@database}",
60
- 'DROP TABLE IF EXISTS comments',
61
- 'CREATE TABLE comments ( id bigint(20) NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci'
60
+ "DROP TABLE IF EXISTS comments",
61
+ "CREATE TABLE comments ( id bigint(20) NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"
62
62
  ]
63
63
 
64
64
  run_commands(sql)
65
65
  end
66
66
 
67
67
  def run_commands(sql)
68
- conn.execute('START TRANSACTION')
68
+ conn.execute("START TRANSACTION")
69
69
  sql.each { |str| conn.execute(str) }
70
- conn.execute('COMMIT')
70
+ conn.execute("COMMIT")
71
71
  end
72
72
 
73
73
  def conn
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: departure
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.0
4
+ version: 8.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Zayats
@@ -177,8 +177,7 @@ files:
177
177
  - ".gitignore"
178
178
  - ".pryrc"
179
179
  - ".rspec"
180
- - ".rubocop.yml"
181
- - ".rubocop_todo.yml"
180
+ - ".standard.yml"
182
181
  - AGENTS.md
183
182
  - Appraisals
184
183
  - CHANGELOG.md
@@ -204,11 +203,13 @@ files:
204
203
  - gemfiles/rails_8_0.gemfile.lock
205
204
  - gemfiles/rails_8_1.gemfile
206
205
  - gemfiles/rails_8_1.gemfile.lock
206
+ - lib/active_record/connection_adapters/departure_adapter_behavior.rb
207
207
  - lib/active_record/connection_adapters/for_alter.rb
208
208
  - lib/active_record/connection_adapters/patch_connection_handling.rb
209
209
  - lib/active_record/connection_adapters/rails_7_2_departure_adapter.rb
210
+ - lib/active_record/connection_adapters/rails_7_2_trilogy_adapter.rb
210
211
  - lib/active_record/connection_adapters/rails_8_0_departure_adapter.rb
211
- - lib/active_record/connection_adapters/rails_8_1_adapter_behavior.rb
212
+ - lib/active_record/connection_adapters/rails_8_0_trilogy_adapter.rb
212
213
  - lib/active_record/connection_adapters/rails_8_1_mysql2_adapter.rb
213
214
  - lib/active_record/connection_adapters/rails_8_1_trilogy_adapter.rb
214
215
  - lib/departure.rb
data/.rubocop.yml DELETED
@@ -1,66 +0,0 @@
1
- ---
2
- inherit_from:
3
- - .rubocop_todo.yml
4
-
5
- require:
6
- - rubocop-performance
7
-
8
- AllCops:
9
- TargetRubyVersion: 3.4.x
10
-
11
- Metrics/AbcSize:
12
- Enabled: false
13
-
14
- Metrics/BlockLength:
15
- Max: 20
16
- Exclude:
17
- - 'spec/*'
18
- - 'spec/**/*'
19
-
20
- Metrics/BlockNesting:
21
- Max: 4
22
-
23
- Metrics/ClassLength:
24
- Max: 250
25
-
26
- Layout/LineLength:
27
- Max: 120
28
- Exclude:
29
- - 'departure.gemspec'
30
- - 'test_database.rb'
31
-
32
- Metrics/MethodLength:
33
- Max: 30
34
-
35
- Metrics/ModuleLength:
36
- Max: 250
37
-
38
- Metrics/ParameterLists:
39
- Max: 5
40
-
41
- Performance/Casecmp:
42
- Enabled: false
43
-
44
- Style/CommandLiteral:
45
- Exclude:
46
- - 'test_database.rb'
47
-
48
- Style/Documentation:
49
- Enabled: false
50
-
51
- Style/FrozenStringLiteralComment:
52
- Enabled: false # We never ended up being forced to do this for Ruby 3.x
53
-
54
- Style/MultilineBlockChain:
55
- Exclude:
56
- - 'spec/integration_spec.rb'
57
-
58
- Layout/MultilineMethodCallIndentation:
59
- Enabled: false
60
-
61
- Style/SymbolArray:
62
- Enabled: false
63
-
64
- Style/RedundantPercentQ:
65
- Exclude:
66
- - 'departure.gemspec'
data/.rubocop_todo.yml DELETED
@@ -1,238 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2024-02-08 17:09:11 UTC using RuboCop version 1.60.2.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 3
10
- # This cop supports safe autocorrection (--autocorrect).
11
- # Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
12
- # Include: **/*.gemspec
13
- Gemspec/OrderedDependencies:
14
- Exclude:
15
- - 'departure.gemspec'
16
-
17
- # Offense count: 1
18
- # Configuration parameters: Severity, Include.
19
- # Include: **/*.gemspec
20
- Gemspec/RequiredRubyVersion:
21
- Exclude:
22
- - 'departure.gemspec'
23
-
24
- # Offense count: 3
25
- # This cop supports safe autocorrection (--autocorrect).
26
- # Configuration parameters: EnforcedStyle.
27
- # SupportedStyles: leading, trailing
28
- Layout/DotPosition:
29
- Exclude:
30
- - 'spec/integration/indexes_spec.rb'
31
-
32
- # Offense count: 6
33
- # This cop supports safe autocorrection (--autocorrect).
34
- Layout/EmptyLineAfterGuardClause:
35
- Exclude:
36
- - 'lib/active_record/connection_adapters/for_alter.rb'
37
- - 'lib/active_record/connection_adapters/percona_adapter.rb'
38
- - 'lib/departure/alter_argument.rb'
39
- - 'lib/departure/log_sanitizers/password_sanitizer.rb'
40
- - 'lib/departure/migration.rb'
41
-
42
- # Offense count: 4
43
- # This cop supports safe autocorrection (--autocorrect).
44
- # Configuration parameters: IndentationWidth.
45
- # SupportedStyles: special_inside_parentheses, consistent, align_brackets
46
- Layout/FirstArrayElementIndentation:
47
- EnforcedStyle: consistent
48
-
49
- # Offense count: 1
50
- # This cop supports safe autocorrection (--autocorrect).
51
- # Configuration parameters: Width, AllowedPatterns.
52
- Layout/IndentationWidth:
53
- Exclude:
54
- - 'spec/integration/indexes_spec.rb'
55
-
56
- # Offense count: 1
57
- # This cop supports safe autocorrection (--autocorrect).
58
- # Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment.
59
- Layout/LeadingCommentSpace:
60
- Exclude:
61
- - 'lib/active_record/connection_adapters/for_alter.rb'
62
-
63
- # Offense count: 2
64
- # This cop supports safe autocorrection (--autocorrect).
65
- # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
66
- # SupportedStyles: space, no_space, compact
67
- # SupportedStylesForEmptyBraces: space, no_space
68
- Layout/SpaceInsideHashLiteralBraces:
69
- Exclude:
70
- - 'spec/active_record/connection_adapters/percona_adapter_spec.rb'
71
-
72
- # Offense count: 9
73
- # Configuration parameters: AllowedMethods.
74
- # AllowedMethods: enums
75
- Lint/ConstantDefinitionInBlock:
76
- Exclude:
77
- - 'spec/integration/change_table_spec.rb'
78
- - 'spec/integration/columns_spec.rb'
79
- - 'spec/integration/data_migrations_spec.rb'
80
- - 'spec/integration/foreign_keys_spec.rb'
81
- - 'spec/integration/indexes_spec.rb'
82
- - 'spec/integration/references_spec.rb'
83
- - 'spec/integration/tables_spec.rb'
84
- - 'spec/integration_spec.rb'
85
- - 'spec/lhm_integration_spec.rb'
86
-
87
- # Offense count: 2
88
- # This cop supports safe autocorrection (--autocorrect).
89
- Lint/RedundantCopDisableDirective:
90
- Exclude:
91
- - 'lib/active_record/connection_adapters/percona_adapter.rb'
92
- - 'lib/departure/command.rb'
93
-
94
- # Offense count: 1
95
- # This cop supports safe autocorrection (--autocorrect).
96
- Lint/SendWithMixinArgument:
97
- Exclude:
98
- - 'spec/spec_helper.rb'
99
-
100
- # Offense count: 2
101
- # This cop supports safe autocorrection (--autocorrect).
102
- # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
103
- Lint/UnusedMethodArgument:
104
- Exclude:
105
- - 'lib/active_record/connection_adapters/for_alter.rb'
106
- - 'spec/spec_helper.rb'
107
-
108
- # Offense count: 1
109
- # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
110
- # AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
111
- Naming/MethodParameterName:
112
- Exclude:
113
- - 'lib/active_record/connection_adapters/percona_adapter.rb'
114
-
115
- # Offense count: 1
116
- # This cop supports unsafe autocorrection (--autocorrect-all).
117
- Security/YAMLLoad:
118
- Exclude:
119
- - 'configuration.rb'
120
-
121
- # Offense count: 1
122
- # This cop supports unsafe autocorrection (--autocorrect-all).
123
- # Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
124
- # SupportedStyles: inline, group
125
- Style/AccessModifierDeclarations:
126
- Exclude:
127
- - 'lib/departure/migration.rb'
128
-
129
- # Offense count: 1
130
- # This cop supports safe autocorrection (--autocorrect).
131
- # Configuration parameters: EnforcedStyle.
132
- # SupportedStyles: compact, expanded
133
- Style/EmptyMethod:
134
- Exclude:
135
- - 'spec/fixtures/migrate/0029_disable_departure.rb'
136
-
137
- # Offense count: 1
138
- # This cop supports safe autocorrection (--autocorrect).
139
- Style/Encoding:
140
- Exclude:
141
- - 'departure.gemspec'
142
-
143
- # Offense count: 4
144
- # This cop supports safe autocorrection (--autocorrect).
145
- Style/ExpandPathArguments:
146
- Exclude:
147
- - 'departure.gemspec'
148
- - 'spec/lhm_integration_spec.rb'
149
- - 'spec/spec_helper.rb'
150
-
151
- # Offense count: 2
152
- # This cop supports unsafe autocorrection (--autocorrect-all).
153
- Style/GlobalStdStream:
154
- Exclude:
155
- - 'lib/active_record/connection_adapters/for_alter.rb'
156
- - 'spec/spec_helper.rb'
157
-
158
- # Offense count: 2
159
- # This cop supports safe autocorrection (--autocorrect).
160
- Style/IfUnlessModifier:
161
- Exclude:
162
- - 'lib/active_record/connection_adapters/percona_adapter.rb'
163
- - 'lib/departure/connection_details.rb'
164
-
165
- # Offense count: 1
166
- # This cop supports unsafe autocorrection (--autocorrect-all).
167
- # Configuration parameters: EnforcedStyle.
168
- # SupportedStyles: literals, strict
169
- Style/MutableConstant:
170
- Exclude:
171
- - 'lib/departure/alter_argument.rb'
172
-
173
- # Offense count: 2
174
- # Configuration parameters: AllowedMethods.
175
- # AllowedMethods: respond_to_missing?
176
- Style/OptionalBooleanParameter:
177
- Exclude:
178
- - 'lib/departure/logger.rb'
179
- - 'lib/departure/null_logger.rb'
180
-
181
- # Offense count: 1
182
- # This cop supports safe autocorrection (--autocorrect).
183
- Style/RedundantConditional:
184
- Exclude:
185
- - 'lib/lhm/column_with_sql.rb'
186
-
187
- # Offense count: 1
188
- # This cop supports unsafe autocorrection (--autocorrect-all).
189
- Style/RedundantInterpolation:
190
- Exclude:
191
- - 'spec/active_record/connection_adapters/percona_adapter_spec.rb'
192
-
193
- # Offense count: 1
194
- # This cop supports safe autocorrection (--autocorrect).
195
- Style/RedundantRegexpCharacterClass:
196
- Exclude:
197
- - 'lib/departure/alter_argument.rb'
198
-
199
- # Offense count: 1
200
- # This cop supports safe autocorrection (--autocorrect).
201
- Style/StderrPuts:
202
- Exclude:
203
- - 'lib/active_record/connection_adapters/for_alter.rb'
204
-
205
- # Offense count: 1
206
- # This cop supports unsafe autocorrection (--autocorrect-all).
207
- # Configuration parameters: Mode.
208
- Style/StringConcatenation:
209
- Exclude:
210
- - 'lib/departure/dsn.rb'
211
-
212
- # Offense count: 12
213
- # This cop supports safe autocorrection (--autocorrect).
214
- # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
215
- # SupportedStyles: single_quotes, double_quotes
216
- Style/StringLiterals:
217
- Exclude:
218
- - 'spec/active_record/connection_adapters/percona_adapter_spec.rb'
219
- - 'spec/fixtures/migrate/0030_data_migration_with_upsert_all.rb'
220
- - 'spec/integration/data_migrations_spec.rb'
221
- - 'spec/integration/foreign_keys_spec.rb'
222
- - 'spec/lhm/column_with_sql_spec.rb'
223
-
224
- # Offense count: 1
225
- # This cop supports safe autocorrection (--autocorrect).
226
- # Configuration parameters: EnforcedStyleForMultiline.
227
- # SupportedStylesForMultiline: comma, consistent_comma, no_comma
228
- Style/TrailingCommaInArguments:
229
- Exclude:
230
- - 'spec/departure/runner_spec.rb'
231
-
232
- # Offense count: 1
233
- # This cop supports safe autocorrection (--autocorrect).
234
- # Configuration parameters: EnforcedStyleForMultiline.
235
- # SupportedStylesForMultiline: comma, consistent_comma, no_comma
236
- Style/TrailingCommaInArrayLiteral:
237
- Exclude:
238
- - 'spec/integration/data_migrations_spec.rb'
@@ -1,64 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module Rails81AdapterBehavior
4
- class SchemaCreation < ActiveRecord::ConnectionAdapters::MySQL::SchemaCreation
5
- def visit_DropForeignKey(name) # rubocop:disable Naming/MethodName
6
- fk_name =
7
- if name =~ /^__(.+)/
8
- Regexp.last_match(1)
9
- else
10
- "_#{name}"
11
- end
12
-
13
- "DROP FOREIGN KEY #{fk_name}"
14
- end
15
- end
16
-
17
- def self.included(adapter_class)
18
- adapter_class.const_set(:SchemaCreation, SchemaCreation)
19
- adapter_class.extend(ClassMethods)
20
- adapter_class.include ForAlterStatements unless adapter_class.method_defined?(:change_column_for_alter)
21
- end
22
-
23
- module ClassMethods
24
- def new_client(config)
25
- original_client = super
26
-
27
- Departure::DbClient.new(config, original_client)
28
- end
29
- end
30
-
31
- # add_index is modified from the underlying mysql adapter implementation to ensure we add ALTER TABLE to it
32
- def add_index(table_name, column_name, options = {})
33
- index_definition, = add_index_options(table_name, column_name, **options)
34
- execute <<-SQL.squish
35
- ALTER TABLE #{quote_table_name(index_definition.table)}
36
- ADD #{schema_creation.accept(index_definition)}
37
- SQL
38
- end
39
-
40
- # remove_index is modified from the underlying mysql adapter implementation to ensure we add ALTER TABLE to it
41
- def remove_index(table_name, column_name = nil, **options)
42
- return if options[:if_exists] && !index_exists?(table_name, column_name, **options)
43
-
44
- index_name = index_name_for_remove(table_name, column_name, options)
45
-
46
- execute "ALTER TABLE #{quote_table_name(table_name)} DROP INDEX #{quote_column_name(index_name)}"
47
- end
48
-
49
- def schema_creation
50
- self.class::SchemaCreation.new(self)
51
- end
52
-
53
- private
54
-
55
- # rubocop:disable Metrics/ParameterLists
56
- def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch: false)
57
- return raw_connection.send_to_pt_online_schema_change(sql) if raw_connection.alter_statement?(sql)
58
-
59
- super
60
- end
61
- # rubocop:enable Metrics/ParameterLists
62
- end
63
- end
64
- end