0

I have 3 different organizations types and 3 different databases structures: one for each type. When org1 registers I'm creating a new database instance for org1, and when org2 registers I'm creating a new db instance, and same for org3.

Now, how do I run migrations for three different db:structure from my application soon after I create a new database instance for organizations.

I am creating a db instance from application by:

ActiveRecord::Base.connection.execute(sql)

How can I do this? Is there another approach I should be using?

1 Answer 1

1

The command you are looking for is establish_connection. You might want to look at the rails rdoc. Search for "Connection to multiple databases in different models" in http://api.rubyonrails.com/classes/ActiveRecord/Base.html.

Connections are usually created through ActiveRecord::Base.establish_connection and retrieved by ActiveRecord::Base.connection. All classes inheriting from ActiveRecord::Base will use this connection. But you can also set a class-specific connection. For example, if Course is an ActiveRecord::Base, but resides in a different database, you can just say Course.establish_connection and Course and all of its subclasses will use this connection instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.