What is the best way to resolve Rails orphaned migrations?

后端 未结 10 1001
陌清茗
陌清茗 2020-12-22 22:29

I have been switching between branches in a project and each of them have different migrations... This is the scenario:

$ rake db:migrate:status

<
10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-22 23:21

    If the migration files are truly missing (e.g. ran migration, forgot to roll back migration, then deleted migration file before commit), I was able to reproduce the missing migration as follows:

    1. go back in git history to get a copy of the schema.rb file and save outside of git repo (git log; git checkout xxxxxx; cp schema.rb ~/schema_old.rb, git checkout master).
    2. run a diff on the two files, and copy the migration commands into a migration file that matches the missing migration ID (diff schema.rb ~/schema_old.rb > migration_file.rb; vi migration_file.rb)
    3. Check your migration status and rollback (rake db:migrate:status; rake db:rollback; rake db:migrate:status;)

提交回复
热议问题