2023-03-21 06:53:39 +00:00
|
|
|
const config = require('./lib/config');
|
2020-02-19 04:55:06 +00:00
|
|
|
|
|
|
|
if (!config.has('database')) {
|
2023-03-21 06:53:39 +00:00
|
|
|
throw new Error('Database config does not exist! Please read the instructions: https://nginxproxymanager.com/setup/');
|
2020-02-19 04:55:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 14:43:01 +00:00
|
|
|
function generateDbConfig() {
|
2023-03-21 06:53:39 +00:00
|
|
|
const cfg = config.get('database');
|
|
|
|
if (cfg.engine === 'knex-native') {
|
|
|
|
return cfg.knex;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
client: cfg.engine,
|
|
|
|
connection: {
|
|
|
|
host: cfg.host,
|
|
|
|
user: cfg.user,
|
|
|
|
password: cfg.password,
|
|
|
|
database: cfg.name,
|
|
|
|
port: cfg.port
|
|
|
|
},
|
|
|
|
migrations: {
|
|
|
|
tableName: 'migrations'
|
|
|
|
}
|
|
|
|
};
|
2020-07-19 14:43:01 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 06:53:39 +00:00
|
|
|
module.exports = require('knex')(generateDbConfig());
|