2

In Rails 5, I am no longer able to use a rake task that migrates files in a different directory. I get the error ActiveRecord::UnknownMigrationVersionError: No migration with version number 20180209214145.

Any idea how I could do this in Rails 5? I think that the line ActiveRecord::Migrator.migrations_paths = ['db/manual_migrate'] no longer works as expected, but I am not quite sure how to fix it.

  desc 'Run db:migrate:up on a task we wish to migrate manually (e.g. not on all servers).' \
    'VERSION is required.'
  task manual_migrate: [:environment, :load_config] do
    raise 'VERSION of migration is required for this task!' unless ENV['VERSION']
    default_paths = ActiveRecord::Migrator.migrations_paths
    ActiveRecord::Migrator.migrations_paths = ['db/manual_migrate']
    begin
      Rake::Task['db:migrate:up'].invoke
    ensure
      ActiveRecord::Migrator.migrations_paths = default_paths
    end
  end
Julie
  • 1,941
  • 3
  • 17
  • 30

0 Answers0