2018-01-10 15:31:54 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Node.js core.
|
|
|
|
const execSync = require('child_process').execSync;
|
2018-01-11 13:22:49 +01:00
|
|
|
const path = require('path');
|
2018-01-10 15:31:54 +01:00
|
|
|
|
|
|
|
// Logger.
|
|
|
|
const logger = require('strapi-utils').logger;
|
|
|
|
|
|
|
|
module.exports = (scope, success, error) => {
|
2018-02-12 19:14:36 +01:00
|
|
|
const knex = require(path.resolve(`${scope.tmpPath}/node_modules/knex`))({
|
2018-01-10 15:31:54 +01:00
|
|
|
client: scope.client.module,
|
2018-02-06 16:00:04 +01:00
|
|
|
connection: Object.assign({}, scope.database.settings, {
|
2018-01-17 09:14:34 +01:00
|
|
|
user: scope.database.settings.username
|
2018-01-10 18:08:43 +01:00
|
|
|
})
|
2018-01-10 15:31:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
knex.raw('select 1+1 as result').then(() => {
|
2018-01-10 18:08:43 +01:00
|
|
|
logger.info('The app has been connected to the database successfully');
|
2018-01-10 15:31:54 +01:00
|
|
|
knex.destroy();
|
2018-03-18 13:29:49 +01:00
|
|
|
execSync(`rm -r "${scope.tmpPath}"`);
|
2018-01-10 15:31:54 +01:00
|
|
|
|
|
|
|
logger.info('Copying the dashboard...');
|
|
|
|
|
|
|
|
success();
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2018-01-10 18:08:43 +01:00
|
|
|
logger.warn('Database connection has failed! Make sure your database is running.');
|
2018-01-10 15:31:54 +01:00
|
|
|
error();
|
|
|
|
});
|
|
|
|
};
|