Ash and AshPostgres generators/installers, built with igniter are available on main!
I’ll be very grateful to anyone willing to give them a shot and report back with there experience.
Keep in mind, things will absolutely break. Not only are these brand new generators, but they are an entirely new kind of generator. For more on igniter
, see this thread: Igniter - A code generation and project patching framework
Commands to dive in with!
Install the archive
mix archive.install hex igniter_new
Create a new app and install dependencies into it
We use the github dependencies here so that you can use the new installers, which are only available on main
currently.
mix igniter.new app_name \
--install ash@github:ash-project/ash
Or install multiple dependencies at once. iterex
in this example doesn’t have an installer (as it doesn’t need one), so it just gets added to the mix.exs
file with no other changes
# as a csv
mix igniter.new app_name \
--install iterex,ash@github:ash-project/ash,ash_postgres@github:ash-project/ash_postgres
# in multiple flags
mix igniter.new app_name \
--install iterex \
--install ash@github:ash-project/ash \
--install ash_postgres@github:ash-project/ash_postgres
Or, modify an existing app!
first, add igniter to your mix.exs
defp deps do
[
{:igniter, "~> 0.2"}
]
end
Install dependencies
mix igniter.install ash@github:ash-project/ash
Install dependencies with example code!
mix igniter.install ash@github:ash-project/ash --example
Generate a resource
mix ash.gen.resource Twitter.Tweets.Tweet \
--uuid-primary-key id \
--attribute text:string:required:public
And generate another one, see how the domain is modified to reference the newly created resource?
mix ash.gen.resource Twitter.Tweets.Like \
--uuid-primary-key id \
--relationship belongs_to:tweet:Twitter.Tweets.Tweet:required:public
Generate a resource using a specific extension!
You will want to install ash_postgres
first for this to work:
mix igniter.install ash_postgres@github:ash-project/ash_postgres
mix ash.gen.resource Twitter.Tweets.Tweet \
--uuid-primary-key id \
--attribute text:string:required:public
--extend postgres
Modify an existing resource to use a new extension
swap its data layer to use ets
mix ash.extend Twitter.Tweets.Tweet ets
And swap it back to use postgres
mix ash.extend Twitter.Tweets.Tweet postgres
Or add a new extension
mix ash.extend Twitter.Tweets.Tweet Ash.Policy.Authorizer
There are a couple more generators you can play with like mix ash.gen.enum
, but I think this is enough to get started.
Happy hacking