Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby: ['3.2', '3.3', '3.4', 'head']
ruby: ['3.2', '3.3', '3.4', '4.0']

steps:
- uses: actions/checkout@v4
Expand Down
19 changes: 12 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ GEM
net-smtp
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.25.5)
minitest (6.0.1)
prism (~> 1.5)
net-imap (0.5.10)
date
net-protocol
Expand All @@ -137,9 +138,11 @@ GEM
net-smtp (0.5.1)
net-protocol
nio4r (2.7.4)
nokogiri (1.18.10-x86_64-darwin)
nokogiri (1.19.0-arm64-darwin)
racc (~> 1.4)
nokogiri (1.18.10-x86_64-linux-gnu)
nokogiri (1.19.0-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.19.0-x86_64-linux-gnu)
racc (~> 1.4)
parallel (1.27.0)
parser (3.3.9.0)
Expand All @@ -148,7 +151,7 @@ GEM
pp (0.6.2)
prettyprint
prettyprint (0.2.0)
prism (1.4.0)
prism (1.9.0)
psych (5.2.6)
date
stringio
Expand Down Expand Up @@ -237,8 +240,9 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
sqlite3 (2.7.3-x86_64-darwin)
sqlite3 (2.7.3-x86_64-linux-gnu)
sqlite3 (2.9.0-arm64-darwin)
sqlite3 (2.9.0-x86_64-darwin)
sqlite3 (2.9.0-x86_64-linux-gnu)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
Expand All @@ -252,7 +256,7 @@ GEM
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.5)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
unicode-emoji (4.2.0)
useragent (0.16.11)
websocket-driver (0.8.0)
base64
Expand All @@ -261,6 +265,7 @@ GEM
zeitwerk (2.7.3)

PLATFORMS
arm64-darwin-25
x86_64-darwin-24
x86_64-linux

Expand Down
20 changes: 11 additions & 9 deletions lib/data_customs/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ class Migration
DEFAULT_BATCH_SIZE = 1000
DEFAULT_THROTTLE = 0.01

def self.run(...) = new(...).run
def self.run(...)
ActiveRecord::Base.transaction do
new(...).run
end
rescue => e
warn "🛃 Data migration failed"
raise e
end

def up = raise NotImplementedError
def verify! = raise NotImplementedError

def run
ActiveRecord::Base.transaction do
up
verify!
puts "🛃 Data migration ran successfully!"
rescue => e
warn "🛃 Data migration failed"
raise e
end
up
verify!
puts "🛃 Data migration ran successfully!"
end

private
Expand Down
2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
ruby = "3.4.8"
15 changes: 15 additions & 0 deletions spec/data_customs/migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ def verify! = raise "Should not reach this"
.and raise_error("Kaboom")
end

it "rolls back db operations in initialize if up fails" do
migration = Class.new(DataCustoms::Migration) do
def initialize
TestUser.create!(name: "Created in initialize")
end

def up = raise "Kaboom"
def verify! = nil
end

expect { migration.run }
.to raise_error("Kaboom")
.and change { TestUser.count }.by(0)
end

describe "helpers" do
it "batches records" do
3.times { |i| TestUser.create!(name: "User #{i}") }
Expand Down