Filipe Pinheiro
Filipe Pinheiro

Reputation: 53

I am having this Issue when trying to deploy my API to heroku

I've installed the PostgreSQL add-on from Heroku, but I am using Knex.js on my backend, as I was using before with SQLite and I'm having the following error.

I was building a backend for a site and mobile app and tried to deploy it to Heroku, when in development I was using SQLite, but figured that since I was using Knex.js, I could easily transfer to Postgres add-on from Heroku. I am running into this problem, when running knex migrate:latest on postbuild.

no such file or directory, scandir '/tmp/build_46fb7aa66e7e3cea06d2f04a21ad9249/migrations'

Here is my knex file:

// Update with your config settings.

module.exports = {

  development: {
    client: 'sqlite3',
    connection: {
      filename: './src/database/db.sqlite'
    },
    migrations: {
      directory: './src/database/migrations'
    },
    useNullAsDefault: true
  },


  test: {
    client: 'sqlite3',
    connection: {
      filename: './src/database/test.sqlite'
    },
    migrations: {
      directory: './src/database/migrations'
    },
    useNullAsDefault: true
  },

  staging: {
    client: 'postgresql',
    connection: {
      database: 'my_db',
      user:     'username',
      password: 'password'
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    }
  },

  production: {
    client: 'pg',
    debug: true,
    connection: process.env.DATABASE_URL,
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    },
    ssl: true
  }

};

and my connections

const knex = require('knex')
const configuration = require('../../knexfile')

const config = process.env.NODE_ENV


const connection = knex(configuration[config])


module.exports = connection

The migrations for test and development are working just fine

I don't know either if this is going to work after that, so if anyone has any experience I could use any help

Upvotes: 0

Views: 263

Answers (1)

Chris
Chris

Reputation: 137159

It looks like Heroku can't find your migrations.

Your production configuration doesn't appear to contain a migrations directory. Try adding it, e.g.

  production: {
    client: 'pg',
    debug: true,
    connection: process.env.DATABASE_URL,
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations',
      directory: './src/database/migrations'  // <-- here
    },
    ssl: true
  }

when in development I was using SQLite, but figured that since I was using Knex.js, I could easily transfer to Postgres add-on from Heroku

I urge you to use the same database in both development and production. Database engines aren't drop-in replacements for each other, even if you are using something like Knex.

Upvotes: 1

Related Questions