This code is mostly a copy-paste from existing pull requests so there's no point in running Rubocop on it.
This is needed to support creating/dumping/loading indexes that use the gin_trgm_ops operator class on PostgreSQL. These changes are taken from Rails pull request https://github.com/rails/rails/pull/19090.