Fix decimal on pg an mysql fix #1273

This commit is contained in:
Jim Laurie 2018-06-04 18:22:21 +02:00
parent 6de61bd2d6
commit c82ba4c089
2 changed files with 19 additions and 14 deletions

View File

@ -361,7 +361,7 @@ module.exports = function(strapi) {
type = definition.client === 'pg' ? 'double precision' : 'double'; type = definition.client === 'pg' ? 'double precision' : 'double';
break; break;
case 'decimal': case 'decimal':
type = 'decimal'; type = 'decimal(10,2)';
break; break;
case 'date': case 'date':
case 'time': case 'time':

View File

@ -78,8 +78,9 @@ module.exports = strapi => {
// Make sure the client is installed in the application // Make sure the client is installed in the application
// `node_modules` directory. // `node_modules` directory.
let client;
try { try {
require(path.resolve(strapi.config.appPath, 'node_modules', connection.settings.client)); client = require(path.resolve(strapi.config.appPath, 'node_modules', connection.settings.client));
} catch (err) { } catch (err) {
strapi.log.error('The client `' + connection.settings.client + '` is not installed.'); strapi.log.error('The client `' + connection.settings.client + '` is not installed.');
strapi.log.error('You can install it with `$ npm install ' + connection.settings.client + ' --save`.'); strapi.log.error('You can install it with `$ npm install ' + connection.settings.client + ' --save`.');
@ -105,18 +106,22 @@ module.exports = strapi => {
migrations: _.get(connection.options, 'migrations') migrations: _.get(connection.options, 'migrations')
}, strapi.config.hook.settings.knex); }, strapi.config.hook.settings.knex);
if (options.client === 'pg' && _.isString(_.get(options.connection, 'schema'))) { if (options.client === 'pg') {
options.pool = { client.types.setTypeParser(1700, 'text', parseFloat);
min: _.get(connection.options, 'pool.min') || 0,
max: _.get(connection.options, 'pool.max') || 10, if (_.isString(_.get(options.connection, 'schema'))) {
afterCreate: (conn, cb) => { options.pool = {
conn.query(`SET SESSION SCHEMA '${options.connection.schema}';`, (err) => { min: _.get(connection.options, 'pool.min') || 0,
cb(err, conn); max: _.get(connection.options, 'pool.max') || 10,
}); afterCreate: (conn, cb) => {
} conn.query(`SET SESSION SCHEMA '${options.connection.schema}';`, (err) => {
}; cb(err, conn);
} else { });
delete options.connection.schema; }
};
} else {
delete options.connection.schema;
}
} }
if (options.client === 'mysql') { if (options.client === 'mysql') {