Droping and creating test database
dawidp opened this issue · 3 comments
On clean install of Debian on vm everything works fine but on my laptop where I have postgresql setup with passwords I've manually created the databases and then executed rake test
and it failed with:
rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: permission denied to create database
: CREATE DATABASE "kikiri_test" ENCODING = 'unicode'
So my question: is it really required to drop & create database? Can't we just drop all the tables ?
Hi, the behavior of rake test
is controlled by Rails, and is not specific to this template. Generally it is not something you or I can control.
In my experience, to be able to run tests for a Rails app on PostgreSQL, you will need to be a super user of the database. Rails does things like disable constraints when loading fixtures, something than an unprivileged user normally is not allowed to do.
Anyway, it looks like the error you pasted is about failure to create the database, not drop it. My guess is that your database.yml
does not have the correct database name and password for the test
environment.
Make sure you've created the database (e.g. using PostgreSQL's createdb
) with the exact name Rails expects (kikiri_test
in this case), and that your database.yml has the correct username and password.
Anyway, it looks like the error you pasted is about failure to create the database, not drop it. My guess is that your
database.yml
does not have the correct database name and password for thetest
environment.
Nope. I've created the databases after issuing \l
I can see them, but after running rake test
that fails with above error the database kikiri_test
doesn't exists anymore. So during rake test
the database is dropped...
Hi, the behavior of rake test is controlled by Rails, and is not specific to this template. Generally it is not something you or I can control.
Darn... Oh well, I'm coming from MySQL where databases weren't dropped. I think the best solution will be to allow this user to create databases.
Anyway thanks for great template. 👍
Ah, you're right. it looks like if there is a pending migration, Rails now drops the test database and recreates it from schema.rb
. Not sure whether it's PostgreSQL-specific, though.