-
Notifications
You must be signed in to change notification settings - Fork 60
Fix seeding #958
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
base: main
Are you sure you want to change the base?
Fix seeding #958
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -261,7 +261,14 @@ defmodule Orcasite.Radio.Feed do | |||||||||||
| description "A comma-separated string of longitude and latitude" | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| argument :maintainer_emails, {:array, :string}, default: [] | ||||||||||||
|
|
||||||||||||
| change &change_lat_lng/2 | ||||||||||||
|
|
||||||||||||
| change fn changeset, _context -> | ||||||||||||
| maintainer_emails = Ash.Changeset.get_argument(changeset, :maintainer_emails) || [] | ||||||||||||
| Ash.Changeset.change_attribute(changeset, :maintainer_emails, maintainer_emails) | ||||||||||||
| end | ||||||||||||
|
Comment on lines
+264
to
+271
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainEnsure upserts can update maintainer_emails; also normalize values. Currently not included in upsert_fields, so existing rows won’t update on conflict; also normalize to lower-case/unique. Apply both diffs:
- change fn changeset, _context ->
- maintainer_emails = Ash.Changeset.get_argument(changeset, :maintainer_emails) || []
- Ash.Changeset.change_attribute(changeset, :maintainer_emails, maintainer_emails)
- end
+ change fn changeset, _context ->
+ maintainer_emails =
+ (Ash.Changeset.get_argument(changeset, :maintainer_emails) || [])
+ |> Enum.map(&String.downcase/1)
+ |> Enum.uniq()
+
+ Ash.Changeset.change_attribute(changeset, :maintainer_emails, maintainer_emails)
+ end
upsert_fields [
:name,
:node_name,
:intro_html,
:image_url,
:visible,
:bucket,
:bucket_region,
:cloudfront_url,
:dataplicity_id,
:orcahello_id,
- :location_point
+ :location_point,
+ :maintainer_emails
]🏁 Script executed: #!/bin/bash
# Verify DB migration exists for the new column
rg -n "maintainer_emails" -g "priv/**/migrations/*.exs" -C2 || echo "MIGRATION NOT FOUND"
# Verify GraphQL schema exposure matches policy (nullable, field policy)
rg -n "nullable_fields.*maintainer_emails" server/lib/orcasite/radio/feed.ex -C2Length of output: 273 Add missing DB migration and update upsert logic
GraphQL exposure ( 🤖 Prompt for AI Agents
Comment on lines
+268
to
+271
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can still be simplified to:
Suggested change
See: https://hexdocs.pm/ash/Ash.Resource.Change.Builtins.html#set_attribute/3 |
||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| update :update 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.
If the argument is an attribute and you're setting the attribute to the argument, you can simply add it to the
acceptlist above and skip theargumentandchange _attributechangeset. You could add it to the upsert_fields too, but it's less important since this is just for seeding.Uh oh!
There was an error while loading. Please reload this page.
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.
Hm I need it to default to empty list though, in case the API returns
nilformaintainer_emails(which it will because it's an auth only field). So I guess I could remove theargumentbut I still need thechangeno? Do you have a better suggestion? Curious how you would tackle it, I don't really know what's idiomaticThere 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.
Ok yeah really good point. In prod we don't want that to be nil, but an empty list works.