Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non unique indexes for paranoid docs #183

Conversation

tomdmaguire
Copy link

fixes paranoid issue described in #172 (updated for latest version of code)

@leemhenson
Copy link

+1

@digitalplaywright
Copy link
Collaborator

Thanks! This is very interesting. I am wondering if it would be better to factor out the index creation into a concern so that people that use the old index format can still upgrade to new versions without recreating indexes. Thought or ideas on better solutions?

@dblock
Copy link
Collaborator

dblock commented Sep 21, 2015

Bunp @tomdmaguire, care to answer @digitalplaywright's question above? Thanks!

@johnnyshields
Copy link
Member

FYI MongoDB 3.2 will support partial indexes which will make for a better solution here--you can declare unique as long as delete_at does not exist.

http://docs.mongodb.org/manual/release-notes/3.1-dev-series/

@dblock
Copy link
Collaborator

dblock commented Sep 9, 2016

@johnnyshields @tomdmaguire After merging #172 (via #227) I read everything there's to read here and there and I don't understand what the problem is with paranoid documents and the slug index. Can someone explain it to me like a 2 yo and tell me what we should do with this PR? Thanks.

@johnnyshields
Copy link
Member

  • this gem adds a unique DB index on the _slugs field. this means if Doc A has slugs: ["foo"] and I try to create Doc B with slugs: ["foo"], the DB itself will not allow Doc B to be saved.
  • paranoid docs are "plain old docs" from the DB perspective. so if I have a paranoid deleted doc with slugs: ["foo"], deleted: true, the DB doesn't care about deleted: true. As long as that deleted paranoid doc is lingering in the DB, I can't save a new doc with slugs: ["foo"]
  • one might think: ok, the solution here is to set slugs: nil on the deleted doc. prior to this PR Better handling of unique and sparse index constraints. #227 this wasn't possible because the index was not sparse, meaning that two docs with _slugs: null would cause the unique index validation to fail. Now that PR Better handling of unique and sparse index constraints. #227 is merged, this approach should be possible.

@dblock
Copy link
Collaborator

dblock commented Sep 9, 2016

Okay this is a very clear explanation!

So I think this particular PR can be closed, because it's fully addressed in #227 which effectively "fixes" the scenario that was attempted here by introducing a sparse index? And the specs now create database-level indexes so we should be good.

@johnnyshields
Copy link
Member

Does paranoid doc remove the value for _slugs? It needs to if it's not doing so already.

@dblock
Copy link
Collaborator

dblock commented Sep 9, 2016

@dblock dblock closed this Sep 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants