mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
Handle different databases names standards
This commit is contained in:
parent
ae943d7492
commit
187700e1c9
@ -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",
|
||||
|
||||
@ -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',
|
||||
|
||||
27
test/e2e.js
27
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user