diff --git a/packages/strapi-hook-bookshelf/lib/index.js b/packages/strapi-hook-bookshelf/lib/index.js index ff0d8fc8d0..5d4ddbc11c 100755 --- a/packages/strapi-hook-bookshelf/lib/index.js +++ b/packages/strapi-hook-bookshelf/lib/index.js @@ -456,15 +456,15 @@ module.exports = function(strapi) { }, start); }; - const generateIndexes = async (table, attrs) => { + const generateIndexes = async (table) => { try { const connection = strapi.config.connections[definition.connection]; let columns = Object.keys(attributes).filter(attribute => ['string', 'text'].includes(attributes[attribute].type)); switch (connection.settings.client) { - case 'pg': + case 'pg': { // Enable extension to allow GIN indexes. - await ORM.knex.raw(`CREATE EXTENSION IF NOT EXISTS pg_trgm`); + await ORM.knex.raw('CREATE EXTENSION IF NOT EXISTS pg_trgm'); // Create GIN indexes for every column. const indexes = columns @@ -479,6 +479,8 @@ module.exports = function(strapi) { await Promise.all(indexes); break; + } + default: columns = columns .map(attribute => `\`${attribute}\``) @@ -685,9 +687,8 @@ module.exports = function(strapi) { ), table => { return _.snakeCase( - pluralize.plural(table.collection) + - ' ' + - pluralize.plural(table.via) + // eslint-disable-next-line prefer-template + pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via) ); } ).join('__'); @@ -704,7 +705,7 @@ module.exports = function(strapi) { resolve(); })); } catch (err) { - strapi.log.error('Impossible to register the `' + model + '` model.'); + strapi.log.error(`Impossible to register the '${model}' model.`); strapi.log.error(err); strapi.stop(); } @@ -822,9 +823,8 @@ module.exports = function(strapi) { ), table => { return _.snakeCase( - pluralize.plural(table.collection) + - ' ' + - pluralize.plural(table.via) + // eslint-disable-next-line prefer-template + pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via) ); } ).join('__'); @@ -848,10 +848,7 @@ module.exports = function(strapi) { // Sometimes the many-to-many relationships // is on the same keys on the same models (ex: `friends` key in model `User`) - if ( - details.attribute + '_' + details.column === - relationship.attribute + '_' + relationship.column - ) { + if (`${details.attribute}_${details.column}` === `${relationship.attribute}_${relationship.column}`) { relationship.attribute = pluralize.singular(details.via); } @@ -866,16 +863,16 @@ module.exports = function(strapi) { return this.belongsToMany( GLOBALS[globalId], collectionName, - relationship.attribute + '_' + relationship.column, - details.attribute + '_' + details.column + `${relationship.attribute}_${relationship.column}`, + `${details.attribute}_${details.column}` ).withPivot(details.withPivot); } return this.belongsToMany( GLOBALS[globalId], collectionName, - relationship.attribute + '_' + relationship.column, - details.attribute + '_' + details.column + `${relationship.attribute}_${relationship.column}`, + `${details.attribute}_${details.column}` ); }; break; @@ -933,7 +930,7 @@ module.exports = function(strapi) { } if (models.length === 0) { - strapi.log.error('Impossible to register the `' + model + '` model.'); + strapi.log.error(`Impossible to register the '${model}' model.`); strapi.log.error('The collection name cannot be found for the morphTo method.'); strapi.stop(); }