rails: maintain_test_schema doesn't honor reverse migrations

Use case: create a migration, migrate forward, notice a problem in the migration, rollback, fix the migration, migrate forward, test db is out of sync.

To demonstrate, I built a test project with minitest and two migrations, added a test that depended on both migrations. The results were this:

  • rake db:migrate; rake # test passed, should pass
  • rake db:rollback; rake # test passed, should fail
  • rake db:migrate VERSION=0; rake # test passed, should fail

Suggest activerecord/lib/active_record/migration.rb#846 be changed from current_version(connection) < last_version …to… current_version(connection) != last_version

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 35 (31 by maintainers)

Most upvoted comments

it’s true that rerunning migrations is not particularly handy with the current state of things. While it’s documented in the guides, it’s cumbersome and easy to forget.

@joallard we can’t simply run db:test:prepare on every db:migrate. There are lots of cases where there is a dev or prod database but not a test database. If you have a good solution that is compatible with different environments please submit a PR so we can discuss the code.