How to configure Travis CI and postgresql using custom db credentials?

I am trying to configure Postgres user credentials using Travis CI, as I would like to avoid defining existing credentials in the test code.

The test code determines which database should be accessed:

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

So I created a file database.travis.yml:

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

... and added to my .travis.ymlfollowing:

services:
  - postgresql

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

However, I still get this during testing:

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

What am I doing wrong?

+4
source share
2 answers

Adding the following to .travis.ymlresolved my problem. No need for file database.travis.yml.

before_script:
  - psql -c "CREATE DATABASE testing_db;" -U postgres
  - psql -c "CREATE USER foo WITH PASSWORD 'bar';" -U postgres
+6
source

Database.yml Ruby On Rails. Travis CI /, docs .

, , script , travis, .

0

Source: https://habr.com/ru/post/1669462/


All Articles