DATABASE_URL being ignored

I have the following 2.0 config:

version: 2
jobs:
  build:
    docker:
      - image: circleci/ruby:2.4.1-node
        environment:
          RAILS_ENV: test
          DATABASE_URL: postgresql://circleci:circleci@127.0.0.1:5432/test_db
      - image: circleci/postgres:9.6-postgis-ram
        environment:
          POSTGRES_DB: test_db
          POSTGRES_USER: circleci
          POSTGRES_PASSWORD: circleci
    steps:
      - checkout
      - run: bundle install
      - run: bundle exec rails db:schema:load
      - run: bundle exec rails test:app

When the container boots for postgres, I get the error:

FATAL: role “rolename” does not exist

Job was canceled

The rolename is from database.yml config, yet I have set DATABASE_URL and RAILS_ENV so it should be using those.

I have ssh’d in to the box to check the env variables which are all as expected.

$ rails c
$ puts ENV[‘DATABASE_URL’]
postgresql://circleci:circleci@127.0.0.1:5432/test_db
$ puts ENV[‘RAILS_ENV’]
test

Should Rails prefer environment variables to the database.yml config file?

It will merge the 2 configs and overwrite in favour of the ENV variable

Fair enough. Just to check, you could add a run after your checkout to echo $DATABASE_URL, just to see if there are any gremlins getting in the way of setting these vars. :smirk_cat:

It echos what I would expect postgresql://circleci:circleci@127.0.0.1:5432/test_db

Hmm. I am not familiar with Rails at all - is there any way you can find out why it is ignoring this value? Is the logic to do this in Ruby itself, where you could add some cheeky debug statements using nano? If you SSH into the box and try to run Ruby stuff, does it behave in the same was as an automatic build on code push?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.