Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Create non-existing schema's as listed in database.yml on db:create #3624

Closed
brendon opened this Issue · 7 comments

5 participants

@brendon

I found this ticket on Lighthouse from 2008 regarding the automatic creation of PostgreSQL schemas defined in database.yml when db:create is called:

https://rails.lighthouseapp.com/projects/8994/tickets/1605-create-schema-during-rake-dbcreate-from-schema_search_path-if-it-does-not-exist-for-postgresql

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?

@frodsan

@brendon is this still an issue? If not, please close it.

@rafaelfranca

I think it is.

@brendon

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.

@steveklabnik
Collaborator

Any thoughts @jonleighton @tenderlove ?

@senny
Owner

I created a basic patch (not complete yet) so that rake db:create will also create schemas if schema_search_path is configured. #10140

@brendon brendon added the stale label
@rafaelfranca
Owner

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

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.

@rafaelfranca rafaelfranca removed the stale label
@rafaelfranca
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.