-
Notifications
You must be signed in to change notification settings - Fork 21
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 Update Channels #243
Add Update Channels #243
Conversation
Pull Request Test Coverage Report for Build 9047d5d5078d8ba8db64f16f4f67cb6498347d84-PR-243Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
61454c3
to
9047d5d
Compare
references(:update_channels, | ||
with: [tenant_id: :tenant_id], | ||
on_delete: :nilify_all | ||
) |
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.
You might want to add a match: full
on the foreign key here.
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.
match: full
doesn't allow the id to be NULL
(see here), and since a device_group
is allowed to have no connected update_channel
, this should be supported
@doc false | ||
def create_changeset(update_channel, attrs) do | ||
update_channel | ||
|> changeset(attrs) | ||
|> validate_required([:target_group_ids]) | ||
end |
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 am missing the broader context, why a different create_changeset/2
that does not cast or perform all the validations included in changeset/2
?
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.
Actually it does, we usually do separate create/update changesets by duplicating the whole function, but I realized that if you need a changeset that is strictly a superset of another one, you can just create the smaller changeset with its function and then add additional validation/casting, which eliminates duplicate code and the need to keep the two changesets in sync for the common parts.
In this case, target_group_ids
is already cast in the changeset
function, but when you update an UpdateChannel
you don't have to necessarily pass target_group_ids
if you don't need to update them, while you do have to pass them when you create it, so I just add an additional validate_required
on top of the other changeset
0b079ee
to
4107493
Compare
4107493
to
0b5bbff
Compare
|> changeset(attrs) | ||
|> validate_required([:target_group_ids]) | ||
end | ||
|
||
@doc false | ||
def changeset(update_channel, attrs) do |
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.
When we have few changesets (see changesets for base_image, ota_operation) usually we prefix their names with verb (like create_changeset
, update_changeset
). Do we want to rename changeset
-> update_changeset
?
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.
In this case I left this name like this because it's actually reused in create_changeset
(which is something I suspect we can do more when we split the whole update/create
stuff). It doesn't make much sense for create_changeset
to call update_changeset
, hence the naming.
4181537
to
84c7dbd
Compare
Generated with: mix phx.gen.context UpdateCampaigns UpdateChannel update_channels \ tenant_id:references:tenants name:string:unique handle:string:unique Copyright headers manually added after generation Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
- Change get_update_channel!/1 to fetch_update_channel/1 - Scope unique indexes to tenant - Validate handle format - Adapt tests and add some more Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Prerequisite for using this fixtures in the upcoming UpdateChannel fixtures Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Identify which update channel (if any) a device group is associated with Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
The association is explicit only on UpdateChannel since we want the dependency between context to only go in that direction (i.e. UpdateCampaigns knows about Groups, not the other way around). Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Allow assigning and unassigning Device Groups when creating, updating or deleting an UpdateChannel. Add relevant tests and fixture changes. Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Also add relevant tests Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Also add relevant tests Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Also add relevant tests Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Also add relevant tests. Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Allow retrieving a device group id -> update channel map for a list of device group ids using a single database query. Also add relevant tests. Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Allow retrieving the UpdateChannel associated with a specific DeviceGroup. Do this using batching so we minimize N+1 query problems. Also add a relevant test and update CHANGELOG since the UpdateChannels feature is now complete. Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Add a GraphQL CRUD for UpdateChannels, allowing to manage them an associate them with Target Groups