High level advice for migrating existing app to Ash

I have been searching for high level advice/heuristics as to how to convert an existing project to Ash.

It has phx auth and 10 database tables. I have the luxury of being able to redo all of the migrations and database structure and writing a custom script to migrate existing data but there is a fair bit of application code and functions.

Some general questions are

  1. Any suggestions for mixing Ash and non-ash managed data - e.g. relationships, etc?
  2. Any advice as to the practicality of changing existing data - my assumption would be that I would have to recreate the schemas, find all of the functions that would be actions and set those up, and generate ash liveviews for everything to compare.
  3. Any advice as to order of operations or is it just one big surgical operation and running tests is what will provide sanity

Thanks for any advice.

I’ve been introducing Ash to very large and fairly complex app.

Our intent is not to migrate everything, but to leverage Ash to build new features and expand on existing ones where it makes sense.

You cannot mix Ecto and Ash data, you’ll need to have one Ash resource for pretty much each Ecto schema you have, but there’s no issues about them using the same DB table. Given our design, this took a while and I it honestly felt like a chore to “duplicate” all we needed to ship a feature in Ash, but once this was done everything just clicked together (and it’s needed only once anyway). I’ve added an Ash namespace prefix to the new modules to create a boundary.

Since we already had all tables in place, we don’t use Ash to migrate data. We added migrate? false to all resources and ran Ash migration so it could create the functions it relies on. We still did not need to add new tables so I can’t tell if we would let Ash manage a new table or would write the migrations ourselves for now.

Also we try to keep a good API for the LiveViews to use, it’s easy to replace Context functions with Ash functions and the other way around if we need. There’s no need to do it all at once, in many places we were able to change stuff under the hood and not break any tests, and whenever we’re comfortable we can just replace our fixtures to use Ash as well to create data in tests.

For auth, we use a version of phx.gen.auth, and have some custom tenant rules with Ash (our actor is a map with org/user [from Ecto] and a few other stuff, instead of just an user) and we’ve had no issues with it.


Thank you, @shamanime That is very helpful.