I need help figuring out why I can't run knex migration on my local machine
using. It seems that knex has some trouble connecting to the postgres database. Running knex migration:latest in the terminal gives me this error:
⇒ knex migrate:latest
Using environment: development
Error: Unable to acquire a connection
at Client_PG.acquireConnection (/Users/moldot/prjx-albert/server/node_modules/knex/lib/client.js:332:40)
at Runner.ensureConnection (/Users/moldot/prjx-albert/server/node_modules/knex/lib/runner.js:233:24)
at Runner.run (/Users/moldot/prjx-albert/server/node_modules/knex/lib/runner.js:47:42)
at SchemaBuilder.Target.then (/Users/moldot/prjx-albert/server/node_modules/knex/lib/interface.js:39:43)
at Migrator._ensureTable (/Users/moldot/prjx-albert/server/node_modules/knex/lib/migrate/index.js:256:66)
at Migrator._listCompleted (/Users/moldot/prjx-albert/server/node_modules/knex/lib/migrate/index.js:405:17)
I'm using postgres on my local Macbook. This is my knexfile:
var PostgressConnectionStringParser = require('pg-connection-string');
module.exports = {
heroku: {
client: 'pg',
connection: process.env.DATABASE_URL,
migrations: {
directory: "migrations",
tableName: "migrations",
},
},
development: {
client: "pg",
host: "localhost",
port: 5432,
username: "moldot",
database: "c_dev",
migrations: {
directory: "migrations",
tableName: "migrations",
},
ssl: true,
},
}
Running psql works fine:
⇒ psql -h localhost -p 5432 -U moldot -d c_dev
psql (10.1, server 9.5.4)
Type "help" for help.
c_dev=#
I'm running the command in the same directory that knexfile.js is in. Thank you!
Your knexfile has an invalid syntax. You have not given the connection attribute there.
It should look like this:
module.exports = {
heroku: {
client: 'pg',
connection: process.env.DATABASE_URL,
migrations: {
directory: "migrations",
tableName: "migrations"
}
},
development: {
client: "pg",
connection: {
host: "localhost",
port: 5432,
username: "moldot",
database: "c_dev",
},
migrations: {
directory: "migrations",
tableName: "migrations"
}
}
}
Related
I'm working on a project for several months. Today I started getting this error: "Error [KnexTimeoutError]: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?".
I've seen other posts here on stackoverflow, that this was an issue with NODE14 and knex <8.0.3. I'm not using these versions, so I don't understand where this error comes from? Here some relevant info:
"next": "^10.2.3"
"pg": "^8.6.0"
knex": "^0.95.6"
The database is on heroku. I've checked the connections - there are connections available.
Here some relevant code:
knexfile.js
module.exports = {
development: {
client: 'pg',
connection: {
// filename: './dev.sqlite3'
database: process.env.DATABASE,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
host: process.env.DATABASE_HOST,
port: process.env.DATABASE_PORT,
}
},
production: {
client: 'postgresql',
connection: {
database: process.env.DATABASE,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
host: process.env.DATABASE_HOST,
port: process.env.DATABASE_PORT,
},
pool: {
min: 0,
max: 50
},
}
};
Can someone help me with this issue? The error comes and goes and I don't know how to solve this. Thanks!
I've been building a NodeJS/React app which connects to an MS SQL Server database. It was working fine, I uploaded it to the Windows hosting and it was working fine connecting to the dev database on a third party hosting company using this config file.
const Sequelize = require('sequelize');
const config = {
user: "myusername",
password: "mypassword",
server: "database_server",
database: "mydatabase",
options: {
enableArithAbort: true
},
};
const seqInstance = new Sequelize(
//
config.database,
config.user,
config.password,
{
dialect: "mssql",
host: config.server,
dialectOptions: {
encrypt: true,
options: {
validateBulkLoadParameters: true
}
},
}
);
module.exports = { seqInstance };
But when I try to connect to the production database which is on the same server, localhost, using this change to the config -
const config = {
user: "mynewusername",
password: "mynewpassword",
server: "localhost",
database: "myproductiondatabase",
options: {
enableArithAbort: true
},
};
it refuses to connect and throws this error.
There are other app on the server connecting to that localhost sql server databases. Why is this small change not working?
I'm trying to run sequelize-cli, specifically npx sequelize db:migrate.
I've created a config file in config/config.js which looks like this (obviously with correct credentials):
module.exports = {
development: {
username: "USER",
password: "PASSWORD",
database: "DB_NAME",
host: "HOST.net",
dialect: 'mssql',
dialectOptions: {
encrypt: "true" // bool - true - doesn't work either
}
}
};
However I'm receiving the following error:
ERROR: Server requires encryption, set 'encrypt' config option to true.
As you can see from my config I believe I have set encrypt to true. This is my understanding of how to set this option from the docs.
How can I successfully set encrypt to true?
This should fix the issue,
module.exports = {
development: {
username: "USER",
password: "PASSWORD",
database: "DB_NAME",
host: "HOST.net",
dialect: 'mssql',
dialectOptions: {
options: {
encrypt: true
}
}
}
};
I have a node.js application where one of the views is a ghost.js blog, which I integrated by following Ghost's wiki article Using Ghost as an npm module.
Currently, my local version works perfectly.
The Error:
When I visit the deployed website, everything works ok, except when I got to mysite.heroku.com/blog, at which point I get the ghost page looking like .
I've noticed that the application has two localhost branches running simultaneusly (localhost:3000 and localhost:2368/). I'm not sure if that could be causing the error. I've checked out my Herokulogs, and they do not provide any more details than that a GET request was sent to /blog, returning first a 301and then a 404 error.
Also, it might be useful to know that when I click on the Go to front page link it sends me to http://localhost:2368/
My config.js file looks like the following:
var path = require('path'),
config;
config = {
// ### Production
// When running Ghost in the wild, use the production environment
// Configure your URL and mail settings here
production: {
url: 'http://example.com/blog',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},
server: {
// Host to be passed to node's `net.Server#listen()`
host: '127.0.0.1',
// Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
port: '2368'
}
},
// ### Development **(default)**
development: {
// The url to use when providing links to the site, E.g. in RSS and email.
// Change this to your Ghost blogs published URL.
url: 'http://localhost:2368/blog',
// Example mail config
// Visit http://support.ghost.org/mail for instructions
// ```
// mail: {
// transport: 'SMTP',
// options: {
// service: 'Mailgun',
// auth: {
// user: '', // mailgun username
// pass: '' // mailgun password
// }
// }
// },
// ```
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost-dev.db')
},
debug: false
},
server: {
// Host to be passed to node's `net.Server#listen()`
host: '127.0.0.1',
// Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
port: '2368'
},
paths: {
contentPath: path.join(__dirname, '/content/')
}
},
// **Developers only need to edit below here**
// ### Testing
// Used when developing Ghost to run tests and check the health of Ghost
// Uses a different port number
testing: {
url: 'http://127.0.0.1:2369',
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost-test.db')
}
},
server: {
host: '127.0.0.1',
port: '2369'
},
logging: false
},
// ### Testing MySQL
// Used by Travis - Automated testing run through GitHub
'testing-mysql': {
url: 'http://127.0.0.1:2369',
database: {
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'root',
password : '',
database : 'ghost_testing',
charset : 'utf8'
}
},
server: {
host: '127.0.0.1',
port: '2369'
},
logging: false
},
// ### Testing pg
// Used by Travis - Automated testing run through GitHub
'testing-pg': {
url: 'http://127.0.0.1:2369',
database: {
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'postgres',
password : '',
database : 'ghost_testing',
charset : 'utf8'
}
},
server: {
host: '127.0.0.1',
port: '2369'
},
logging: false
}
};
// Export config
module.exports = config;
It looks like Ghost is configured via a config.js file (see the link you provided), and that you may have it configured for url: 'http://localhost:2368/blog'. Looks like you'll need to change that to your actual URL.
Also, see this https://github.com/cobyism/ghost-on-heroku
The issue I have is related to the following quote from the official documentation:
Note If any connection to an adapter is used by a model, then all connections to that adapter will be loaded on sails.lift, whether or not models are actually using them. In the example above, if a model was configured to use the localMysql connection, then both localMysql and remoteMysql would attempt to connect at run time. It is therefore good practice to split your connection configurations up by environment and save them to the appropriate environment-specific config files, or else comment out any connections that you don't want active.
How can you configure the connection for a production server?
My connections.js file looks like this:
module.exports.connections = {
mongoDev: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: 'username',
password: 'password',
database: 'database'
},
mongoLive: {
adapter: 'sails-mongo',
host: 'host.mongolab.com',
port: 31681,
user: 'user',
password: 'password',
database: 'database'
}
};
And in my environment config files I've got:
development.js
module.exports = {
models: {
connection: 'mongoDev'
}
};
production.js
module.exports = {
models: {
connection: 'mongoLive'
},
port: 3000,
};
This works on my local machine, because the production database server is on an external server.
On the production environment I'm getting the following error:
[Error: failed to connect to [localhost:27017]]
It works if I remove the mongoDev object from my the connections object.
I've also tried using adaptors.js, but this only resulted in some deprecation errors.
$ sails -v
info: v0.9.9
I'm getting something different when running sails lift:
info: Sails
info: v0.10.5
You want to save the actual connection definition in the either development.js or production.js and remove them from connections.js. It's a little non-intuitive.
development.js
module.exports = {
connections : {
mongoDev: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: 'username',
password: 'password',
database: 'database'
}
},
models: {
connection: 'mongoDev'
}
};
production.js
module.exports = {
connections : {
mongoLive: {
adapter: 'sails-mongo',
host: 'host.mongolab.com',
port: 31681,
user: 'user',
password: 'password',
database: 'database'
}
},
models: {
connection: 'mongoLive'
},
port: 3000,
};