The other day, I had to change the type of a field in an Ecto embedded schema from a string to a list of strings. Sounds simple, right? Well, not quiteβbecause this field already had existing data stored in PostgreSQL as JSONB. That meant I had to not only update my Elixir codebase but also write a migration to transform the stored data correctly.
Since this is a challenge others will likely encounter, I wanted to document the process, including the reasoning behind each step. If you ever need to change a field type in an embedded schema, this guide will help you do it safely without breaking your existing data.
continue reading on dreamingecho.es
β οΈ This post links to an external website. β οΈ
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.