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

Bookshelf & Knex upgrade #6103

Closed
3 of 9 tasks
ErisDS opened this issue Nov 20, 2015 · 4 comments
Closed
3 of 9 tasks

Bookshelf & Knex upgrade #6103

ErisDS opened this issue Nov 20, 2015 · 4 comments
Labels
help wanted [triage] Ideal issues for contributors to help with server / core Issues relating to the server or core of Ghost

Comments

@ErisDS
Copy link
Member

ErisDS commented Nov 20, 2015

Bookshelf & knex did not get upgraded at the start of this release cycle. This was because there was a reasonable amount of work to do, and I got carried away with other work before I completed it. I very much regret this, as several of the filter, include, etc features I've been building into our model layer would have been simpler had I had access to the newer features.

I did try out upgrading to [email protected] & [email protected], it did not cause any test regressions (and iirc I ran the old casper.js test suite against this). The current versions are [email protected] and [email protected], and so there's been another significant update which warrants testing.

  • Update bookshelf
  • Update knex

At the start of the next release cycle, I want to get this upgrade done ASAP. I'll be using this issue to document everything that I know can or needs to be changed as a result of the upgrade.

  • Bookshelf now has a serialize method that is called by toJSON. It should be possible to use the new structure to override serialize instead of toJSON in places in our codebase, and simplify our code.
  • Bookshelf now has count methods which may be useful
  • Knex has a new modify method that should make it easier to construct complex query builders from pre-defined parts.
  • Knex should be getting a new countDistinct method we can use to replace some horrible knex.raw code in the pagination plugin (should be in knex 0.9.1)
  • Knex now supports nested transactions, may be useful for improving our post & tag saving code
  • Knex has had significant improvements to the join syntax which we may be able to leverage

Even newer:

  • Bookshelf has got a pagination plugin and a fetchPage method that we can use instead of our own.

Things to be aware of:

  • The pool handling software has changed completely in knex since 0.7. There are some open issues around pools and so some significant testing might be in order.
@ErisDS ErisDS added data server / core Issues relating to the server or core of Ghost labels Nov 20, 2015
@mikebaldry
Copy link

Really need this, with a non-perfect PG connection, current version of knex just crashes the whole app any time a connection dies, instead of closing it and reconnecting. This is now handled nicely in 0.8.6

ErisDS added a commit to ErisDS/Ghost that referenced this issue Feb 8, 2016
refs: TryGhost#6103

- dependency upgrade only, code changes to follow
@ErisDS ErisDS added the help wanted [triage] Ideal issues for contributors to help with label Feb 14, 2016
@ErisDS
Copy link
Member Author

ErisDS commented Feb 14, 2016

The library updates are done, but none of the code changes / potential improvements are done yet.

@ErisDS
Copy link
Member Author

ErisDS commented May 20, 2016

Bookshelf 0.9.5 (merged by #6836) has its own pagination plugin (finally!) it may be worth looking at dropping ours in favour of theirs.

@ErisDS
Copy link
Member Author

ErisDS commented Aug 3, 2017

Can close this. Bookshelf is actively maintained again, and at some point we'll look into catching up again. When we do, this information is here. Right now the built in fetchPage doesn't seem stable, so should stick to our own implementation for a bit longer probably.

@ErisDS ErisDS closed this as completed Aug 3, 2017
kirrg001 added a commit that referenced this issue Feb 14, 2018
refs #6103

- simplify `toJSON`
- `baseKey` was not used - have not find a single use case
- all the functionality of our `toJSON` is offered in bookshelf
- `omitPivot` does remove pivot elements from the JSON obj (bookshelf feature)
- `shallow` allows you to not return relations
- make use of `serialize`, see http://bookshelfjs.org/docs/src_base_model.js.html#line260
- fetching nested relations e.g. `users.roles` still works (unrelated to this refactoring)

> pick('shallow', 'baseKey', 'include', 'context')

We will re-add options validation in #9427, but then with the official way: use `filterOptions`.

---

We return all fetched relations (pre-defined with `withRelated`) by default.
You can disable it with `shallow:true`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted [triage] Ideal issues for contributors to help with server / core Issues relating to the server or core of Ghost
Projects
None yet
Development

No branches or pull requests

2 participants