Elixir-Code-Smells
Elixir-Code-Smells copied to clipboard
Discussion: data manipulation without migrations when using releases
Under Data manipulation by migration, the recommended refactoring of creating a mix task only really works if you're able to run mix tasks. Which means that if you're using releases it's not quite clear what the solution would be.
Should one create a release task? Would that be the case even if it's a one-off thing? The mix release guide does suggest using helper modules for grouping commands that one notices one is using repeatedly.
Being a one-off thing, it may be tempting to use eval or rpc or even to open a remote iex session and manually do it. But, if the data manipulation that one needs to do gets even a little bit complicated, or if one is going to deploy to more than one environment, it may easily become error-prone.
So, what would be the best solution when using releases?
Hi Santiago,
this point raised by you is really interesting. Our examples and refactorings are not intended to cover all implementation and deployment possibilities. We provide them with a more didactic and illustrative purpose. For this reason, you are right when you say that our refactoring proposal does not address the cases where developers are using releases.
I need to think a little more to suggest a solution for when releases are being used. I'll leave this issue open even to receive suggestions about it from other community members.
Thank you so much for raising this discussion!
Thank you for your response! I would like to hear your thoughts on this kind of approach: https://blog.appsignal.com/2020/02/25/migrating-production-data-in-elixir.html
I also believe this guide covers data migrations: https://fly.io/phoenix-files/safe-ecto-migrations/