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

Multiple databases, main DB is assumed even though it's specified in the model. Is there a better way? #399

Open
epetre opened this issue Dec 22, 2023 · 1 comment

Comments

@epetre
Copy link

epetre commented Dec 22, 2023

One of our models is connecting to a warehouse DB since it's for reporting and not to serve the app features.
That model is based on a materialized view.

When refreshing, we currently can't use Scenic.database to connect to the database because it defaults to the main DB (it seems).
It's not a major issue since we can simply use the connection from the model, but I am wondering if scenic supports this and I am missing something or if it doesn't.

  # In one of my models
  
  def self.refresh
     Scenic.database.refresh_materialized_view(table_name, 
                                               concurrently: false, 
                                               cascade: false)
  end

Instead we have to do this workaround which works fine, but I wonder if there is a better way?

def self.refresh
  connection.execute("REFRESH MATERIALIZED VIEW #{table_name};")
end
@derekprior
Copy link
Contributor

This is probably something we need to look into as Scenic dates back to before multiple database support was properly added to Rails. What you have is fine, but I think in our own fix for this we'd want to keep the SQL abstracted from this point. I wonder if it would make more sense for us to inject the model's connection.

@calebhearth calebhearth added this to the 2.0 milestone Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants