Reputation: 1639
I have a rails app that I use to connect to a production slave database hosted on amazon. I want to create a second database, that has an entirely different schema and just keep it on my local machine. The reason is to import data from a third party we use and better organize and be able to access it faster than hitting their api. My question is how would I go about setting this second database up? Would it be better just to create a new rails application all together? If I set up a new environment and a new database in my database.yml, how would I create a custom schema etc. for that database?
Thanks!
Upvotes: 4
Views: 4363
Reputation: 2843
Whether you use a different Rails application depends on how much functional overlap there is between the two applications, if there are two applications.
However, if you want to address two separate databases from the same Rails application, so that you can process entries from one database to make changes in a different database, that is fairly easy. There are a number of examples if you search for establish_connection, for example here: https://web.archive.org/web/20160320192534/http://blog.nistu.de/2012/03/25/multi-database-setup-with-rails-and-rspec
Basically, you have a main, default database for your application, and then set up one or more of your models to use a different database by defining the second database's configuration under a different name in database.yml. Then, put the establish_connection call, referencing the different database configuration, in your model definition.
There are some options for managing the migrations in a multi-database configuration here: Using Rails Migration on different database than standard "production" or "development"
Upvotes: 4