Skip to content
tchandy edited this page Sep 14, 2010 · 6 revisions

Migrations

Octopus allow you to send migrations to specific shards. If you don’t specify what shard to send the migration or Octopus isn’t configured to run in that enviroment, Octopus will send the migration to master database specified in database.yml.

Code Examples:

To send a migration to specific shard:

# This will send the migration to the shard named "canada"
class CreateUsersOnCanada < ActiveRecord::Migration
  using(:canada)

  def self.up
    User.create!(:name => "Sharding")
  end

  def self.down
    User.delete_all()
  end
end

To send a migration to multiple shards:

# This will send the migration to the shards named "canada" and "brazil"
class CreateUsersOnBothShards < ActiveRecord::Migration
  using(:brazil, :canada)

  def self.up
    User.create!(:name => "Both")
  end

  def self.down
    User.delete_all()
  end
end

To send a migration to a group of shards:

# This will send the migration to the all shards inside "country_shards" group
class CreateUsersOnShardsOfAGroup < ActiveRecord::Migration
  using_group(:country_shards)

  def self.up
    User.create!(:name => "Group")
  end

  def self.down
    User.delete_all()
  end
end

To send a migration to a multiple groups of shards:

# This will send the migration to all shards inside "country_shards" 
# and "history_shards" groups
class CreateUsersOnMultiplesGroups < ActiveRecord::Migration
  using_group(:country_shards, :history_shards)

  def self.up
    User.create!(:name => "MultipleGroup")
  end

  def self.down
    User.delete_all()
  end
end
Clone this wiki locally