-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
migration fails in Rails 6 project with multiple database types #291
Comments
Hmmm, yeah. I like the direction you took with 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 (It might not be clear, but I'd intended the body of |
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. 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?
The text was updated successfully, but these errors were encountered: