vitess-activerecord-migration 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4e6886e3311d81a26675589df0420f5e4ea72ef3f5b7a4288029ef2feb4542f
4
- data.tar.gz: 407235b276dc0f370663348491e03e2cfa6a2ae7b108c67fbd3f66967162561e
3
+ metadata.gz: ccf02af6a599148167a09bb0281fcb891663bf455b280c74bcd0f344d15b0008
4
+ data.tar.gz: 6fbd1977dd22de177572f0de28dbbd80824b445361c62f0d2f1f7741c8b884ba
5
5
  SHA512:
6
- metadata.gz: d867e55428ac7f48b5a87c34faece5d2de9deab0aa63779b759917e52becb7361cd2c13e8cafb2765008238df62c910392843aa1e2da8795a27c41f97d03820b
7
- data.tar.gz: 115075f6113b7b0cf64d2a52b2148048271130c7ded01cdb6ef2367c25b9307b047f3c9ab5990b386f88d9829a816cd765da17d2c318ed99e3e1c97ba385b675
6
+ metadata.gz: a02873ccab767abf06dc40277d4f75dd169449d43d1e3b40b08c15ddc099efd89edab6016af640379842c92e1d999e1e112c21a97107eda80b5c0858077f9116
7
+ data.tar.gz: 42336d57e7c0e870a2dae788ab66ed56858683738df9b76094ce87c8df8b09d8844fc878a9679028a9b1de3cc68dde3b37e890b96a5455ef04d56f06f36c9c02
data/.env CHANGED
@@ -1,3 +1,3 @@
1
1
  RUBY_VERSION=${RUBY_VERSION:-3.2}
2
2
  RAILS_VERSION=${RAILS_VERSION:-~> 7.2.0}
