Last active
March 5, 2019 17:11
-
-
Save JamesPaden/64f424697e01f8f4fbfa2bb6eb07a240 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
module ActiveMigrator | |
class ActiveMigratorDestinationModel < ActiveRecord::Base | |
self.abstract_class = true | |
# disable STI for this "copy" model | |
self.inheritance_column = :_type_disabled | |
establish_connection DB_ACTIVE_MIGRATOR_CONFIGURATION[:destination] | |
end | |
end | |
module ActiveMigrator | |
module ActiveMigratorSource | |
extend ActiveSupport::Concern | |
included do | |
@active_migrator_destination_klass_name = "ActiveMigrator::#{self.name}ActiveMigratorDestinationModel" | |
eval <<-STR, nil, __FILE__, __LINE__ | |
ActiveMigrator.send(:remove_const, :#{self.name}ActiveMigratorDestinationModel) if defined?(#{@active_migrator_destination_klass_name}) | |
class #{@active_migrator_destination_klass_name} < ActiveMigrator::ActiveMigratorDestinationModel | |
self.table_name = '#{table_name}' | |
self.record_timestamps = false | |
self.lock_optimistically = false | |
end | |
STR | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment