Maksym Prokopov personal blog
Idea is a something worth sharing

Stop writing data migrations

15.09.2025
Reading time: 1 min.

As many of us, I was writing data migrations as a part of database schema migrations.

That’s a bad practice, and here is how I perform the same nowadays.

Example

Migration from the plain text fields to rich text fields with ActiveText. How?

  1. Create a migration to add action_text_rich_texts table.
  2. Create a migration to rename old column containing plain text to the field prefixed with old_
  3. Write a rake task to convert the data from old column to the new place.
  4. Write a migration to remove old content after everything went smooth

Steps 1-2-3 are done within a single new PR. Once the schema is in the new state, I perform rake tasks for data movement.

The subsequent PR just tears down old fields and voila.