Skip to content

`rake db:create` creates a schema when `schema_search_path` is specified #10140

Closed
wants to merge 1 commit into from

5 participants

@senny
Ruby on Rails member
senny commented Apr 8, 2013

Closes #3624

After this patch rake db:create will create a schema if schema_search_path is specified. Currently it only works if schema_search_path is a single schema. I've seen a couple of tickets related to schema_search_path so I first wanted to ask what format we actually support. If something like first, second is a valid schema_search_path of course I'd have to adjust the patch to create two schemas.

@senny
Ruby on Rails member
senny commented Apr 8, 2013
@rafaelfranca rafaelfranca was assigned Apr 30, 2013
@gregmolnar

This one looks good to me.

@akshay-vishnoi akshay-vishnoi commented on the diff May 3, 2014
.../lib/active_record/tasks/postgresql_database_tasks.rb
@@ -15,11 +15,16 @@ def initialize(configuration)
def create(master_established = false)
establish_master_connection unless master_established
connection.create_database configuration['database'],
- configuration.merge('encoding' => encoding)
+ configuration.merge('encoding' => encoding)

It was correct. Need indentation as this line defines the 2nd argument of connection.create_database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rafaelfranca
Ruby on Rails member

@senny please apply this patch.

@matthewd
Ruby on Rails member
matthewd commented May 5, 2014

I don't think we should do this, any more than we'd mkdir everything listed in ENV['PATH'] -- creating necessary schemata seems the responsibility of schema.rb / structure.sql. My recollection is that there's a version of PG that [inadvertently] produces the error mentioned in #3624, and other versions treat it as the warning it's intended to be. (And if we're going to encounter said error, won't it be in establish_connection, before we get here?)

That said, if we do want this change, we probably don't want to stop iterating the list as soon as we encounter a schema that exists.

There's also the possibility of quoted schema names (potentially including commas). And then there's the $user complication.

@rafaelfranca
Ruby on Rails member

How would schema.rb create the database schema if we can't even create the database because the schema configure in the databse.yml doesn't exist?

@matthewd
Ruby on Rails member
matthewd commented May 5, 2014

It's not (supposed to be) an error to set a search_path that contains a schema that doesn't exist.

% psql postgres
psql (9.3.1)
Type "help" for help.

[local]/postgres=# set search_path to lskdjflsdjf;
SET
[local]/postgres=# create table foo ();
ERROR:  no schema has been selected to create in
[local]/postgres=#
@rafaelfranca
Ruby on Rails member

If there is no error we can close both issues.

@matthewd
Ruby on Rails member
matthewd commented May 5, 2014

Apparently it was 9.1 that accidentally treated that situation as an error: postgres/postgres@880bfc3

And that was fixed in 9.1.4: postgres/postgres@35400e1

@rafaelfranca
Ruby on Rails member

Thank you for looking on it

@senny senny deleted the senny:3624_create_missing_schemas branch May 6, 2014
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.