Module: Mongoid::Tasks::Database
- Defined in:
- lib/patches/db_commands.rb
Instance Method Summary collapse
- #remove_indexes(models = ::Mongoid.models) ⇒ Object
- #undefined_indexes(models = ::Mongoid.models) ⇒ Object
Instance Method Details
#remove_indexes(models = ::Mongoid.models) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/patches/db_commands.rb', line 107 def remove_indexes(models = ::Mongoid.models) models.each do |model| next if model. begin indexes = model.collection.indexes.map{ |doc| doc["name"] } indexes.delete_one("_id_") model.remove_indexes rescue Moped::Errors::OperationFailure next end logger.info("MONGOID: Removing indexes on: #{model} for: #{indexes.join(', ')}.") model end.compact end |
#undefined_indexes(models = ::Mongoid.models) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/patches/db_commands.rb', line 82 def undefined_indexes(models = ::Mongoid.models) undefined_by_model = {} models.each do |model| unless model. begin model.collection.indexes.each do |index| # ignore default index unless index['name'] == '_id_' key = index['key'].symbolize_keys spec = model.index_specification(key) unless spec # index not specified undefined_by_model[model] ||= [] undefined_by_model[model] << index end end end rescue Moped::Errors::OperationFailure; end end end undefined_by_model end |