0

Here's the output: https://travis-ci.org/maxdobeck/gateway/jobs/373773101.

Why am I getting this error: error: relation "members" does not exist

I am able to use a .sql file to create the tables that I need but when it comes time to run tests the database says the tables don't exist? Am I configuring the database correction incorrectly?

amishpanda
  • 91
  • 1
  • 8
  • Are you sure that the script is connecting to the db `travis`? My first guess would be that you're either looking for the tables either in a wrong database or wrong schema. – Jim Jones May 02 '18 at 05:46
  • That's what I've been leaning towards. I just now saw the "Raw Log" button and when I pass in: `$ psql -U postgres -d scheduler -c '\dt;'` I get "No relations found". So I must not be connecting to the correct database when I create my tables. Unsure how to verify but now that I can test stuff with the raw log that helps. – amishpanda May 02 '18 at 06:00
  • can you check in these scripts if it is the case? https://travis-ci.org/maxdobeck/gateway/jobs/373773101#L481 I cant see their content – Jim Jones May 02 '18 at 06:01
  • https://travis-ci.org/maxdobeck/gateway Got the green light! It was technically the Create tables script. I was using the generate_uuid function like so:https://stackoverflow.com/questions/12505158/generating-a-uuid-in-postgres-for-insert-statement#12505220 adding the `create extension` line did the trick. This error was pointing to real root cause: `psql:./db/migrations/travis_setup.sql:11: ERROR: function uuid_generate_v4() does not exist HINT: No function matches the given name and argument types. You might need to add explicit type casts.` – amishpanda May 02 '18 at 06:07
  • awesome! good luck with your project :) – Jim Jones May 02 '18 at 06:09

2 Answers2

0

It was technically the Create tables script. I was using the generate_uuid function like in this SO post

Adding the create extension line did the trick.

This error was pointing to real root cause:

ERROR: function uuid_generate_v4() does not exist HINT: No function matches the given name and argument types. You might need to add explicit type casts.

amishpanda
  • 91
  • 1
  • 8
0

I had this same problem and I just fixed it. The problem is probably because travis cannot create the table which in your case is members. You need to add the following lines in your .travis.yaml file

    before_script:
  - psql -c "create database yourdbname;" -U postgres
  - psql -c "create user dbusername WITH PASSWORD 'yourpassword';" -U postgres

create a script that contains the query for creating the table. mine resembles something like this.

const pg = require('pg');

const config = {
  user: 'yourdbusername', // this is the db user credential
  database: 'yourdb',
  password: 'yourdbpass',
  port: 5432,
  max: 10, // max number of clients in the pool
  idleTimeoutMillis: 30000
};
const pool = new pg.Pool(config);

pool.on('connect', () => {
  console.log('connected to the Database');
});

/**
 * Create Tables
 */
const createTables = () => {
  const queryText = `your query`;

  pool
    .query(queryText)
    .then(res => {
      console.log(res);
      pool.end();
    })
    .catch(err => {
      console.log(err);
      pool.end();
    });
};

pool.on('remove', () => {
  console.log('client removed');
  process.exit(0);
});

module.exports = {
  createTables,
  pool
};
require('make-runnable');

it will be preferable to make use of a remote database like elephantSQL or any other remote postgres db. Go to your package.json and add the following line under scripts

    "create": "node ./path/to/the/file createTables",

Now update your before_script to this

before_script:
  - psql -c "create database wayfarer;" -U postgres
  - psql -c "create user wayfarer WITH PASSWORD 'rrwcscrz1';" -U postgres
  - "npm run create" 

Also make sure you'vev installed make-runnable and pg packages

SirG
  • 91
  • 2
  • 5