Skip to content

Commit

Permalink
Fixing issue described in GH thiagopradi#407
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagopradi committed Nov 5, 2017
1 parent ca88043 commit b3e5009
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/octopus/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class << self

alias_method :run_without_octopus, :run
alias_method :run, :run_with_octopus

alias_method :rollback_without_octopus, :rollback
alias_method :rollback, :rollback_with_octopus
end
end

Expand Down Expand Up @@ -145,6 +148,14 @@ def run_with_octopus(direction, migrations_paths, target_version)
end
end

def rollback_with_octopus(migrations_paths, steps = 1)
return rollback_without_octopus(migrations_paths, steps) unless connection.is_a?(Octopus::Proxy)

connection.send_queries_to_multiple_shards(connection.shard_names) do
rollback_without_octopus(migrations_paths, steps)
end
end

private

def connection
Expand Down
19 changes: 19 additions & 0 deletions spec/octopus/migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@
end
end

it "should rollback correctly migrations" do
migrations_root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'migrations'))

ActiveRecord::Migrator.run(:up, migrations_root, 4)

expect(User.using(:canada).find_by_name('Group')).not_to be_nil
expect(User.using(:brazil).find_by_name('Group')).not_to be_nil
expect(User.using(:russia).find_by_name('Group')).not_to be_nil


Octopus.using(:canada) do
ActiveRecord::Migrator.rollback(migrations_root, 4)
end

expect(User.using(:canada).find_by_name('Group')).to be_nil
expect(User.using(:brazil).find_by_name('Group')).to be_nil
expect(User.using(:russia).find_by_name('Group')).to be_nil
end

it 'should run once per shard' do
OctopusHelper.migrating_to_version 5 do
expect(User.using(:canada).where(:name => 'MultipleGroup').size).to eq(1)
Expand Down

0 comments on commit b3e5009

Please sign in to comment.