Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up Travis CI and postgresql using custom db credentials?

Tags:

travis-ci

I'm trying to set up custom Postgres credentials with Travis CI as I'd like to avoid the existing credentials definition in the code to be tested.

The testing code defines that the database should be accessed on:

'sqlalchemy.url': 'postgresql://foo:bar@localhost/testing_db'

I've therefore created a database.travis.yml file:

postgresql: &postgresql
adapter: postgresql
username: foo
password: bar
database: testing_db

...and added the following to my .travis.yml:

services:
  - postgresql

before_script:
  - psql -c 'create database stalker_test;' -U postgres
  - mkdir config && cp database.travis.yml config/database.yml

However, I am still getting this during testing:

OperationalError: (psycopg2.OperationalError) FATAL:  role "foo" does not exist

What am I doing wrong?

like image 967
fredrik Avatar asked Feb 11 '17 14:02

fredrik


1 Answers

Adding the following to .travis.yml solved my issue. No need for a database.travis.yml file.

before_script:
  - psql -c "CREATE DATABASE testing_db;" -U postgres
  - psql -c "CREATE USER foo WITH PASSWORD 'bar';" -U postgres
like image 112
fredrik Avatar answered Oct 12 '22 10:10

fredrik