I found this ticket on Lighthouse from 2008 regarding the automatic creation of PostgreSQL schemas defined in database.yml when db:create is called:
It got shot down for some small reason and I wondered if things had changed significantly enough that it could now be added in?
Here's my use case: I have a schema_search_path defined in my database.yml file. When I run rake db:reset or db:setup I end up with an error because it created the database (but not the schema) and then tries to load seeds.rb which calls:
SET search_path TO some_value
The error is:
PGError: ERROR: invalid value for parameter "search_path": "some_value"
DETAIL: schema "some_value" does not exist
It'd be nice to be able to dump and reload the whole database with seeds (db:reset) but this currently isn't possible automatically when using schemas.
I've never done up a patch for Rails so if someone wanted to tackle this instead that would be cool. Otherwise some pointers on whether to change the rake file or the database adapter to achieve this outcome would be appreciated. I'm currently of the opinion that it'd be better done in the rake file as it is specific to db creation there. Though perhaps there is more to consider in how the test databases are created?
@brendon is this still an issue? If not, please close it.
I think it is.
Unless someone has patched this in another place, then yes it's still an issue. I haven't worked on the project that requires schema's since I put this ticket in so I'm not sure if it's still happening. I worked around it by adding custom rake tasks that created the schema's I needed after the database was initialized.
Any thoughts @jonleighton @tenderlove ?
`rake db:create` creates a schema when `schema_search_path` is specified
I created a basic patch (not complete yet) so that rake db:create will also create schemas if schema_search_path is configured. #10140
This issue has been automatically marked as stale because it has not been commented on for at least
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.
I'm closing this issue.
You should make sure the schema is create in the database through schema.rb or structure.sql before trying to use it. Also new versions of PostgreSQL doesn't raise error when trying to use a schema not existent yet (I tested with 9.2.4 and 9.3.1)