Ash Framework Book: various errata

I created my own tunez app from scratch using mix new tunes_hg
I successfully followed the book creating the ash_resource ‘artist’.
I created the migrations using mix ash.codegen create_artists

Then I did mix ash.migrate and got the error:
Postgrex.Protocol (#PID<0.198.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database “tunes_hg_dev” does not exist.

I searched the internet for this error and found mix ash.setup

Using it worked out perfectly.

mix ash.setup
Getting extensions in current project…
Running setup for AshPostgres.DataLayer…
The database for TunesHg.Repo has been created

05:31:11.988 [info] == Running 20250116154542 TunesHg.Repo.Migrations.InitializeExtensions1.up/0 forward

== Migrated 20250117040821 in 0.0s

Maybe others may trip on this error to?

Heiko Goes

P.S.: I am very happy with your book :smile:

Errata
I think on page 12:

To create an Artist record, we need to provide the data to be stored — in this
case, the name and biography attributes, in a map. (The other attributes, such
as timestamps, will be automatically managed by Ash.) We call these the
attributes that the action accepts, and can list them in the action with the
accept macro.
01/lib/tunez/music/artist.ex
actions do
create :create do
accept [:name, :biography]
end

it should be keyword list and not map

All the best from Heiko

I found two errors using the update-handler and changeset on page 19.

artist |>
Tunez.Music.update_artist(%{name: “Hello”})
{:error,
%Ash.Error.Invalid{
errors: [
%Ash.Error.Invalid.InvalidPrimaryKey{
resource: Tunez.Music.Artist,
value: {:ok,
#Tunez.Music.Artist<
meta: ecto.Schema.Metadata<:loaded, “artists”>,
id: “eb65818b-2dbd-4a54-bfa2-2ea8594ec922”,
name: “Valkyrie’s Fury”,
biography: "…,
inserted_at: ~U[2025-01-17 10:21:41.115490Z],
updated_at: ~U[2025-01-17 10:21:41.115490Z],
aggregates: %{},
calculations: %{},

>},
splode: Ash.Error,
bread_crumbs: ,
vars: ,
path: ,
stacktrace: #Splode.Stacktrace<>,
class: :invalid
}
]
}}

and

Ash.Changeset.for_update(artist, :update, %{name: “World”})
** (ArgumentError) Initial must be a changeset with the action type of :update or :destroy, or a record.

Got: {:ok, #TunesHg.Music.Artist<meta: ecto.Schema.Metadata<:loaded, “artists”>, id: “02201170-9387-4dfd-b6d8-866435da9daf”, name: “Valkyrie’s Fury”, biography: “…”, inserted_at: ~U[2025-01-17 10:20:14.823742Z], updated_at: ~U[2025-01-17 10:20:14.823742Z], aggregates: %{}, calculations: %{}, …>}

(ash 3.4.55) lib/ash/changeset/changeset.ex:1481: Ash.Changeset.for_update/4

There is a small typo too:
Tunez.Music.update_artist(%{name: “Hello”}
the ‘)’ is missing.

Best regards from Heiko

As I told before, I create a new TunesHg-App to follow the course.

Question 1:
I tried seeding but it didn’t work, because I hadn’t implemented the ‘update’-action, because it is implemented later.
Maybe the seeding should be later too…

Question 2:
How do I create the seeder.ex from scratch?

Best wishes from Heiko

Okay, let me go through all the comments!

Some of the errors you’re seeing, such as not having run mix ash.setup, are because you’ve created your own app and have skipped our setup instructions. We can try and accommodate more use cases, such as showing people how they can create new apps using Igniter and Ash, but we can’t cover every possibility. I’ll try to keep it in mind, but you may find more issues like this through the book.

it should be keyword list and not map

When calling the create action you need to provide a map of data, not a keyword list, eg.
Tunez.Music.create_artist(%{name: "Name"}).

I found two errors using the update-handler and changeset on page 19.

The previous code sample to load an artist by ID uses the bang version of the method, get_artist_by_id! to return an Artist struct, not an ok tuple - I think you’ve missed the bang from the previous example as your artist is an ok tuple.

I’ll fix the typo on that page, thank you for spotting that!

I tried seeding but it didn’t work, because I hadn’t implemented the ‘update’-action, because it is implemented later.

We have several different seed scripts that are runnable when we specify them at that part of the book. In chapter 1, only the first script is usable, so we advise to run mix run priv/repo/seeds/01-artists.exs - there is no update in that script.

How do I create the seeder.ex from scratch?

I’m not sure what you mean by this question - I created the seed data in the Tunez app using ChatGPT and Midjourney. Can you clarify what you’re trying to do?

Dear Rebecca.

Thank you for your patience.
I hope, I didn’t disturb you too much.

I think, I succeeded creating the tunez app from scratch the way I wanted.
The reason, I am so keen doing this is

  1. Knowing how to setup a web-app using ash on my own.
  2. The Tunez-Repo includes the completed code of chapter 1-6, but not the code directly before chapter1 (or did I miss that?)

What I did was:

mix archive.install hex phx_new

mix igniter.new tuneshg \

–install ash,ash_postgres,ash_phoenix \

–with phx.new \

–extend postgres \

–example

mix ash.gen.domain Tuneshg.Music

mix ash.gen.resource Tuneshg.Music.Artist --extend postgres

adding the necessary code

mix ash_phoenix.gen.live --domain Tuneshg.Music --resource Tuneshg.Music.Artist --resourceplural artists

I hope, you do understand my intentions better now.

Best wishes from Heiko