Closed ericsaboia closed 11 years ago
I agree that having to clear out old indexes is a problem, but in other databases, modifying the schema (which clearing the unique index is an example of) is not done by the testing framework, but instead by a database migration.
rspec, for example, will clear the contents of the database, but will not modify the schema. That would be up to the database migrations. I think that if you remove a unique index from your code, you should be responsible for removing it via a database migration of some sort, not the testing framework. You're going to need to do that anyway, because you don't run your specs against your production instance.
Consider the following scenario related to yours above, but adding a unique key instead of removing it:
Does that make sense? The more I think about it, the more I am sure that clearing indexes should not be part of clearing the contents of the database.
I think that if you wrote a test for this, you would see the problem. For example, write a test that has a model with a unique index, and test to see if inserting a duplicate record will still fail after the database has been cleared. I am confident that the datastore will be in a bad state.
Nothing is re-adding indexes after they are cleared. Mongoose does that once when it starts.
Yeah, you are right. Sorry about that!
You have no need to apologize! This conversation helped me form a solid opinion about whether or not this should be added. Thank you for contributing!
Note that this is related (or a duplicate) of #5.