New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knex doesn't accept string parameters passed by Heroku #2570

Closed
go-on-blog opened this Issue Apr 14, 2018 · 6 comments

Comments

Projects
None yet
5 participants
@go-on-blog

go-on-blog commented Apr 14, 2018

When I run this command:

$ heroku run "knex-migrator init"

I get the following error:

Running knex-migrator init on ⬢ my-app... up, run.6370 (Free)
[2018-03-31 07:47:54] ERROR

MESSAGE: Tarn: opt.max must be an integer > 0

Error: Tarn: opt.max must be an integer > 0
    at new Pool (/app/node_modules/tarn/lib/Pool.js:29:13)
    at Client_MySQL.initializePool (/app/node_modules/knex/lib/client.js:306:17)
    at Client_MySQL.Client (/app/node_modules/knex/lib/client.js:117:12)
    at new Client_MySQL (/app/node_modules/knex/lib/dialects/mysql/index.js:62:20)
    at Knex (/app/node_modules/knex/lib/index.js:60:34)
    at Object.connect (/app/node_modules/knex-migrator/lib/database.js:25:12)
    at KnexMigrator.init (/app/node_modules/knex-migrator/lib/index.js:83:32)
    at /app/node_modules/knex-migrator/bin/knex-migrator-init:24:29
    at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/app/node_modules/bluebird/js/release/promise.js:638:18)
    at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:582:21)
    at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:614:10)

I am using ghost@1.21.6 and a ClearDB database installed this way:

$ heroku addons:create cleardb:ignite
$ heroku config:set \
database__connection__user=... \
database__connection__password=... \
database__connection__host=... \
database__connection__database=...

$ heroku config:set database__pool__max=2

According to the answer I received from knex-migrator when filing a bug, the issue could be between heroku and knex: the database__pool__max value would be passed as a string by heroku but not converted to integer by knex.

I am wondering how Ghost/Heroku deployment procedures I have found (like this) could work with such an issue.

Did anybody else encounter the same issue?

Environment

Knex-migrator version: 3.1.5
Knex version: 0.14.4
Database + version: ClearDB MySQL
OS: Ubuntu 16.04

@elhigu

This comment has been minimized.

Collaborator

elhigu commented Apr 14, 2018

Yup, tarn is very strict about passed parameters, and knex client doesn't have pretty much any tests so it seems to be broken.

https://github.com/Vincit/tarn.js/blob/master/lib/Pool.js#L28

Indeed sounds like knex bug, that it is passing pool.max as string.

@sdhawley

This comment has been minimized.

sdhawley commented Apr 21, 2018

The issue isn't really knex or knex-migrator, Ghost provides the config to knex-migrator and should be providing it with the correct type. The knex docs are plenty clear that it expects a number type for pool.max. Ghost uses nconf to parse the environment variables, its a simple fix to have nconf parse the data types. I've verified with a heroku Ghost deploy of my own that it works.

Make a change in core/server/config/index.js around line 30 to add parseValues: true to the nconf.env config

nconf.env({
   separator: '__',
   parseValues: true
});
@elhigu

This comment has been minimized.

Collaborator

elhigu commented Apr 23, 2018

@sdhawley thanks for investigating more, sounds like this is not knex bug after all then.

@elhigu elhigu closed this Apr 23, 2018

@aldavies

This comment has been minimized.

aldavies commented Apr 26, 2018

@sdhawley how did you change that file and not have heroku get rid of changes when editing it, it appears that when you exit the dyno it destroys the changes

@sdhawley

This comment has been minimized.

sdhawley commented Apr 26, 2018

@aldavies I edited the file in my local repo, committed it, and then pushed to heroku. Not sure what your setup looks like but if you don't have the change saved in the git repo it won't persist.

@svsamipillai

This comment has been minimized.

svsamipillai commented Aug 13, 2018

@sdhawley Make the changes to core/server/config/index.js and push it to your repository.

You need to add the 'parseValues:true' property.

nconf.env({
   separator: '__',
   parseValues: true
});

kandluis added a commit to Omnistyle/thebookbabe that referenced this issue Sep 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment