Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use 'public' schema path when connecting to 'postgres' database. [#170 …
…state:resolved] Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
- Loading branch information
Showing
1 changed file
with
2 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to connect to a postgres schema other than "public" within my test environment, but it seems ActiveRecord is overwriting the schema_search_path to "public" due to this commit - inconvenient. I have a very complex postgres database which requires schemas for adequate testing.
Link to original bug: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/170-postgresql-update-rake-tasks-to-use-full-settings-from-database-yml-bugfix
3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These connections are only used for creating and dropping a database and the connections aren't even made to your configured database but to the 'postgres' database which is expected to have the 'public' schema. https://rails.lighthouseapp.com/projects/8994/tickets/170
3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if someone has to deal with a legacy postgres db which actually has some schema other than public? I could submit a patch to the database task to figure the schemas needed to be re-created, but I am not sure whether there isn't a very good reason to do so that I am not aware of (since it should be a pretty easy and useful thing to do). If someone can clarify why this feature is not already available, I am willing to put some work into it.
3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance that this issue gets looked up and re-opened? Otherwise
rake test:units
is simply not usable.3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicb would changing the search path based on environment variable be acceptable? I would accept a patch for that. :-)
3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would definitely think so, since there is already a
schema_search_path
key in theconfig/database.yml
, that key could indeed be re-used in the rake task instead of flattening it topublic
. I will give it a try as soon as I get a chance to do it and report back (and provide a patch if I get to somewhere functional).3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicb Sorry I couldn't be of more help here. Wondering about your legacy database though, why does it not have a 'public' schema in the 'postgres' database, was the database created before postgresql implemented schemas, or was another schema name intentionally used? Any reason you can't just create an empty 'public' schema for the 'postgres' database? (in case it isn't clear, the schema is just needed to connect to postgresql, it has nothing to do with the specific database for rails that is being created or deleted using that connection).
3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The database I'm working with has already been in production for several years. They had an 'old implementation' of the database in the
public
schema, and they did a new implementation using a different schema name. That sounds silly perhaps, but 'they' is somebody I don't know so I can't even ask why they did it this way. Since I cannot change the structure of the production database, I have two options:public
) for the testing suiteI could easily do (1) but I don't think it is the correct way to go. If the ruby pg adapter supports schemas and the rails implementation supports schemas (which it does, since you can define them in configuration), then we should be able to run tests on the database configured for tests as it is for production. Also because otherwise these tests are missing one important point which could crop up in production.
I am starting to think how to fix it. The super-easiest fix of them all is to set an environment variable like:
I don't know if that is enough to actually do the job properly. I am proposing it here to you before checking it to bar probable naiveties on my side.
3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other option is that we could have a
schema
section in the configuration file. Rails could use the regular settings (the current defaults), or override if aschema
configuration is present. Having a schema configuration would probably be cleaner, but I'm fine with an environment variable too.3fee237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicb could you try if just removing the 'schema_search_path' from the establish_connection line make this work for you? In shouldn't really matter what the schema search path is while running "create database" and "drop database" queries.