scenic-views / scenic

Versioned database views for Rails
https://thoughtbot.com/blog/announcing-scenic--versioned-database-views-for-rails
MIT License
3.44k stars 224 forks source link

Support Rails' multiple database feature #402

Open derekprior opened 9 months ago

derekprior commented 9 months ago

For some time now, Rails has offered multiple database support. Scenic, however, operated with the assumption that there is one database, hanging its functionality off the singleton, Scenic.database. We should make the changes necessary to support multiple databases, which may have the added benefit of easily offering view path configurability as has been asked for by a number of folks.

I'm currently messing with multiple databases in a sample app and will use this issue to enumerate the changes I think we need to make.

leoplct commented 8 months ago

In the meanwhile, what workaround could I use to run Scenic on my secondary database?

joshfester commented 1 month ago

@leoplct I use Scenic in my primary database, but not in my cache database (SQLite). I was able to get rails db tasks to work by creating an initializer with this:

# Don't use Scenic in db tasks for SQLite
module CustomSchemaDumper
  def dumpable_views_in_database
    if ActiveRecord::Base.connection.adapter_name == "SQLite"
      []
    else
      super
    end
  end
end

# Don't use Scenic in db tasks for SQLite
module Scenic
  module SchemaDumper
    prepend CustomSchemaDumper
  end
end