-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 5.0.0
-
Component/s: None
-
None
As a recent errbit user discovered (https://github.com/errbit/errbit/issues/994), running rake db:mongoid:remove_undefined_indexes removes full text indexes when they are defined.
You can reproduce this issue with the following steps:
1. check out errbit: https://github.com/errbit/errbit/commit/d168395807ea897bd48efcc8ee68fb01789073a3
2. Follow the installation instructions https://github.com/errbit/errbit#installation
3. Run rake db:mongoid:create_indexes
4. Run rake db:mongoid:remove_undefined_indexes
Notice how the full text index on the Problem model is always removed even though it is defined.
After a bit of debugging, I can see that Mongoid is expecting they keys for Problem.index_specifications to match the keys in Problem.collection.indexes, but only the regular indexes match and the full text index does not:
~~~
[11] pry(Problem)> Problem.index_specifications.map
=> [{:app_id=>1},
{:app_name=>1},
{:message=>1},
{:last_notice_at=>1},
{:first_notice_at=>1},
{:last_deploy_at=>1},
{:resolved_at=>1},
{:notices_count=>1},
{:error_class=>"text",
:where=>"text",
:message=>"text",
:app_name=>"text",
:environment=>"text"}]
[12] pry(Problem)> Problem.collection.indexes.map
=> [{:_id=>1},
{:app_id=>1},
{:app_name=>1},
{:message=>1},
{:last_notice_at=>1},
{:first_notice_at=>1},
{:last_deploy_at=>1},
{:resolved_at=>1},
{:notices_count=>1},
{:_fts=>"text", :_ftsx=>1}]
~~~
Because the index key for the text index doesn't match the specification, the text in this rake task fails: https://github.com/mongodb/mongoid/blob/master/lib/mongoid/tasks/database.rb#L51 and the index is dropped when it should not be dropped.