How to adjust a Globalize translation table without breaking app/migrations

571 Views Asked by At

I tested a localized rails/react app with the Globalize Gem. Everything locally is working fine.

When I pushed to Heroku I had an error when running heroku run rails db:migrate because my migration to create the translation table with had a mistake:

xxxx_create_translation_table_for_movies

class CreateTranslationTableForMovies < ActiveRecord::Migration[5.2]
  def change
    reversible do |dir|
      dir.up do
        Movie.create_translation_table!({
                                           :title => :string,
                                           :text => :text
                                       }, {
                                           :migrate_data => true
                                       })
      end

      dir.down do
        Post.drop_translation_table! :migrate_data => true
      end
    end
  end
end

when actually the model has an excerpt instead of a text attribute: schema.rb

create_table "movie_translations", force: :cascade do |t|
    t.bigint "movie_id", null: false
    t.string "locale", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "title"
    t.text "excerpt"
    t.index ["locale"], name: "index_movie_translations_on_locale"
    t.index ["movie_id"], name: "index_movie_translations_on_movie_id"
  end

Rails is probably smart enough to run all that locally no problem but of course Heroku is not happy:

rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

Missing translated field :text

I would like to correct my mistake by just swapping :text => :text for :excerpt => :text but I know that sometimes messing with migrations can break your entire app :D

How could I correct all that in order to push to github again and then to reinstall to heroku? Should I create a specific migration to address this issue? Also, will it break the rest of the app that was working fine locally?

Thanks!

0

There are 0 best solutions below