Fix inconsistency between knexfile and runtime knex config
parent
8ba25d9504
commit
77cb19e70c
|
@ -1,2 +1,2 @@
|
|||
const config = require('./src/cfg');
|
||||
module.exports = config.knex;
|
||||
const knexConfig = require("./src/knexConfig");
|
||||
module.exports = knexConfig;
|
||||
|
|
47
src/knex.js
47
src/knex.js
|
@ -1,45 +1,2 @@
|
|||
const path = require("path");
|
||||
const config = require("./cfg");
|
||||
|
||||
let knexOptions;
|
||||
if (config.dbType === "sqlite") {
|
||||
const resolvedPath = path.resolve(process.cwd(), config.sqliteOptions.filename);
|
||||
console.log(`Using an SQLite database:\n ${resolvedPath}`);
|
||||
|
||||
knexOptions = {
|
||||
client: "sqlite",
|
||||
connection: {
|
||||
...config.sqliteOptions,
|
||||
},
|
||||
};
|
||||
} else if (config.dbType === "mysql") {
|
||||
const host = config.mysqlOptions.host || "localhost";
|
||||
const port = config.mysqlOptions.port || 3306;
|
||||
const mysqlStr = `${config.mysqlOptions.user}@${host}:${port}/${config.mysqlOptions.database}`;
|
||||
console.log(`Using a MySQL database:\n ${mysqlStr}`);
|
||||
|
||||
knexOptions = {
|
||||
client: "mysql2",
|
||||
connection: {
|
||||
...config.mysqlOptions,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = require("knex")({
|
||||
...knexOptions,
|
||||
|
||||
useNullAsDefault: true,
|
||||
migrations: {
|
||||
directory: path.resolve(__dirname, "..", "db", "migrations"),
|
||||
},
|
||||
log: {
|
||||
warn(message) {
|
||||
if (message.startsWith("FS-related option specified for migration configuration")) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.warn(message);
|
||||
},
|
||||
},
|
||||
});
|
||||
const knexConfig = require("./knexConfig");
|
||||
module.exports = require("knex")(knexConfig);
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
const path = require("path");
|
||||
const config = require("./cfg");
|
||||
|
||||
let knexOptions;
|
||||
if (config.dbType === "sqlite") {
|
||||
const resolvedPath = path.resolve(process.cwd(), config.sqliteOptions.filename);
|
||||
console.log(`Using an SQLite database:\n ${resolvedPath}`);
|
||||
|
||||
knexOptions = {
|
||||
client: "sqlite",
|
||||
connection: {
|
||||
...config.sqliteOptions,
|
||||
},
|
||||
};
|
||||
} else if (config.dbType === "mysql") {
|
||||
const host = config.mysqlOptions.host || "localhost";
|
||||
const port = config.mysqlOptions.port || 3306;
|
||||
const mysqlStr = `${config.mysqlOptions.user}@${host}:${port}/${config.mysqlOptions.database}`;
|
||||
console.log(`Using a MySQL database:\n ${mysqlStr}`);
|
||||
|
||||
knexOptions = {
|
||||
client: "mysql2",
|
||||
connection: {
|
||||
...config.mysqlOptions,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
...knexOptions,
|
||||
|
||||
useNullAsDefault: true,
|
||||
migrations: {
|
||||
directory: path.resolve(__dirname, "..", "db", "migrations"),
|
||||
},
|
||||
log: {
|
||||
warn(message) {
|
||||
if (message.startsWith("FS-related option specified for migration configuration")) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.warn(message);
|
||||
},
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue