Last active
March 5, 2019 17:11
-
-
Save JamesPaden/76d26f7696bbdcee6e4b002930aa7e4a to your computer and use it in GitHub Desktop.
A code example referenced in our blog post: https://medium.com/expected-behavior/our-plan-for-zero-downtime-database-transitions-with-rails-part-2-3cc4c5d6051c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write_active_migrator_destination_model! | |
if ActiveMigrator.config.enabled_checker.call(id) | |
ActiveMigrator.config.metric_incrementer.call("active_migrator.#{active_migrator_source_klass.name}.write_active_migrator_destination_model") | |
original_record = find_original_model | |
if original_record | |
active_migrator_destination_model = original_record.find_active_migrator_destination_model | |
original_record.transformed_attributes_for_active_migrator.each do |name, value| | |
active_migrator_destination_model.send(:write_attribute, name, value) | |
end | |
active_migrator_destination_model.save! | |
else | |
active_migrator_destination_model = find_active_migrator_destination_model | |
active_migrator_destination_model.destroy unless active_migrator_destination_model.new_record? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment