diff --git a/CHANGELOG.md b/CHANGELOG.md index 6423874f..034ea0b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Unreleased +# 4.5.1 (Jul, 2025) +* Create update before insert trigger + # 4.5.0 (Feb, 2025) * Update test matrix to include Rails 8 * Add option to force tables to use default engine diff --git a/Gemfile.lock b/Gemfile.lock index d0e9614a..6e8cd32b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lhm-shopify (4.5.0) + lhm-shopify (4.5.1) retriable (>= 3.0.0) GEM diff --git a/gemfiles/activerecord_7.2.gemfile.lock b/gemfiles/activerecord_7.2.gemfile.lock index c294b970..addbd25e 100644 --- a/gemfiles/activerecord_7.2.gemfile.lock +++ b/gemfiles/activerecord_7.2.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - lhm-shopify (4.5.0) + lhm-shopify (4.5.1) retriable (>= 3.0.0) GEM diff --git a/gemfiles/activerecord_8.0.gemfile.lock b/gemfiles/activerecord_8.0.gemfile.lock index f1d04b6e..8217011a 100644 --- a/gemfiles/activerecord_8.0.gemfile.lock +++ b/gemfiles/activerecord_8.0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - lhm-shopify (4.5.0) + lhm-shopify (4.5.1) retriable (>= 3.0.0) GEM diff --git a/gemfiles/activerecord_head.gemfile.lock b/gemfiles/activerecord_head.gemfile.lock index 0a4ac20a..3fb89740 100644 --- a/gemfiles/activerecord_head.gemfile.lock +++ b/gemfiles/activerecord_head.gemfile.lock @@ -26,7 +26,7 @@ GIT PATH remote: .. specs: - lhm-shopify (4.5.0) + lhm-shopify (4.5.1) retriable (>= 3.0.0) GEM diff --git a/lib/lhm/entangler.rb b/lib/lhm/entangler.rb index 60854629..61a6cde1 100644 --- a/lib/lhm/entangler.rb +++ b/lib/lhm/entangler.rb @@ -27,8 +27,8 @@ def initialize(migration, connection = nil) def entangle [ create_delete_trigger, + create_update_trigger, create_insert_trigger, - create_update_trigger ] end diff --git a/lib/lhm/version.rb b/lib/lhm/version.rb index 689fa412..850d0334 100644 --- a/lib/lhm/version.rb +++ b/lib/lhm/version.rb @@ -2,5 +2,5 @@ # Schmidt module Lhm - VERSION = '4.5.0' + VERSION = '4.5.1' end diff --git a/spec/unit/entangler_spec.rb b/spec/unit/entangler_spec.rb index 1b08d74b..6d3fd6ac 100644 --- a/spec/unit/entangler_spec.rb +++ b/spec/unit/entangler_spec.rb @@ -27,18 +27,18 @@ @destination.columns['tags'] = { :type => 'varchar(255)' } end - it 'should create insert trigger to destination table' do + it 'should create the delete trigger to the destination table first' do ddl = %Q{ - create trigger `lhmt_ins_origin` - after insert on `origin` for each row - replace into `destination` (`info`, `tags`) /* large hadron migration */ - values (`NEW`.`info`, `NEW`.`tags`) + create trigger `lhmt_del_origin` + after delete on `origin` for each row + delete ignore from `destination` /* large hadron migration */ + where `destination`.`id` = OLD.`id` } - value(@entangler.entangle).must_include strip(ddl) + assert_equal strip(ddl), @entangler.entangle[0] end - it 'should create an update trigger to the destination table' do + it 'should create the update trigger to the destination table second' do ddl = %Q{ create trigger `lhmt_upd_origin` after update on `origin` for each row @@ -46,18 +46,18 @@ values (`NEW`.`info`, `NEW`.`tags`) } - value(@entangler.entangle).must_include strip(ddl) + assert_equal strip(ddl), @entangler.entangle[1] end - it 'should create a delete trigger to the destination table' do + it 'should create the insert trigger to destination table last' do ddl = %Q{ - create trigger `lhmt_del_origin` - after delete on `origin` for each row - delete ignore from `destination` /* large hadron migration */ - where `destination`.`id` = OLD.`id` + create trigger `lhmt_ins_origin` + after insert on `origin` for each row + replace into `destination` (`info`, `tags`) /* large hadron migration */ + values (`NEW`.`info`, `NEW`.`tags`) } - value(@entangler.entangle).must_include strip(ddl) + assert_equal strip(ddl), @entangler.entangle[2] end it 'should retry trigger creation when it hits a lock wait timeout' do