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

Implements support for promise based migrations. #82

Closed
wants to merge 7 commits into from

Conversation

jdpnielsen
Copy link
Contributor

No description provided.

lib/migrate.js Outdated
if (err) return fn(err)

next(migrations.shift())
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this fine, or should i split the callback out into a separate function, which can be reused in both callback & promise cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I would do that for sure.

lib/migrate.js Outdated
@@ -42,6 +47,30 @@ function migrate (set, direction, migrationName, fn) {
next(migrations.shift())
})
})

if (migrationPromise && migrationPromise.then) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer this to be typeof Promise !== 'undefined' && migrationPromise instanceof Promise

@wesleytodd
Copy link
Collaborator

Would prefer to keep as much backward support as possible. Can you revert the let's to var? For utility libraries like this, the cost of sticking with good ole es5 is not worth the inability to support older versions of node.

Reading this reminded me to go back and ensure I did not use any arrow functions or const's. So I will be updating that later today hopefully.

module.exports.down = function (next) {
setTimeout(function () {
return next()
}, 200)
Copy link
Collaborator

Choose a reason for hiding this comment

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

To reduce test time, just do a timeout of 1 ms. It achieves the same effect without the wait.

test/promises.js Outdated
})
})

afterEach(function (done) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this to the top like in the other tests. If this file grows it will get lost way down here.

lib/migrate.js Outdated

let migrationPromise = migration[direction](function (err) {
if (migrationCompleted) {
Copy link
Collaborator

@wesleytodd wesleytodd Oct 5, 2017

Choose a reason for hiding this comment

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

Even though I prefer multi-line if statements with curlys like this, the majority of the code base is done on a single line. Please follow the common formatting.

@wesleytodd
Copy link
Collaborator

@jdpnielsen Awesome work. Thanks! With these few changes I can merge this up before we do the 1.0 release for sure.

@jdpnielsen
Copy link
Contributor Author

Done.

@wesleytodd
Copy link
Collaborator

Weird, I amended the commit and added the closes #82 but it didn't close it. Anyway, this is published in the next beta 1.0.0-2. Install with npm i migrate@next or npm i migrate@1.0.0-2.

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

Successfully merging this pull request may close these issues.

2 participants