Search code examples
ruby-on-railstravis-cipostgresql-11

Travis CI not connecting to PostgreSQL 11.2


I'm having trouble with a build of a Rails application for a PostgreSQL 11.2 database.

Here's the .travis.yml file:

rvm:
  - 2.6.1
dist: xenial
services:
  - postgresql
addons:
  postgresql: "11.2"
  apt:
    packages:
      - postgresql-11
before_script:
  - psql --version
  - psql -c 'create database kpdotcom_test;' -U postgres
  - cp config/database.yml.travis config/database.yml
  - bundle exec rake db:schema:load

However, the build fails:

enter image description here

Any suggestions would be gratefully appreciated.


Solution

  • I had this problem too. Here's the config file that fixed it for me:

    This script:

    1. Shuts down all 9.* postgreSQL databases
    2. installs 11.2 (at the time of this writing)
    3. copies the authentication information from the old 9.6 configuration
    4. creates a role called "travis"
    language: ruby
    rvm: 2.6.2
    before_install:
      - sudo apt-get update
      - sudo apt-get --yes remove postgresql\*
      - sudo apt-get install -y postgresql-11 postgresql-client-11
      - sudo cp /etc/postgresql/{9.6,11}/main/pg_hba.conf
      - sudo service postgresql restart 11  
    before_script:
      - psql --version
      - psql -c 'CREATE DATABASE {{your database name here}};' -U postgres
      - psql -c 'CREATE ROLE travis SUPERUSER LOGIN CREATEDB;' -U postgres
      - cp config/database.yml.travis config/database.yml
    script: bundle exec rake spec
    services:
      - postgresql
    addons:
      postgresql: "11.2"