Skip to content

Commit

Permalink
Add a patch to ActiveRecord::Migration
Browse files Browse the repository at this point in the history
This patch does two things.

1. It adds migration versions to MiqRegion#ran_migrations as they
   are completed
2. It halts the global region migration process if the changes from
   the same migration in all the remote regions have not been replicated

This combination will allow us to ensure that the global region will
never attempt to replicate data which would be inconsistent with the
current schema.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1601015
  • Loading branch information
carbonin committed Aug 28, 2018
1 parent 8ce9565 commit 1a35421
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/extensions/ar_pglogical_migration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module ArPglogicalMigration
def migrate(direction)
PglogicalSubscription.all.each do |s|
provider_region = MiqRegion.find(s.provider_region)

while !provider_region.migrations_ran.include?(version) do
s.disable
s.enable
sleep 1
provider_region.reload
end
end

super(direction)

r = MiqRegion.my_region
if r.respond_to?(:migrations_ran=)
new_migrations = ActiveRecord::SchemaMigration.normalized_versions
new_migrations << version if direction == :up

r.migrations_ran = new_migrations
r.save
end
end
end

ActiveRecord::Migration.prepend(ArPglogicalMigration)

0 comments on commit 1a35421

Please sign in to comment.