Module: ActiveRecordShards::ActualMigrationExtension

Defined in:
lib/active_record_shards/migration.rb

Overview

ok, so some ‘splaining to do. Rails 3.1 puts the migrate() method on the instance of the migration, where it should have been. But this makes our monkey patch incompatible. So we’re forced to either include or extend this.

Instance Method Summary collapse

Instance Method Details

#migrate_with_forced_shard(direction) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/active_record_shards/migration.rb', line 89

def migrate_with_forced_shard(direction)
  if migration_shard.blank?
    raise "#{name}: Can't run migrations without a shard spec: this may be :all, :none,
             or a specific shard (for data-fixups).  please call shard(arg) in your migration."
  end

  shard = ActiveRecord::Base.current_shard_selection.shard

  if shard.nil?
    return if migration_shard != :none
  else
    return if migration_shard == :none
    return if migration_shard != :all && migration_shard.to_s != shard.to_s
  end

  migrate_without_forced_shard(direction)
end

#migration_shardObject



107
108
109
# File 'lib/active_record_shards/migration.rb', line 107

def migration_shard
  self.class.migration_shard
end