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(dependency): Support pg version 7 #7888

Merged
merged 2 commits into from Jul 20, 2017

Conversation

alitaheri
Copy link
Contributor

@alitaheri alitaheri commented Jul 5, 2017

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Upgrade pg API usage to be forward compatible with version 7. Also gets rid of the deprecation warning.

Closes #7818

@codecov
Copy link

codecov bot commented Jul 5, 2017

Codecov Report

Merging #7888 into master will increase coverage by 0.01%.
The diff coverage is 97.43%.

@alitaheri
Copy link
Contributor Author

@felixfbecker No idea why the tests fail :/

docs/usage.md Outdated
@@ -201,7 +201,7 @@ const sequelize = new Sequelize('sqlite:relativePath/dbname.db')

### PostgreSQL

The library for PostgreSQL is`pg@~3.6.0` You'll just need to define the dialect:
The library for PostgreSQL is`pg@~6.1.0` You'll just need to define the dialect:
Copy link
Contributor

Choose a reason for hiding this comment

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

7 doesnt match ~6.1.0. The whole range of supported versions should be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well it's not released yet. Might confuse some people O.o

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 see anything wrong with documenting that both 6 and 7 are supported. Otherwise someone will have to update this documentation once 7 is out

Copy link
Contributor Author

@alitaheri alitaheri Jul 5, 2017

Choose a reason for hiding this comment

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

Agreed. does pg@>=6.1.0 make more sense or pg@^6.1.0 || ^7.0.0

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say the latter, there is a high chance we won't support 8.0 when it comes out

@felixfbecker felixfbecker added the dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). label Jul 5, 2017
@alitaheri
Copy link
Contributor Author

@felixfbecker I skipped ci, have a final look and lemme know if everything's alright.

@felixfbecker
Copy link
Contributor

@alitaheri that doesn't work for PRs, you need the status check for the last commit ;)

@alitaheri
Copy link
Contributor Author

Ops sorry 😅 😅

@yocontra
Copy link
Contributor

yocontra commented Jul 6, 2017

Any idea what release this might make it out on? 4.x or backported?

@felixfbecker
Copy link
Contributor

@contra as soon as it's merged into master, it will be released as 4.x

@yocontra
Copy link
Contributor

yocontra commented Jul 6, 2017

@felixfbecker Cool, thanks for the speedy response.

@felixfbecker
Copy link
Contributor

Sorry, there are merge conflicts. You probably just need to rebase your version and run eslint --fix over it, there were some updates to eslint

@alitaheri alitaheri force-pushed the upgrade-pg branch 2 times, most recently from 28773ab to c4b0cbf Compare July 11, 2017 10:47
@alitaheri
Copy link
Contributor Author

@felixfbecker It's done. please rerun the tests. thanks 😁

@xcambar xcambar mentioned this pull request Jul 11, 2017
@alitaheri
Copy link
Contributor Author

@felixfbecker Any chance we can merge this as is? 😁 😅

@felixfbecker
Copy link
Contributor

Don't ask me, I approved - need more than 1 review

Copy link
Member

@janmeier janmeier left a comment

Choose a reason for hiding this comment

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

Can we somehow check that the right version of pg is installed? Releasing this as a minor might break for some people on old versions of pg that don't support promises (it's an obvious break, but still a break)

@alitaheri
Copy link
Contributor Author

@janmeier The version compatible ( v6.1.0 ) is almost a year old now. If people are upgrading sequelize to v4 I'm sure they've long upgraded pg to v6.1.0 😅

@janmeier
Copy link
Member

Roger that :)


type.types.postgres.oids.push(row.oid);
type.types.postgres.array_oids.push(row.typarray);
return connection.query(query).then(result => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is nested .then() handler and could be moved one level higher

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@felixfbecker Could you elaborate on that? Do you mean I should return query and continue the upper promise chain?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah.
bad:

return foo().then(() => {
  return bar().then(() => {
    return baz()
  })
})

good:

return foo()
  .then(() => {
    return bar()
  })
  .then(() => {
    return baz()
  })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@felixfbecker I can't do what you asked. Because it's not a nested then it's tap and then. If I chain the promises then the client won't be returned. Since I hate non-standard promise APIs I'll remove the chaining code and solve it differently.

Copy link
Contributor

Choose a reason for hiding this comment

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

I hate them too, I don't even know what tap does 😄

@felixfbecker
Copy link
Contributor

Hmm, but it's still a breaking change if we really did still support 3.x with Sequelize 4.0... Is there a way to make this change backwards-compatible, e.g. by not relying on the promise support?

@alitaheri
Copy link
Contributor Author

@felixfbecker node-postgres also supports node-style callbacks. I can use promisify to make sure it works with older versions too. Would that be enough?

@felixfbecker
Copy link
Contributor

felixfbecker commented Jul 15, 2017

I usually just use this oneliner:

new Promise((resolve, reject) => conn.query(sql, (err, rows) => err ? reject(err) : resolve(rows)))

@alitaheri
Copy link
Contributor Author

@felixfbecker @janmeier Have a look.

Copy link
Contributor

@felixfbecker felixfbecker left a comment

Choose a reason for hiding this comment

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

This is much better if this prevents the breaking change! Thanks!

} else if (row.typname === 'geography') {
type = dataTypes.postgres.GEOGRAPHY;
}
return new Promise((resolve, reject) => connection.query(query, (error, result) => error ? reject(error) : resolve([connection, result])));
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, resolving with a tuple to maintain the connection is a bit weird. I didn't see that connection is still needed in scope, I would say in that case the nested promise is okay

docs/usage.md Outdated
@@ -201,7 +201,7 @@ const sequelize = new Sequelize('sqlite:relativePath/dbname.db')

### PostgreSQL

The library for PostgreSQL is`pg@~3.6.0` You'll just need to define the dialect:
The library for PostgreSQL is`pg@^6.1.0 || ^7.0.0` You'll just need to define the dialect:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we lower the constraint if we don't use the promise support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would 5.0.0 be ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure how outdated this doc is - maybe you could find out the minimal version that passes the tests? Does pg@3.6.0 even work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@felixfbecker Is that really necessary?

@alitaheri
Copy link
Contributor Author

@felixfbecker Done what you've asked.

@brianc
Copy link

brianc commented Jul 18, 2017

Hey y'all - sorry I just saw this! The deprecation of query.on was to clean up some confusion around that API I've had users experience for a while and allow me to do fewer allocations and gymnastics internally in future versions. If it's causing an upgrade headache or you need to support older versions you can still use this API:

https://node-postgres.com/guides/upgrading#client-query-submittable-

+1 for using callbacks or promises though. The callback style should work for every old versions of node-postgres too.

If y'all ever run into questions or weird bugs you think are related to node-postgres itself please don't hesitate to open an issue or ping me on twitter. Thanks for all you do here!! ❤️ 🤗

@alitaheri
Copy link
Contributor Author

@felixfbecker Any reason you haven't merged this yet? We need this change for production 😅 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants