feat(version) Automatically determine the database version when creat…#4192
feat(version) Automatically determine the database version when creat…#4192
Conversation
There was a problem hiding this comment.
A Promise should always return something in the middle of a promise chain so I recommend to rewrite this to:
var promise;
if (self.sequelize.options.databaseVersion === 0) {
promise = self.$connect(self.config)...;
} else {
promise = Promise.resolve();
}
return promise.then(function () { ... });Or:
return Promise.try(function() {
if (self.sequelize.options.databaseVersion !== 0) {
return;
}
return self.$connect(self.config)...;
}).then(...);There was a problem hiding this comment.
return; would not be returning something, i don't really see the importance in any case, but up to @janmeier
There was a problem hiding this comment.
Although i do generally prefer short circuit code like your second example, although that example will still race.
There was a problem hiding this comment.
return; is sugar for return undefined;. So it'll return undefined and not nothing ;). I personally use return void 0; but that's just something I got used to quite a while ago. If you do not return something in the middle of a promise chain the promise thinks it's done and has to realize that there's another then chained.
|
LGTM with one small comment |
There was a problem hiding this comment.
This will race, won't it?
There was a problem hiding this comment.
If several concurrent calls request a transaction yes. The other alternative is to block once the first call is sent, but it would make the code slightly more complicated. I don't really think its a big problem that call getversion maxConnections number of times :)
There was a problem hiding this comment.
Just if you have several concurrent calls i assume? Each will request a new connection from the pool.
Blocking would not be too tricky, save the connect + databaseversion promise in a variable, if var is set use that to resolve.
There was a problem hiding this comment.
Yep, nothing to do with transaction :)
…ing the first connection. Re-roll of #3842
633b71e to
e249d5e
Compare
feat(version) Automatically determine the database version when creat…
|
Updated, thanks for the feedback @mickhansen and @BridgeAR :) |
…ing the first connection. Re-roll of #3842
Should be good to go, just want to get a quick review on it :)