Changing the Type of a Column in Table (Elixir, Fly)

Hi @janjakubek,

The Safe Ecto Migrations guide is really intended for migrating production data where you want to avoid downtime. If you are doing this migration on a hobby project or you can tolerate some brief downtime, then you can be more aggressive in how you solve it.

The general idea of a multi-stage migration is…

  • Migrations change the database structure
  • Then a separate data migration can migrate the data from the old structure to the new structure.
  • Doing these as separate steps lets you avoid service interruptions. If you don’t care about that, then you can do it all together if want.

In answer to your questions:

  1. Keep the additional migrations on separate branches. The point is, they aren’t deployed at the same time.
  2. There is no built-in way to do an export/backup of a single table.
  3. You create a module in your code that does the performs the data migration from the source field to the converted target field. You can deploy the application and when you are ready, get an IEx shell into your running application and manually execute the data migration code. It’s a one-time migration step anyway.

Again, these more broken out steps are for avoiding downtime or service interruptions on production systems. Just make sure you’re performing this additional work when it’s needed and not for personal dev project. :slight_smile:

1 Like