diff --git a/package.json b/package.json index 20cd20fb35a..50712a97655 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "shelljs": "^0.7.7", "snyk": "^1.99.0", "strapi-lint": "file:packages/strapi-lint", - "wait-on": "^3.2.0" + "wait-on": "^3.2.0", + "yargs": "^13.2.2" }, "scripts": { "clean": "npm run removesymlinkdependencies && npx rimraf package-lock.json && npx rimraf packages/*/package-lock.json", diff --git a/packages/strapi-hook-bookshelf/lib/index.js b/packages/strapi-hook-bookshelf/lib/index.js index 9ce7149d4aa..e4692fdcb27 100644 --- a/packages/strapi-hook-bookshelf/lib/index.js +++ b/packages/strapi-hook-bookshelf/lib/index.js @@ -23,6 +23,20 @@ const buildQuery = require('./buildQuery'); const PIVOT_PREFIX = '_pivot_'; const GLOBALS = {}; +const getDatabaseName = connection => { + const dbName = _.get(connection.settings, 'database'); + switch (_.get(connection.settings, 'client')) { + case 'sqlite3': + return 'main'; + case 'pg': + return `${dbName}.public`; + case 'mysql': + return dbName; + default: + return dbName; + } +}; + /** * Bookshelf hook */ @@ -83,7 +97,7 @@ module.exports = function(strapi) { // Add some informations about ORM & client connection & tableName definition.orm = 'bookshelf'; - definition.databaseName = _.get(connection.settings, 'database'); + definition.databaseName = getDatabaseName(connection); definition.client = _.get(connection.settings, 'client'); _.defaults(definition, { primaryKey: 'id', diff --git a/test/e2e.js b/test/e2e.js index fdfc0725cb1..84744aa97d7 100644 --- a/test/e2e.js +++ b/test/e2e.js @@ -1,7 +1,12 @@ const path = require('path'); -const { cleanTestApp, generateTestApp, startTestApp } = require('./helpers/testAppGenerator'); +const { + cleanTestApp, + generateTestApp, + startTestApp, +} = require('./helpers/testAppGenerator'); const execa = require('execa'); const waitOn = require('wait-on'); +const yargs = require('yargs'); const appName = 'testApp'; @@ -25,9 +30,7 @@ const test = async () => { }); }; -const main = async () => { - const database = process.argv.length > 2 ? process.argv.slice(2).join(' ') : databases.sqlite; - +const main = async database => { try { await cleanTestApp(appName); await generateTestApp({ appName, database }); @@ -45,11 +48,23 @@ const main = async () => { testAppProcess.kill(); process.exit(0); } catch (error) { - console.log(error) + console.log(error); process.stdout.write('Tests failed\n', () => { process.exit(1); }); } }; -main(); +yargs + .command( + '$0 [databaseName]', + 'run end to end tests', + yargs => { + yargs.positional('databaseName', { + default: 'sqlite', + choices: Object.keys(databases), + }); + }, + ({ databaseName }) => main(databases[databaseName]) + ) + .help().argv;