departure 8.0.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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +41 -2
  3. data/.pryrc +6 -6
  4. data/.standard.yml +9 -0
  5. data/AGENTS.md +77 -0
  6. data/Appraisals +11 -8
  7. data/CHANGELOG.md +16 -0
  8. data/Gemfile +8 -9
  9. data/Gemfile.lock +25 -11
  10. data/README.md +26 -4
  11. data/RELEASING.md +5 -4
  12. data/Rakefile +10 -10
  13. data/configuration.rb +3 -3
  14. data/departure.gemspec +26 -29
  15. data/gemfiles/rails_7_2.gemfile +2 -2
  16. data/gemfiles/rails_7_2.gemfile.lock +28 -11
  17. data/gemfiles/rails_8_0.gemfile +2 -2
  18. data/gemfiles/rails_8_0.gemfile.lock +28 -11
  19. data/gemfiles/rails_8_1.gemfile +3 -3
  20. data/gemfiles/rails_8_1.gemfile.lock +27 -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 -10
  23. data/lib/active_record/connection_adapters/patch_connection_handling.rb +7 -6
  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 +23 -0
  29. data/lib/active_record/connection_adapters/rails_8_1_trilogy_adapter.rb +21 -0
  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/migration.rb +40 -10
  41. data/lib/departure/option.rb +4 -4
  42. data/lib/departure/rails_adapter.rb +145 -85
  43. data/lib/departure/rails_patches/active_record_migrator_with_advisory_lock_patch.rb +2 -2
  44. data/lib/departure/railtie.rb +7 -5
  45. data/lib/departure/runner.rb +3 -3
  46. data/lib/departure/user_options.rb +1 -1
  47. data/lib/departure/version.rb +1 -1
  48. data/lib/departure.rb +21 -23
  49. data/lib/lhm/adapter.rb +12 -12
  50. data/lib/lhm/column_with_sql.rb +8 -8
  51. data/lib/lhm.rb +1 -1
  52. data/test_database.rb +10 -10
  53. metadata +12 -4
  54. data/.rubocop.yml +0 -66
  55. data/.rubocop_todo.yml +0 -238
  56. data/lib/active_record/connection_adapters/rails_8_1_departure_adapter.rb +0 -83
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,83 +0,0 @@
1
- require 'active_record/connection_adapters/abstract_mysql_adapter'
2
- require 'active_record/connection_adapters/mysql2_adapter'
3
- require 'active_record/connection_adapters/patch_connection_handling'
4
- require 'departure'
5
- require 'forwardable'
6
-
7
- module ActiveRecord
8
- module ConnectionAdapters
9
- class Rails81DepartureAdapter < ActiveRecord::ConnectionAdapters::Mysql2Adapter
10
- TYPE_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) } if defined?(initialize_type_map)
11
-
12
- class Column < ActiveRecord::ConnectionAdapters::MySQL::Column
13
- def adapter
14
- Rails81DepartureAdapter
15
- end
16
- end
17
-
18
- # https://github.com/departurerb/departure/commit/f178ca26cd3befa1c68301d3b57810f8cdcff9eb
19
- # For `DROP FOREIGN KEY constraint_name` with pt-online-schema-change requires specifying `_constraint_name`
20
- # rather than the real constraint_name due to to a limitation in MySQL
21
- # pt-online-schema-change adds a leading underscore to foreign key constraint names when creating the new table.
22
- # https://www.percona.com/blog/2017/03/21/dropping-foreign-key-constraint-using-pt-online-schema-change-2/
23
- class SchemaCreation < ActiveRecord::ConnectionAdapters::MySQL::SchemaCreation
24
- def visit_DropForeignKey(name) # rubocop:disable Naming/MethodName
25
- fk_name =
26
- if name =~ /^__(.+)/
27
- Regexp.last_match(1)
28
- else
29
- "_#{name}"
30
- end
31
-
32
- "DROP FOREIGN KEY #{fk_name}"
33
- end
34
- end
35
-
36
- extend Forwardable
37
-
38
- include ForAlterStatements unless method_defined?(:change_column_for_alter)
39
-
40
- ADAPTER_NAME = 'Percona'.freeze
41
-
42
- def self.new_client(config)
43
- original_client = super
44
-
45
- Departure::DbClient.new(config, original_client)
46
- end
47
-
48
- # add_index is modified from the underlying mysql adapter implementation to ensure we add ALTER TABLE to it
49
- def add_index(table_name, column_name, options = {})
50
- index_definition, = add_index_options(table_name, column_name, **options)
51
- execute <<-SQL.squish
52
- ALTER TABLE #{quote_table_name(index_definition.table)}
53
- ADD #{schema_creation.accept(index_definition)}
54
- SQL
55
- end
56
-
57
- # remove_index is modified from the underlying mysql adapter implementation to ensure we add ALTER TABLE to it
58
- def remove_index(table_name, column_name = nil, **options)
59
- return if options[:if_exists] && !index_exists?(table_name, column_name, **options)
60
-
61
- index_name = index_name_for_remove(table_name, column_name, options)
62
-
63
- execute "ALTER TABLE #{quote_table_name(table_name)} DROP INDEX #{quote_column_name(index_name)}"
64
- end
65
-
66
- def schema_creation
67
- SchemaCreation.new(self)
68
- end
69
-
70
- private
71
-
72
- attr_reader :mysql_adapter
73
-
74
- # rubocop:disable Metrics/ParameterLists
75
- def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch: false)
76
- return raw_connection.send_to_pt_online_schema_change(sql) if raw_connection.alter_statement?(sql)
77
-
78
- super
79
- end
80
- # rubocop:enable Metrics/ParameterLists
81
- end
82
- end
83
- end