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

feat: add DB migration flow #164

Merged
merged 14 commits into from
Mar 3, 2017
Merged

feat: add DB migration flow #164

merged 14 commits into from
Mar 3, 2017

Conversation

bsatrom
Copy link
Contributor

@bsatrom bsatrom commented Feb 13, 2017

Initial flow for DB migration added under xervo mongo migrate command. Works up to librarian migrate call.

addresses XervoIO/product-dev/issues/10

hostname: api[1],
port: api[0] === 'https' ? 443 : 80,
version: 'v2',
token: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not add the user token here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above. I assumed this was for an admin token, but if putting the apiKey here prevents the need to pass in that second param, I can include it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

var Client = apiUtil({
protocol: api[0],
hostname: api[1],
port: api[0] === 'https' ? 443 : 80,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think the port is necessary to set. it will be 443. If not, there are other configuration problems that exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going off the docs in the api-util repo, but I can remove it if it's not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that worked, thx

Client.post('/databases/' + db.id + '/clone', {
db: db,
hosts: hosts
}, userConfig.data.apiKey, callback)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the token is added to the Client.token then it can be removed here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

this.line('Migrates a MongoDB database to a different version and host.'.input)
})

xervo.program
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's a convention of having flags for anything besides the command, is it best to do so here? It would also make the .action function not require another function that calls a function

package.json Outdated
@@ -32,6 +32,7 @@
}
],
"dependencies": {
"@xervo/api-util": "^0.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ^?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if (err) {
return error.handlePromptError(err, cb)
}
return cb(null, envVars[result.environmentVar - 1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to return here since it's the last call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
}
if (databases.length === 0) {
xervo.io.error('You currently have no databases. One can be created using the `mongo create` command.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually pass that message to the callback as the error and it will print. Saves 1 line of code 🥂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

if (databaseName !== '') {
for (var i = 0; i < databases.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use databases.find instead of looping over each one individually


mongo.chooseDatabasePrompt(databases, databaseName, function (err, database) {
if (err) {
err = error.handleApiError(err, 'MIGRATE_MONGO', cb)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be a prompt error instead of api error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


mongo.chooseRegionPrompt(function (err, regionData) {
if (err) {
err = error.handleApiError(err, 'MIGRATE_MONGO', cb)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if mongo.chooseRegionPrompt handles the error, you can just pass it to the callback instead of doing another error handler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

xervo.io.success('Database available at: ' + database.uri + '. Please update any running applications to use this db before removing your original.')

// Create users for the new DB
createUserOnClonedDB(database, false, function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to handle errors here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants