Question

In a VPS I have Postgres installed and 2 Rails projects. Both are running on production mode and connecting PG as different users.

Now I want to set CruiseControl.rb for one of them. Everything went perfectly, except when cruise is trying to run the test it's throwing this error:

PGError: ERROR:  permission denied to create database
: CREATE DATABASE "myProject" ENCODING = 'utf8'

This test database is created with a different owner name, and all of them are specified correctly in ~/.cruise/projects/myProject/work/config/database.yml.

When I am running these following series of commands manually inside ~/.cruise/projects/myProject/work, they are working perfectly.

RAILS_ENV=test rake db:migrate
rake test

I've created the database using these following commands:

create user test_user with password 'abcxyz';
create database test_database TEMPLATE template0 owner test_user;
grant all privileges on database test_database to test_user;

After hitting the Build Now button, the test_database is getting deleted, and then its trying to create it again and throwing that exception.

I'm puzzled, why the test db is getting deleted on the first place? Is there anything I'm missing here?

Était-ce utile?

La solution

It sounds like you haven't granted access to your test user to create a new database, even though you issued permissions for the test_user on the existing test_database.

You may need to grant privileges to create a new DB like so:

GRANT CREATE ON SCHEMA public TO test_user;

The commands you executed before created the test_user and so must have been executed as an admin or the postgres user.

TL;DR

You should compare the permissions for your cruise user to the user you executed these steps with manually, something is wrong preventing the test db creation during db:test:prepare

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top