-
-
Notifications
You must be signed in to change notification settings - Fork 122
Add support for field names in idenitity constraints #478
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
Add support for field names in idenitity constraints #478
Conversation
lib/data_layer.ex
Outdated
| ] | ||
| ) | ||
| identity = Enum.find(identities, fn identity -> | ||
| String.contains?(constraint, to_string(identity.name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably not the right approach to match violated constraint with an identity but it was the quickest way to test this feature in my local env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have some logic elsewhere to get the name for a given identity, so we should reverse engineer it here. I believe we do this in the migration generator and elsewhere when we actually add in the constraint. So we can search the identities for a match on that name instead of just containing the identity name 😄
ab8b966 to
7486066
Compare
|
@zachdaniel please let me know if this is what you meant by:
In your original response. Thanks! |
|
Hey there! Haven't forgotten about you, will review soon, hopefully today. |
|
Looks great! As you pointed out, the main issue is how we get the relevant identity. It should be doable, search in the |
7486066 to
f137692
Compare
Thank you! I followed your suggestions and I've updated the logic to match identity to constraint. I would like to work on tests now but I have problems running tests for the but I have many failures across multiple files, as an example here is the output from Are those failures related to my setup? Thanks! |
|
|
||
| "main" -> | ||
| [git: "https://github.com/ash-project/ash.git"] | ||
| [git: "https://github.com/ash-project/ash.git", override: true] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I don't add override, then I'm not able to use main option for ASH_VERSION variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I haven't had that problem but adding that should fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without override: true, I was getting a following error:
Dependencies have diverged:
* ash (https://github.com/ash-project/ash.git)
the dependency ash in mix.exs is overriding a child dependency:
> In mix.exs:
{:ash, [env: :prod, git: "https://github.com/ash-project/ash.git"]}
> In deps/ash_sql/mix.exs:
{:ash, "~> 3.0 and >= 3.4.60", [env: :prod, hex: "ash", repo: "hexpm"]}
Ensure they match or specify one of the above in your deps and set "override: true"
** (Mix) Can't continue due to errors on dependencies
test/support/resources/post.ex
Outdated
| identities do | ||
| identity(:uniq_one_and_two, [:uniq_one, :uniq_two]) | ||
| identity(:uniq_on_upper, [:upper_thing]) | ||
| identity(:uniq_on_upper_title, [:upper_title], field_names: [:title]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to use this identity to test field_names option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to use Organization resource as it's not heavily used in other tests. When I added a new constraint to the Post resource, some other tests started to fail.
|
Don't worry about those tests 😄 They are related to other things that have been fixed elsewhere. |
|
It depends on ash-project/ash#1786 |
a16e7d5 to
0344284
Compare
|
Dependent PR has been merged. @zachdaniel can you give it a final review, please? |
|
Looks great, however |
Thank you! Just to make sure I understand. Now I need to wait for new |
|
Yeah we just need to pin to at least 3.4.64 |
Done. I believe now they can be released together. |
|
🚀 Thank you for your contribution! 🚀 |
This PR kicks start the work I suggested in proposal to add field names to identities.
Please keep in mind the feature is not complete yet and it also relies on adding
field_namesoption toAsh.Resource.Identitythat I plan to address after this one is completed.Once the overall direction is approved, I will work on tests to cover this new functionality.
Please let me know what you think!
PS. It's my first constribution to any Elixir open source project. I only use Elixir in my spare time so please forgive all my mistakes. I treat is as an opportunity to learn more about Elixir and Ash ecosystem.
Contributor checklist