Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Add ability to specify a unique constraint on exact and range indexes #61

Merged
merged 9 commits into from
Aug 12, 2022

Conversation

fimac
Copy link
Contributor

@fimac fimac commented Aug 10, 2022

This PR updates:

  • stash indexes and the schema builder to handle the ability specify a unique constraint on range and exact indexes.
  • Raises an error if a unique constraint is specified on a match index.
  • Tests to cover the above and check if an error is raised when a duplicate record is inserted.
  • I also added a test to check to see if case sensitivity made a difference. A RecordPutFailure will still be raised even if the field is in a different case.
  • Updates readme.

@fimac fimac force-pushed the pass-unique-constraint-with-index branch from d2f695f to 2ec1f38 Compare August 10, 2022 11:07
@fimac fimac force-pushed the pass-unique-constraint-with-index branch from 0696876 to 5213aba Compare August 10, 2022 22:06
@fimac fimac force-pushed the pass-unique-constraint-with-index branch from 60ef7b5 to aa0fb65 Compare August 10, 2022 22:20
@fimac fimac force-pushed the pass-unique-constraint-with-index branch from aa0fb65 to f67b369 Compare August 10, 2022 22:30
@fimac fimac marked this pull request as ready for review August 10, 2022 22:32
@fimac fimac requested a review from a team as a code owner August 10, 2022 22:32
@fimac fimac changed the title Add unique constraint to exact and range index Add ability to specify a unique constraint to exact and range index Aug 10, 2022
@fimac fimac changed the title Add ability to specify a unique constraint to exact and range index Add ability to specify a unique constraint on exact and range indexes Aug 10, 2022
README.md Outdated
end
```

Used in combination with `except` and `only` you can specify a unique constraint on a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what circumstance would you want to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was to show the syntax for adding a unique constraint when using except and only. So if they didn't want the other indexes, like range for ordering or match for free text search this is what it would look like.

Do you think this is unnecessary info?

README.md Outdated
@@ -247,6 +248,49 @@ User.query("ruby")
For more information on index types and their options, see the [CipherStash
docs](https://docs.cipherstash.com/reference/index-types/index.html).

## Unique indexes

ActiveStash supports adding server side unique constraints on `:range` and `:exact` indexes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it might be overloading the user with unnecessary information. The only data types for which we create both a range and an exact index are string-ish types (string and text), and we only do it there because ranges on strings aren't suitable for querying. If we stick to talking about "unique fields", I think that gives the right level of context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the detail in talking about the specific range and exact indexes here.

lib/active_stash/schema_builder.rb Outdated Show resolved Hide resolved
@fimac fimac force-pushed the pass-unique-constraint-with-index branch from 5202ef0 to de3091e Compare August 11, 2022 23:02
@fimac fimac merged commit 102a1f5 into main Aug 12, 2022
@fimac fimac deleted the pass-unique-constraint-with-index branch August 12, 2022 03:30
freshtonic pushed a commit that referenced this pull request Dec 21, 2022
…ndex

Add ability to specify a unique constraint on exact and range indexes
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants