-
Notifications
You must be signed in to change notification settings - Fork 23
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
Conversation
9522725
to
b46cb60
Compare
b46cb60
to
6957027
Compare
lib/controllers/mongo.js
Outdated
hostname: api[1], | ||
port: api[0] === 'https' ? 443 : 80, | ||
version: 'v2', | ||
token: null |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/controllers/mongo.js
Outdated
var Client = apiUtil({ | ||
protocol: api[0], | ||
hostname: api[1], | ||
port: api[0] === 'https' ? 443 : 80, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that worked, thx
lib/controllers/mongo.js
Outdated
Client.post('/databases/' + db.id + '/clone', { | ||
db: db, | ||
hosts: hosts | ||
}, userConfig.data.apiKey, callback) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/routes/mongo.js
Outdated
this.line('Migrates a MongoDB database to a different version and host.'.input) | ||
}) | ||
|
||
xervo.program |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove ^
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/commands/env.js
Outdated
if (err) { | ||
return error.handlePromptError(err, cb) | ||
} | ||
return cb(null, envVars[result.environmentVar - 1]) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/commands/mongo.js
Outdated
} | ||
} | ||
if (databases.length === 0) { | ||
xervo.io.error('You currently have no databases. One can be created using the `mongo create` command.') |
There was a problem hiding this comment.
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 🥂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/commands/mongo.js
Outdated
} | ||
|
||
if (databaseName !== '') { | ||
for (var i = 0; i < databases.length; i++) { |
There was a problem hiding this comment.
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
lib/commands/mongo.js
Outdated
|
||
mongo.chooseDatabasePrompt(databases, databaseName, function (err, database) { | ||
if (err) { | ||
err = error.handleApiError(err, 'MIGRATE_MONGO', cb) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/commands/mongo.js
Outdated
|
||
mongo.chooseRegionPrompt(function (err, regionData) { | ||
if (err) { | ||
err = error.handleApiError(err, 'MIGRATE_MONGO', cb) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 () { |
There was a problem hiding this comment.
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?
Initial flow for DB migration added under
xervo mongo migrate
command. Works up tolibrarian
migrate call.addresses XervoIO/product-dev/issues/10