Patch for ActiveRecord 8.1+ which restores pre Rails 8 db:migrate behavior
README.md

ActiveRecord migrate fix #

Gem Version

What does this do #

This is a tiny monkey-patch for ActiveRecord 8.1+, reverting this change made in AR 8.0, where rake db:migrate no longer runs all migrations from the beginning on an empty database, but instead just installs the schema from db/schema.rb same way that db:prepare does.

The fix overrides ActiveRecord::Tasks::DatabaseTasks#migrate_all with a version that instead of calling #initialize_database, which creates the database if needed and imports the schema.rb, calls a local helper #create_database_if_missing, which only creates the database, but doesn't add the tables, letting the migration runner take care of that.

Requirements #

  • Ruby 3.2 or newer
  • compatible with ActiveRecord 8.1.x

Usage #

Add the gem to your Gemfile:

gem 'activerecord-migrate-fix', '~> 0.1.0'

And load it in your Rakefile:

require 'activerecord-migrate-fix'

Now, when you run bundle exec rake db:migrate in the app with no database initialized, it should run all migrations one by one.

Credits #

This project: copyright © 2026 Kuba Suder (@mackuba.eu).

Rails & ActiveRecord: copyright © David Heinemeier Hansson and Rails contributors.

The code is available under the terms of the MIT license.