Class: ActiveRecord::Migrator
- Inherits:
-
Object
- Object
- ActiveRecord::Migrator
- Defined in:
- lib/active_record_shards/migration.rb
Class Method Summary collapse
-
.shard_status(versions) ⇒ Object
public list of pending and missing versions per shard [=> [1234567], => [2345678]].
Instance Method Summary collapse
Class Method Details
.shard_status(versions) ⇒ Object
public list of pending and missing versions per shard
- => [1234567], => [2345678]
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_record_shards/migration.rb', line 36 def self.shard_status(versions) pending = {} missing = {} collect = lambda do |shard| migrated = get_all_versions p = versions - migrated pending[shard] = p if p.any? m = migrated - versions missing[shard] = m if m.any? end ActiveRecord::Base.on_shard(nil) { collect.call(nil) } ActiveRecord::Base.on_all_shards { |shard| collect.call(shard) } [pending, missing] end |
Instance Method Details
#migrated ⇒ Object
21 22 23 |
# File 'lib/active_record_shards/migration.rb', line 21 def migrated self.class.get_all_versions end |
#pending_migrations ⇒ Object
27 28 29 30 31 |
# File 'lib/active_record_shards/migration.rb', line 27 def pending_migrations pending, _missing = self.class.shard_status(migrations.map(&:version)) pending = pending.values.flatten migrations.select { |m| pending.include?(m.version) } end |