3
- VITESS_VERSION=${VITESS_VERSION:-20.0}
3
+ VITESS_VERSION=${VITESS_VERSION:-21.0}
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2025-08-30
4
+
5
+ - **BREAKING**: Drop Rails 6.1 support, require ActiveRecord >= 7.0 (#7)
6
+ - **BREAKING**: Raise errors on failed/cancelled/timed-out migrations (#5)
7
+
3
8
  ## [0.1.0] - 2024-09-02
4
9
 
5
10
  - Initial release
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Vitess::Activerecord::Migration
2
2
 
3
+ [![Ruby](https://github.com/yoheimuta/vitess-activerecord-migration/actions/workflows/main.yml/badge.svg)](https://github.com/yoheimuta/vitess-activerecord-migration/actions/workflows/main.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/vitess-activerecord-migration.svg)](https://badge.fury.io/rb/vitess-activerecord-migration)
5
+ [![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/yoheimuta/protolint/blob/master/LICENSE)
6
+
3
7
  vitess-activerecord-migration is a gem for integrating Vitess with ActiveRecord migrations.
4
8
 
5
9
  Vitess::Activerecord::Migration provides tools to integrate Vitess with ActiveRecord migrations,
@@ -3,7 +3,7 @@
3
3
  module Vitess
4
4
  module Activerecord
5
5
  module Migration
6
- VERSION = "0.2.0"
6
+ VERSION = "0.3.0"
7
7
  end
8
8
  end
9
9
  end
@@ -7,6 +7,9 @@ module Vitess
7
7
  module Activerecord
8
8
  module Migration
9
9
  class Error < StandardError; end
10
+ class Failed < Error; end
11
+ class Cancelled < Error; end
12
+ class TimedOut < Error; end
10
13
 
11
14
  # Returns the default DDL strategy.
12
15
  # This method is called and set before executing the change, up, or down methods.
@@ -17,13 +20,24 @@ module Vitess
17
20
  end
18
21
 
19
22
  # Returns the timeout seconds for waiting for the completion of the DDL statement.
20
- # Even after the timeout, the migration on Vitess will not be stopped, but a warning will be logged.
23
+ # If the DDL exceeds the timeout:
24
+ #
25
+ # * A warning will be logged.
26
+ # * An error will be raised and halt the Rails migration if `raise_on_timeout` is `true`.
27
+ # * The Vitess migration will continue.
21
28
  #
22
29
  # Override this method if you want to change the default timeout.
23
30
  def wait_timeout_seconds
24
31
  7200 # 120 minutes
25
32
  end
26
33
 
34
+ # Returns whether an error will be raised when the DDL statement exceeds wait_timeout_seconds.
35
+ #
36
+ # Override this method if you want to change how timeouts are handled.
37
+ def raise_on_timeout
38
+ true
39
+ end
40
+
27
41
  # Returns the columns of SHOW VITESS_MIGRATIONS to log during the run.
28
42
  #
29
43
  # Override this method if you want to change the default columns.
@@ -114,7 +128,18 @@ module Vitess
114
128
  @stopped_uuid ||= []
115
129
 
116
130
  loop do
131
+ # A Rails migration will create a separate Vitess migration for each DDL submitted by Rails.
132
+ # Each Rails migration has a unique version and this is used to group the resulting Vitess migrations using the `migration_context` field.
133
+ # Vitess records the DDL submitted by Rails in the `migration_statement` column.
134
+ # If the Rails migration fails and is later retried, Vitess will create additional Vitess migrations with the same `migration_context` from the previous attempt.
135
+ # Vitess will immediately mark "duplicate" DDLs that were previously successful as complete.
136
+ # Vitess will retry "duplicate" DDLs that were previously unsuccessful.
137
+ # The overall Rails migration status is determined by the `migration_status` of the last Vitess migration of each DDL.
138
+ # For details on Vitess duplicate migration detection, see:
139
+ # https://vitess.io/docs/22.0/user-guides/schema-changes/advanced-usage/
117
140
  migrations = ActiveRecord::Base.connection.select_all("SHOW VITESS_MIGRATIONS LIKE '#{@migration_context}'")
141
+ .group_by { |migration| migration['migration_statement'] }
142
+ .map { |_, migrations| migrations.last }
118
143
 
119
144
  migrations.each do |migration|
120
145
  id = migration["id"]
@@ -130,8 +155,10 @@ module Vitess
130
155
  Rails.logger.info("Vitess Migration #{id} completed successfully at #{migration["completed_timestamp"]}")
131
156
  when "failed"
132
157
  Rails.logger.error("Vitess Migration #{id} failed: #{migration["message"]} at #{migration["completed_timestamp"]}")
158
+ raise Failed, "Vitess Migration #{id} failed: #{migration["message"]}"
133
159
  when "cancelled"
134
160
  Rails.logger.warn("Vitess Migration #{id} was cancelled at #{migration["cancelled_timestamp"]}")
161
+ raise Cancelled, "Vitess Migration #{id} was cancelled: #{migration["message"]}"
135
162
  end
136
163
  @stopped_uuid << id
137
164
  else
@@ -146,6 +173,7 @@ module Vitess
146
173
 
147
174
  if Time.now - start_time > timeout_seconds
148
175
  Rails.logger.warn("Vitess Migration did not complete within #{timeout_seconds} seconds. Timing out.")
176
+ raise TimedOut, "Vitess Migration did not complete within #{timeout_seconds} seconds."
149
177
  break
150
178
  end
151
179
 
@@ -154,6 +182,8 @@ module Vitess
154
182
  interval_seconds = [interval_seconds * 2, max_interval_seconds].min
155
183
  end
156
184
  rescue => e
185
+ raise e if [Failed, Cancelled].include?(e.class)
186
+ raise e if e.class == TimedOut && raise_on_timeout
157
187
  Rails.logger.error("An error occurred while waiting for Vitess DDL: #{e.message}")
158
188
  Rails.logger.error(e.backtrace.join("\n"))
159
189
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitess-activerecord-migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yohei Yoshimuta
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-15 00:00:00.000000000 Z
11
+ date: 2025-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '8.1'
19
+ version: '7.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: '6'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '8.1'
26
+ version: '7.0'
33
27
  description: Vitess::Activerecord::Migration provides tools to integrate Vitess with
34
28
  ActiveRecord migrations, allowing for seamless database schema changes in a Vitess
35
29
  environment.
@@ -57,7 +51,6 @@ files:
57
51
  - sig/rails_support.rbs
58
52
  - sig/vitess/activerecord/migration.rbs
59
53
  - tmp/.keep
60
- - vitess-activerecord-migration.gemspec
61
54
  homepage: https://github.com/yoheimuta/vitess-activerecord-migration
62
55
  licenses:
63
56
  - MIT
@@ -66,7 +59,7 @@ metadata:
66
59
  homepage_uri: https://github.com/yoheimuta/vitess-activerecord-migration
67
60
  source_code_uri: https://github.com/yoheimuta/vitess-activerecord-migration
68
61
  changelog_uri: https://github.com/yoheimuta/vitess-activerecord-migration/blob/main/CHANGELOG.md
69
- post_install_message:
62
+ post_install_message:
70
63
  rdoc_options: []
71
64
  require_paths:
72
65
  - lib
@@ -81,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
74
  - !ruby/object:Gem::Version
82
75
  version: '0'
83
76
  requirements: []
84
- rubygems_version: 3.0.3.1
85
- signing_key:
77
+ rubygems_version: 3.4.10
78
+ signing_key:
86
79
  specification_version: 4
87
80
  summary: A gem for integrating Vitess with ActiveRecord migrations.
88
81
  test_files: []
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/vitess/activerecord/migration/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "vitess-activerecord-migration"
7
- spec.version = Vitess::Activerecord::Migration::VERSION
8
- spec.authors = ["Yohei Yoshimuta"]
9
- spec.email = ["yoheimuta@gmail.com"]
10
-
11
- spec.summary = "A gem for integrating Vitess with ActiveRecord migrations."
12
- spec.description = "Vitess::Activerecord::Migration provides tools to integrate Vitess with ActiveRecord migrations, allowing for seamless database schema changes in a Vitess environment."
13
- spec.homepage = "https://github.com/yoheimuta/vitess-activerecord-migration"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.7.0"
16
-
17
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
-
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/yoheimuta/vitess-activerecord-migration"
21
- spec.metadata["changelog_uri"] = "https://github.com/yoheimuta/vitess-activerecord-migration/blob/main/CHANGELOG.md"
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(__dir__) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (File.expand_path(f) == __FILE__) ||
28
- f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
29
- end
30
- end
31
- spec.bindir = "exe"
32
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
- spec.require_paths = ["lib"]
34
-
35
- # Uncomment to register a new dependency of your gem
36
- spec.add_dependency "activerecord", ">= 6", "< 8.1"
37
-
38
- # For more information and examples about making a new gem, check out our
39
- # guide at: https://bundler.io/guides/creating_gem.html
40
- end