diff --git a/package.json b/package.json index 84c743e83..2e5862673 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,8 @@ "pretty": "prettier src test --write", "prepare": "husky install && npm run build", "test-raw": "mocha 'test/**/*.test.js'", - "test": "npm run lint && npm run build && npm run test-raw" + "test": "npm run lint && npm run build && npm run test-raw", + "test-one": "mocha 'test/db/db-info.test.js'" }, "repository": { "type": "git", diff --git a/src/commands/database.js b/src/commands/database.js index 22c2d59a4..fb0495a1c 100644 --- a/src/commands/database.js +++ b/src/commands/database.js @@ -29,6 +29,11 @@ exports.builder = (yargs) => .option('template', { describe: 'Pass template option to dialect, PostgreSQL only', type: 'string', + }) + .option('show-password', { + describe: 'Will show password as plain text', + type: 'boolean', + default: false, }).argv; exports.handler = async function (args) { @@ -52,8 +57,13 @@ exports.handler = async function (args) { queryInterface.queryGenerator || queryInterface.QueryGenerator; const query = getCreateDatabaseQuery(sequelize, config, options); + let configOutput = ''; switch (command) { + case 'db:info': + configOutput = transformConfigObject(config, args['show-password']); + helpers.view.log('Config', configOutput); + break; case 'db:create': await sequelize .query(query, { @@ -183,3 +193,9 @@ function getDatabaseLessSequelize() { helpers.view.error(e); } } + +function transformConfigObject(config, showPassword) { + if (config.password !== null && !showPassword) { + config.password = '***'; + } +} diff --git a/src/sequelize.js b/src/sequelize.js index 7249135c6..f9835d582 100644 --- a/src/sequelize.js +++ b/src/sequelize.js @@ -35,6 +35,7 @@ yargs .command('db:seed:undo', 'Deletes data from the database', seedOne) .command('db:seed:all', 'Run every seeder', seed) .command('db:seed:undo:all', 'Deletes data from the database', seed) + .command('db:info', 'Return database configuration info', database) .command('db:create', 'Create database specified by configuration', database) .command('db:drop', 'Drop database specified by configuration', database) .command('init', 'Initializes project', init) diff --git a/test/db/db-info.test.js b/test/db/db-info.test.js new file mode 100644 index 000000000..e57d9fb4c --- /dev/null +++ b/test/db/db-info.test.js @@ -0,0 +1,33 @@ +// const expect = require('expect.js'); +const Support = require(__dirname + '/../support'); +const helpers = require(__dirname + '/../support/helpers'); +const gulp = require('gulp'); +const _ = require('lodash'); + +const prepare = function (flag, callback, options) { + options = _.assign({ config: {} }, options || {}); + + const configPath = 'config/config.json'; + const config = _.assign({}, helpers.getTestConfig(), options.config); + const configContent = JSON.stringify(config); + + gulp + .src(Support.resolveSupportPath('tmp')) + .pipe(helpers.clearDirectory()) + .pipe(helpers.runCli('init')) + .pipe(helpers.removeFile(configPath)) + .pipe(helpers.overwriteFile(configContent, configPath)) + .pipe(helpers.runCli(flag, { pipeStdout: true })) + .pipe(helpers.teardown(callback)); +}; + +['db:info'].forEach((flag) => { + describe(Support.getTestDialectTeaser(flag), () => { + (function (folders) { + folders.forEach((folder) => { + prepare(); // wip + console.log('oo', folder); + }); + }); + }); +});