Skip to content
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

Add dbport option for db setup #1260

Merged
merged 3 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions lib/tasks/configure/get-prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ module.exports = function getPrompts(config, argv, environment) {
});
}

if (!argv.dbport) {
prompts.push({
type: 'input',
name: 'dbport',
message: 'Enter your MySQL port' +
`${config.has('database.connection.port') ? ' (skip to keep current port)' : ''}:`,
default: config.get('database.connection.port', 3306)
});
}

if (!argv.dbname) {
const sanitizedDirName = path.basename(process.cwd()).replace(/[^a-zA-Z0-9_]+/g, '_');
const shortenedEnv = environment === 'development' ? 'dev' : 'prod';
Expand Down
6 changes: 6 additions & 0 deletions lib/tasks/configure/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ module.exports = {
type: 'string',
group: 'Database Options:'
},
dbport: {
description: 'Database port',
configPath: 'database.connection.port',
type: 'number',
group: 'Database Options:'
},
dbname: {
description: 'Database name',
configPath: 'database.connection.database',
Expand Down
35 changes: 29 additions & 6 deletions test/unit/tasks/configure/get-prompts-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ describe('Unit: Tasks: Configure > getPrompts', function () {
const config = new Config('config.json');
const prompts = getPrompts(config, {url: 'http://localhost.com'}, 'development');

expect(prompts).to.have.length(4);
expect(prompts).to.have.length(5);
expect(prompts.find(prompt => prompt.name === 'dbhost')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbuser')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbpass')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbport')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbname')).to.be.ok;
});

Expand All @@ -53,7 +54,7 @@ describe('Unit: Tasks: Configure > getPrompts', function () {
config.set('database.connection.password', 'password');
const prompts = getPrompts(config, {url: 'http://localhost.com', db: 'mysql'}, 'development');

expect(prompts).to.have.length(4);
expect(prompts).to.have.length(5);
expect(prompts.find(prompt => prompt.name === 'dbhost')).to.be.ok;

const userprompt = prompts.find(prompt => prompt.name === 'dbuser');
Expand All @@ -66,6 +67,11 @@ describe('Unit: Tasks: Configure > getPrompts', function () {
expect(passprompt.message).to.match(/skip to keep current/);
expect(passprompt.default).to.equal('password');

const portprompt = prompts.find(prompt => prompt.name === 'dbport');
expect(portprompt).to.be.ok;
expect(portprompt.message).to.match(/Enter your MySQL port/);
expect(portprompt.default).to.equal(3306);

const nameprompt = prompts.find(prompt => prompt.name === 'dbname');
expect(nameprompt).to.be.ok;
expect(nameprompt.validate('example123')).to.be.true;
Expand All @@ -78,43 +84,59 @@ describe('Unit: Tasks: Configure > getPrompts', function () {
const config = new Config('config.json');
const prompts = getPrompts(config, {url: 'http://localhost.com', db: 'mysql', dbhost: 'localhost'}, 'development');

expect(prompts).to.have.length(3);
expect(prompts).to.have.length(4);
expect(prompts.find(prompt => prompt.name === 'dbhost')).to.not.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbuser')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbpass')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbport')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbname')).to.be.ok;
});

it('doesn\'t return dbuser prompt if dbuser provided', function () {
const config = new Config('config.json');
const prompts = getPrompts(config, {url: 'http://localhost.com', db: 'mysql', dbuser: 'root'}, 'development');

expect(prompts).to.have.length(3);
expect(prompts).to.have.length(4);
expect(prompts.find(prompt => prompt.name === 'dbhost')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbuser')).to.not.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbpass')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbport')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbname')).to.be.ok;
});

it('doesn\'t return dbpass prompt if dbpass provided', function () {
const config = new Config('config.json');
const prompts = getPrompts(config, {url: 'http://localhost.com', db: 'mysql', dbpass: 'password'}, 'development');

expect(prompts).to.have.length(3);
expect(prompts).to.have.length(4);
expect(prompts.find(prompt => prompt.name === 'dbhost')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbuser')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbpass')).to.not.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbport')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbname')).to.be.ok;
});

it('doesn\'t return dbport prompt if dbport provided', function () {
const config = new Config('config.json');
const prompts = getPrompts(config, {url: 'http://localhost.com', db: 'mysql', dbport: 3306}, 'development');

expect(prompts).to.have.length(4);
expect(prompts.find(prompt => prompt.name === 'dbhost')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbuser')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbpass')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbport')).to.not.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbname')).to.be.ok;
});

it('doesn\'t return dbname prompt if dbname provided', function () {
const config = new Config('config.json');
const prompts = getPrompts(config, {url: 'http://localhost.com', db: 'mysql', dbname: 'ghost'}, 'development');

expect(prompts).to.have.length(3);
expect(prompts).to.have.length(4);
expect(prompts.find(prompt => prompt.name === 'dbhost')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbuser')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbpass')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbport')).to.be.ok;
expect(prompts.find(prompt => prompt.name === 'dbname')).to.not.be.ok;
});

Expand All @@ -125,6 +147,7 @@ describe('Unit: Tasks: Configure > getPrompts', function () {
db: 'mysql',
dbhost: 'localhost',
dbuser: 'ghost_rnd',
dbport: 3306,
dbpass: 'good_pass'
};

Expand Down