Skip to content
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

improvement: add Igniter installer task #61

Merged
merged 10 commits into from
Jul 14, 2024

Conversation

ibarakaiev
Copy link
Contributor

@ibarakaiev ibarakaiev commented Jun 26, 2024

Contributor checklist

  • Bug fixes include regression tests
  • Features include unit/acceptance tests

This PR adds an Igniter installer which also checks whether AshPostgres is in use, and if so, installs the AshMoney.AshPostgresExtension as well as ex_money_sql.

When testing, everything works, but I am facing an issue that seems unrelated to this installer:

** (UndefinedFunctionError) function AshMoney.AshPostgresExtension.extension/0 is undefined (module AshMoney.AshPostgresExtension is not available)
    AshMoney.AshPostgresExtension.extension()
    (ash_postgres 2.0.12) lib/migration_generator/migration_generator.ex:205: anonymous fn/1 in AshPostgres.MigrationGenerator.create_extension_migrations/2
    (elixir 1.17.0) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.17.0) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (ash_postgres 2.0.12) lib/migration_generator/migration_generator.ex:203: anonymous fn/2 in AshPostgres.MigrationGenerator.create_extension_migrations/2
    (elixir 1.17.0) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (ash_postgres 2.0.12) lib/migration_generator/migration_generator.ex:52: AshPostgres.MigrationGenerator.generate/2
    (mix 1.17.0) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5

It might be possible that it's actually related to it, so I'm marking the PR as draft until I figure out what's the issue.

@zachdaniel
Copy link
Contributor

Won't have time to look into the error you mentioned today, LMK if you figure it out :)

@ibarakaiev ibarakaiev force-pushed the add-igniter-installer branch from e34ddb6 to 2f697e3 Compare June 27, 2024 21:07
@ibarakaiev ibarakaiev force-pushed the add-igniter-installer branch from 2f697e3 to 347967e Compare June 27, 2024 21:13
@ibarakaiev
Copy link
Contributor Author

Well, the problem seems to have gone away by itself. Maybe there was a hidden dependency issue. Marking as ready for review then!

@ibarakaiev ibarakaiev marked this pull request as ready for review June 27, 2024 22:01
@ibarakaiev
Copy link
Contributor Author

The remaining dialyzer warning in CI is because of ash-project/igniter#19.

@ibarakaiev
Copy link
Contributor Author

Another strange finding: running mix igniter.install ash_money twice leads to:

** (CaseClauseError) no case clause matching: #Sourceror.Zipper<
  [{:__aliases__, [trailing_comments: [], leading_comments: [], last: [line: 2, column: 43], line: 2, column: 28], [:AshMoney, :Types, :Money]}]
>
    (igniter 0.2.3) lib/code/common.ex:591: Igniter.Code.Common.within/2
    (igniter 0.2.3) lib/project/config.ex:162: Igniter.Project.Config.modify_configuration_code/5
    (igniter 0.2.3) lib/igniter.ex:710: Igniter.apply_func_with_zipper/3
    (igniter 0.2.3) lib/igniter.ex:160: Igniter.update_elixir_file/3
    (ash_money 0.1.9) lib/mix/tasks/ash_money.install.ex:15: Mix.Tasks.AshMoney.Install.igniter/2
    (elixir 1.17.0) lib/enum.ex:4423: anonymous fn/3 in Enum.reduce/3
    (elixir 1.17.0) lib/stream.ex:1879: anonymous fn/3 in Enumerable.Stream.reduce/3
    (elixir 1.17.0) lib/enum.ex:4858: Enumerable.List.reduce/3

which seems to be happening in Mix.Tasks.AshMoney.Install.configure_config/1 when config :ash, known_types: [...] already exists. However, changing append_new_to_list to prepend_new_to_list in the updater function for Igniter.Project.Config.configure/6 fixed the error. Not sure what's the deal there.

@zachdaniel
Copy link
Contributor

append_new_to_list should be fixed now.

@ibarakaiev
Copy link
Contributor Author

Should probably change the manual |> Igniter.add_task("deps.get") task to |> Igniter.apply_and_fetch_dependencies() if/once ash-project/igniter#28 is merged.

@zachdaniel
Copy link
Contributor

Alright, check out the new info/2 callback and use that for orchestrating the things you want to orchestrate and I think that should solve a lot of problems.

@ibarakaiev
Copy link
Contributor Author

The installer is now complete, pending ash-project/igniter#33.

@ibarakaiev
Copy link
Contributor Author

Should we support "breakpoints" for Igniter.add_task/3? Otherwise, a scenario like this happens:

  1. Run mix igniter.install ash_postgres,ash_money (with versions).
  2. ash_postgres.install installs the "ash-functions" extension and adds a ash.codegen install_ash_postgres task.
  3. ash_money.install installs AshMoney.AshPostgresExtension and adds a ash.codegen install_ash_money task.
  4. All changes are commited and the tasks are only then being run, resulting in the following sequence:
  • install_ash_postgres install both "ash-functions" and AshMoney.AshPostgresExtension in one migration.
  • install_ash_money is still run, but produces nothing.

In my hobby project I also have a pipeline where ash_postgres, ash_money are installed, then some resources are created and ash.codegen setup_resources is added as a task, but all three steps gets squashed into one migration within install_ash_postgres while the other run with empty results.

@zachdaniel
Copy link
Contributor

I think supporting things like checkpoints will make things very complicated relative to the current implementation. A simpler way to accomplish this would be to add a function in Ash.Igniter called add_codegen_task(name), that will either add the codegen task or update it to update the name argument to be old_name_and_new_name.

@zachdaniel
Copy link
Contributor

Going to make one main change with this which is to use the installs option in the info/2 callback, which will handle the front-loading installation of any dependencies.

@zachdaniel zachdaniel merged commit 5811d00 into ash-project:main Jul 14, 2024
14 of 15 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

@zachdaniel
Copy link
Contributor

Ah, right that was the complexity here, which is that it's installed conditionally. 🤔 🤔 🤔

@zachdaniel
Copy link
Contributor

Okay, I've updated igniter such that it will only apply changes to the deps function when that function is called :)

@ibarakaiev ibarakaiev deleted the add-igniter-installer branch July 15, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants