binarypaladin
Integrating Ash into an existing project
I have a pretty large existing project and I want introduce Ash. I have existing schemas, migrations, etc. It’s a Phoenix project. The good news here is that the scope of the project touches really lightly on existing schemas. It’s not quiet greenfield, but close enough.
The documentation for Ash is… a lot. This is a good thing. I’ve watched some videos, gone through the LiveBook, read stuff all over the place (actual docs, blogs, etc.). I’m now at the place where the rubber meets the road and for Ash Postgres… it’s got its own repo, migrations (well sorta), etc. Is there some kind of guide one pitfalls, gotchas, best practices… maybe an unfinished blog article on the matter? Haha. (So it’s not lost in this post, that is the actual question.)
Longer Version for context:
I have been eyeballing Ash for at least a year. The system in question uses a library I put together ages ago (my first Elixir project actually) and some conventions to mimic the resource model. (We’re even running JSON:API.) When I dug into Ash… “OMG. This is basically an awesome version of what I was doing put together by someone who was able to articulate the the problem I was trying to solve much better than I was!”
My long term goal is to see how we like it in reality on this project and, if it works as well as I expect, put together a plan to replace our custom stuff with Ash. Not only does it appear to be far superior, but I think the work involved in our backporting–though in no way trivial–will pay far greater dividends than trying to fix/improve/better document our own stuff. Plus we get a community behind us rather than working in a proprietary silo.
Anyway, this is both my goal and frankly, who doesn’t love getting to mess with something new in their professional life? Any info before I actually start coding would be appreciated.
Most Liked
Guy14
Hey!
Just to answer your first post bold question:
Is there some kind of guide one pitfalls, gotchas, best practices… maybe an unfinished blog article on the matter?
I’ve written a few months ago a series of articles about my own experience of migrating a Phoenix project to Ash.
Here is the link: Migration to Ash series | Blog of the (p)repair project
It covers with some details and complete code example the migration process from an Ecto Schema to an Ash Resource.
I wrote it for me, as a way to validate my comprehension of the process and differences between frameworks approaches. I also wrote it with the goal to share it with the community. Because I spent a lot of time during last spring (April and May 2024) on the Ash Discord, and I received many help from Ash developers and users
.
Finally I had to switch my life project and to find a new job to get revenue (my first job as a programmer, and unfortunately it’s not in Elixir but PHP and JavaScript, but now that I start to get used of these “new” languages, I’m switching back to my (p)repair project on my free time). Well I guess, that’s out of the current topic
.
Hope these articles can help new Ash adopters which would came from Phoenix !
frankdugan3
Having done this migration on a large ERP with tons of schemas, I can advise these steps:
-
Prefix the Ash stuff you add, like
MyApp.Ash.[...]. This makes it easy to namespace Ecto schemas vs Ash resources. They can coexist while you migrate. If you are depending on PubSub, you’ll need to do a little bit of cross-notification integration between the two in places where the app is using the same schema/resource in both paradigms. Personally, I found it easier in general to avoid that by just migrating an entire context at once. YMMV. -
Implement all new features in Ash.
-
As you migrate from your old contexts, you can gradually remove your deprecated modules when they are no longer used.
-
Once all your old modules are gone, you can do a little search & replace to get rid of the
.Ash.namespace if you want.
Note: Pay close attention to Zach’s advice about the migration generator. It is very worth using, just make sure you delete anything that was already done in your previous migrations.
zachdaniel
I don’t believe that there is any particular guide for this ![]()
I’m happy to use this thread to answer questions on this regard. The most important thing to keep in mind is:
You can turn your Ecto repo into an AshPostgres.Repo and still use it with Ecto
.
Ash’s generated migrations are also standard ecto migrations meaning that they should be compatible as-is. Because you already have some database structure, you may end up generating migrations and then deleting or hand-modifying the generated migrations sometimes etc.
You may also be interested in the task to bootstrap a suite of Ash resources from a postgres database:
mix ash_postgres.gen.resource MyApp.MyDomain
Popular in Questions
Other popular topics
Latest Ash Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex










