0

i'm trying the db-migrate library to handle migration for my application but i can't seem to figure out how to connect to my local postgres database. Here're my configs: (I'm using postgres v13 on ubuntu 20.14)

// database.json
{
  "dev": {
    "driver": "pg",
    "user": "postgres",
    "password": "*****",
    "host": "localhost",
    "port": "5432",
    "schema": "public"
  }
}

I have a migration file

exports.setup = function(options, seedLink) {
  dbm = options.dbmigrate;
  type = dbm.dataType;
  seed = seedLink;
};

exports.up = function (db) {
  return db.createTable('users', {
    columns: {
      id: { type: 'int', primaryKey: true, autoIncrement: true },
      name: { type: 'string', notNull: true, unique: true,}
    },
    ifNotExists: true
  });
};

exports.down = function(db) {
  return db.dropTable('users');
};

exports._meta = {
  "version": 1
};

And then i try running npx db-migrate up and getting this error

[ERROR] AssertionError [ERR_ASSERTION]: ifError got unwanted exception: connect ETIMEDOUT 18.140.31.15:5432
at module.exports (/home/tom/Workspace/mark/node_modules/db-migrate/lib/commands/helper/assert.js:9:14)

I have no idea why it's trying to connect to 18.140.31.15 while my config file has stated the host to be localhost. Anyone has any idea what i'm doing wrong here ?

Tom
  • 107
  • 7
  • Another `database.json` file present that has the other host? – Adrian Klaver Aug 20 '21 at 17:26
  • Another thought, do you have `env` variables set for Postgres from another project? – Adrian Klaver Aug 20 '21 at 17:37
  • Nope `database.json` is the only file in this project. First time using db-migrate too. No i don't think i set any `env` variable for Postgres, on my other project i load the db connection as an url to AWS RDS as well. – Tom Aug 21 '21 at 16:54
  • To be sure about the `env`, in whatever session you are doing the migrate do: `env | grep PG` and see if any of these [Env variables] turn up? Is `18.140.31.15` by any change the host of your RDS? I'm betting it is as a `whois` shows that IP registered to AWS. Also betting you set up some AWS tools that in turn loaded `env` variables. – Adrian Klaver Aug 21 '21 at 17:06
  • Aaah, that should be chance not change. – Adrian Klaver Aug 21 '21 at 17:12
  • Also `db-migrate` can use [dotenv](https://www.npmjs.com/package/dotenv) so if there is a `.env` file in the project root it will take env variables from it. In my previous comment it should have been [Env variables](https://www.postgresql.org/docs/current/libpq-envars.html). – Adrian Klaver Aug 21 '21 at 20:36
  • I do have an `.env` file in my root project that i copied from my other project that points to RDS. Seems like it could be the problem. – Tom Aug 22 '21 at 04:52
  • Still it's strange that the cli would takes the `env` variables ahead of the config file. I'll investigate this later. – Tom Aug 22 '21 at 04:53
  • Yeah, that is something you will need to take up with the db-migrate folks. – Adrian Klaver Aug 23 '21 at 17:24

0 Answers0