This project is archived and is in readonly mode.
databases.rake forcing database and schema with postgres
-
Shak
It seems that this is based on a much larger assumption about how your postgresql database is structured, assumptions which do not apply in general development and migration etc (ownership of databases etc).
I've decided to just manage initialisation myself, although I do think that the test database should have the same requirements as prod and dev.
-
Shak
For anyone interested, more info and workarounds here:
-
Rizwan Reza
- State changed from new to open
- Assigned user set to Rizwan Reza
- Milestone cleared.
-
Harold Giménez
I don't think this is a problem or bug at all. Every postgres database cluster will have three databases by default: postgres, template0 and template1. When doing administrative work, you probably do want to connect to the postgres database (or one of the templates) just so you can drop and create other databases. In other words, if you connect to my_app_development and try to drop my_app_development, postgres will probably complaint.
-
Rizwan Reza
Shak and Harold, can we close this ticket then?
-
Harold Giménez
My vote is to close it. Although I'd like to hear from Shak if there are examples of this actually causing a problem? Some rake task that you could not run because of this?
To add to the story, I think this is necessary in order for rake db:create to work. Otherwise the postgres adapter will try to connect to my_app_development in order to create my_app_development. You see the chicken and egg there? Therefore you need to connect to the admin DB first in order to create your app's databases.
But as I said, I'd really like to hear how this breaks.
-
Shak
Everything works provided you have a single schema per single database per single Rails app. It's probably just my usage, but my database can have other related schemas in it, those not managed by Rails. These are required since Postgres doesn't allow cross DB queries. As such my rails user in production shouldn't be allowed to drop anything other than its own schema, and this should be reflected in dev and test too. This is why the default rake tasks do not work for me.
Also generally, I'm not sure it's proper to allow an application user access to the any database other than its own, but I will concede if Rails' opinion differs on that.
Based on the links above I've patched my own database.rake to drop and create schemas instead of databases and it seems to be working quite well. I'm happy to contribute this, but as a novice Rails user I have no idea how to or whether it breaks anything else.
I've recognised this as non-Rails usage so this ticket doesn't need to be reopened, however I do think switching to a schema aware model would bring added benefits to those using Postgres as their storage.