Skip to content

feat(version) Automatically determine the database version when creat…#4192

Merged
janmeier merged 1 commit intomasterfrom
databaseVersion
Jul 26, 2015
Merged

feat(version) Automatically determine the database version when creat…#4192
janmeier merged 1 commit intomasterfrom
databaseVersion

Conversation

@janmeier
Copy link
Copy Markdown
Member

…ing the first connection. Re-roll of #3842

Should be good to go, just want to get a quick review on it :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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(...);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return; would not be returning something, i don't really see the importance in any case, but up to @janmeier

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Although i do generally prefer short circuit code like your second example, although that example will still race.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@BridgeAR
Copy link
Copy Markdown
Contributor

LGTM with one small comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will race, won't it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, nothing to do with transaction :)

janmeier added a commit that referenced this pull request Jul 26, 2015
feat(version) Automatically determine the database version when creat…
@janmeier janmeier merged commit 5357f6d into master Jul 26, 2015
@janmeier janmeier deleted the databaseVersion branch July 26, 2015 11:32
@janmeier
Copy link
Copy Markdown
Member Author

Updated, thanks for the feedback @mickhansen and @BridgeAR :)

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.

3 participants