I have experience of migration Ruby On Rails application from MySQL to PostgreSQL. An application is moved table by table for steady and successive migration. Production application is using two databases at the same time.

I spent some time in search of the best solution, and in my opinion, it is next:

config/database.yml

development:
  adapter: mysql2
  database: ***
  ...
  postgres:
    adapter: postgresql
    database: ***
    ...

app/models/version.rb

class Version < ActiveRecord::Base
  DB_CONFIG = -> { configurations[Rails.env]['postgres'].symbolize_keys }

  self.table_name = :versions
  establish_connection DB_CONFIG.call
end

And we don’t change connection in other models.

unicorn.ru:

after_fork do |server, worker|
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
    Vesion.establish_connection(Version::DB_CONFIG.call)
  end
end

before_fork do |server, worker|
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    Version.connection.disconnect!
  end
end

In such way we use Version::DB_CONFIG lambda twice and do not repeat ourself.

This solution suppose that migration process is executed by the third-party tool. I think that the most reliable of them is pgloader.