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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/patches/db_commands.rb', line 134 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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/patches/db_commands.rb', line 109 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 |