Changed how the ticket filter query is constructed.
Sort values to be used for `IN()` query selects.
Move upgrade queries into a helper class.