Test out Ash Frameworks' first igniter-backed generators/installers!

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 :sunglasses:

10 Likes

Got the below error while running :

mix igniter.new app_name \
  --install ash@github:ash-project/ash
  • Getting ash (GitHub - ash-project/ash: A declarative, extensible framework for building Elixir applications.)
    remote: Enumerating objects: 44617, done.
    remote: Counting objects: 100% (1646/1646), done.
    remote: Compressing objects: 100% (1099/1099), done.
    remote: Total 44617 (delta 613), reused 1544 (delta 536), pack-reused 42971
    origin/HEAD set to main
    error: invalid path ‘documentation/dsls/DSL:-Ash.DataLayer.Ets.md’
    error: invalid path ‘documentation/dsls/DSL:-Ash.DataLayer.Mnesia.md’
    error: invalid path ‘documentation/dsls/DSL:-Ash.Domain.md’
    error: invalid path ‘documentation/dsls/DSL:-Ash.Notifier.PubSub.md’
    error: invalid path ‘documentation/dsls/DSL:-Ash.Policy.Authorizer.md’
    error: invalid path ‘documentation/dsls/DSL:-Ash.Reactor.md’
    error: invalid path ‘documentation/dsls/DSL:-Ash.Resource.md’
    ** (Mix) Command “git --git-dir=.git checkout --quiet origin/HEAD” failed
    mix deps.get returned exited with code: 1

Interesting…can you please open an issue on the igniter GH repo?

If anyone else is getting that same error please let me know as well.

EDIT: I’m unable to reproduce it. Are you on windows?

Yes , i am on Windows 11

Hmm…I think this issue is unrelated to igniter in that case. If you were to make a fresh project and point a mix dependency at github, you’d likely encounter this same issue. You’ll probably need to wait until we release proper hex version to try these out in that case, sorry about that :cry:

1 Like

Congrats on the beta release

Tried using uuidv7 with --uuid-v7-primary-key id but noticed that it fails silently, and generates a resource without a primary key.

Then noticed that it also silently ignores any unknown/typo-ed parameters

Could you make it error out instead of silently ignoring unknown params in this case?

TIA

This is actually kind of a tough one because of the way that we pass arguments down into nested generators :thinking: I will see what I can do :slight_smile:

1 Like