Skip to content

Add db:info command which returns database configuration #931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions src/commands/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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, {
Expand Down Expand Up @@ -183,3 +193,9 @@ function getDatabaseLessSequelize() {
helpers.view.error(e);
}
}

function transformConfigObject(config, showPassword) {
if (config.password !== null && !showPassword) {
config.password = '***';
}
}
1 change: 1 addition & 0 deletions src/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions test/db/db-info.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});