Open mhw opened 4 years ago
Hmmm, yeah. I like the direction you took with NewConfiguration
in your sample repository, but that's a breaking change.
I wonder if we can think of a way to enable this in a non-breaking way? Or perhaps this just has to be 2.0?
Hi! Thanks for looking it over.
I'd tried to extend Configuration
in a way that would not break existing code: providing a database=
writer and if that is used the database
method reverts to its previous behaviour. What usage are you thinking of that this would break?
(It might not be clear, but I'd intended the body of NewConfiguration
to replace the Configuration
class, as in this commit. For what it's worth, with that change in place the test suite passes unchanged.)
Any updates on Rails 6 multi-database support? I'll be testing with the branch from @mhw but would certainly prefer to use the official gem.
@hopsoft: In the project where I need this working I've been using scenic 1.5.4 along with the initializer without any issues. I'd suggest going that route as I've not kept my fork up to date.
@mhw Hi! I am liking this gem very much, however I have one issue related to this thread. I have a Rails 6 app that has a second database configured. I am able to simply move the generated migration file for a given view to the correct folder (e.g. db/migrate/secondary_db
) and migration will create view for that db. However, the second part of the migration fails because it does not support similar pattern for the sql view files in db/views
directory.
Is there a workaround for this? Thanks!
@rquant Not that I'm aware of, I'm afraid. My project only required migrations run against the primary PostgreSQL database so I didn't go as far as that. I'm sure it would be feasible but it would take some digging through the Rails source to figure out how to implement it.
It's always been possible to have connections to multiple databases of different types specified in
database.yml
and used throughestablish_connection
. In Rails 6 this was expanded to support primary and replica databases, with a new 3-layer configuration style indatabase.yml
and enhancements to the rake tasks to manage multiple databases.It's also possible to use this 3-layer configuration style with databases of different types - for example, mixing Postgres and MySQL in a legacy recovery project. The pg-mysql branch of this sample project shows how this can be done. However this set up breaks the rake
db:migrate
task as the schema dumper attempts to treat the MySQL database as though it were Postgres. An excerpt from the error that results:The issue is that
Scenic.database
is a singleton, and the schema dumper additions assume it will always be possible to callviews
on it. The Rails database tasks now change theActiveRecord::Base.connection
to run migrations and the schema dumper against each database listed indatabase.yml
. In the test app above this results in Scenic's Postgres adapter being used with a MySQL database connection, hence the error.As
Scenic.database
is also really part of the Scenic public API (here for example), the best option I've come up with is to extend theConfiguration
class along the lines of the initializer on the master branch. I've also added aNullAdapter
which gives the flexibility to work with database connections where Scenic is not used, as on the pg-mysql-fix branch.I wanted to check the overall direction here before submitting a pull request along these lines. Does this look like a reasonable addition?