Migration from Rails to phoenix

Currently, I have a rails app. I wanted to migrate to Phoenix. I can build all new APIs in phoenix but the question is how manage DB models? If I add in rails then I can’t access them on phoenix and vice versa. How to manage these dependencies?

1 Like

I don’t know if I got what you mean, but you can use https://github.com/elixir-ecto/ecto to access the resources of your DB

1 Like

Thanks for reply. Yes, I can access DB through Ecto. What if new API demands new model? Where should I add? If I add it in rails then I can’t access in Elixir? To make it accessible in Elixir I need to add Ecto schema which makes code duplication? Is there any way to avoid duplication?

Can just use the schema-less Ecto API.

I do not think there’s an easy way to avoid duplication while you are migrating the application. You will get rid of it eventually, but during the process you might need the same schemas/models on both ends.

I would, however, double think if you want to add new stuff or change functioanlity in the process of rewriting. I think easier would be to do a Rails -> Phoenix migration first, and only then start changing stuff. That is, if it’s possible to avoid it - I would avoid it :).

4 Likes

It seems to me that if you are adding new models that you need to interact with in both apps, then you aren’t really migrating off your Rails codebase, you’re just duplicating a new feature in both apps. So you’re going to have to inherently duplicate code. :slight_smile:

1 Like

If we can’t avoid duplication then I would duplicate. Thanks for suggestion.