ORM refactors

Working together with @jasl (see source PR in https://github.com/doorkeeper-gem/doorkeeper/pull/478).
Line is too long. [85/80]