Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with multiple database connections #209

Closed
ombr opened this issue Jun 9, 2017 · 5 comments
Closed

Issue with multiple database connections #209

ombr opened this issue Jun 9, 2017 · 5 comments

Comments

@ombr
Copy link

ombr commented Jun 9, 2017

I would like to use scenic to create a view on another database connection.

Here is what I tried:

In my model:

class Event < ApplicationRecord
  establish_connection :events_db
end
class EventView < ApplicationRecord
  establish_connection :events_db
end

In my migration:

EventStat.connection.create_view :event_stats, materialized: true

But is does not work, or it creates the view on the wrong database.

Any ideas how I could make it work ?

Thanks.

@nthj
Copy link

nthj commented Jun 12, 2017

I think I might be missing something. In your example above, you reference Event and EventView, but your migration references EventStat. Does EventStat also have establish_connection :events_db, or should your migration look more like:

Event.connection.create_view :event_stats, materialized: true

@ombr
Copy link
Author

ombr commented Jun 12, 2017

Both Event and EventStats have establish_connection :events_db.
I am trying to create a view on another database for a table which is located on that other database.

In fact, Event.connection and EventStat.connection are the same connection to events_db.

Is that clear enough ?

@derekprior
Copy link
Contributor

We default to using the ActiveRecord::Base.connection in the adapter. You could override this, but it's not really meant to be changed at runtime. I think it could work, though. See the docs here: https://github.com/thoughtbot/scenic/blob/master/lib/scenic/adapters/postgres.rb#L25-L40

@epetre
Copy link

epetre commented Dec 22, 2023

So this gem doesn't support multiple databases from what I am gathering here. Would that be correct to assume?

@derekprior
Copy link
Contributor

Not directly, though that's something we'd like to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants