0

I tried the answer provided in this post unsuccessfully. The migration just ran against my default database.

How do I migrate a non-default db in Rails 4?

config/database.yml (foo substituted for sensitive values):

personnel_development:
  adapter: postgresql
  host: foo
  database: personnel
  username: foo
  password: foo

personnel_production:
  adapter: postgresql
  host: foo
  database: personnel
  username: foo
  password: foo

db/migrate/20150107222716_create_personnels.rb:

class CreatePersonnels < ActiveRecord::Migration
  def connection
    ActiveRecord::Base.establish_connection("quiz_#{Rails.env}").connection
  end

  def change
    create_table :personnels do |t|
      t.string :fn
      t.string :ln

      t.timestamps
    end
  end
end

Model:

class Personnel < ActiveRecord::Base
  establish_connection "personnel_#{Rails.env}"
end
Community
  • 1
  • 1
Choylton B. Higginbottom
  • 2,236
  • 3
  • 24
  • 34

2 Answers2

0

You can use octopus gem for that, see this blog post: http://grigio.org/multiple_database_same_rails_app_octopus

Alex Ponomarev
  • 885
  • 5
  • 11
0

We ended up setting up a database with the desired schemas and associations manually, and deleted the migrations. The app then worked correctly with the model and config listed in the question. Definitely solved the problem, but unfortunately not the "Rails way".

Choylton B. Higginbottom
  • 2,236
  • 3
  • 24
  • 34