21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / api / db / migrate / 20230922000000_add_btree_name_index_to_collections_and_groups.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class AddBtreeNameIndexToCollectionsAndGroups < ActiveRecord::Migration[5.2]
6   #
7   # We previously added 'index_groups_on_name' and
8   # 'index_collections_on_name' but those are 'gin_trgm_ops' which is
9   # used with 'ilike' searches but despite documentation suggesting
10   # they would be, experience has shown these indexes don't get used
11   # for '=' (and/or they are much slower than the btree for exact
12   # matches).
13   #
14   # So we want to add a regular btree index.
15   #
16   def up
17     ActiveRecord::Base.connection.execute 'CREATE INDEX index_groups_on_name_btree on groups USING btree (name)'
18     ActiveRecord::Base.connection.execute 'CREATE INDEX index_collections_on_name_btree on collections USING btree (name)'
19   end
20   def down
21     ActiveRecord::Base.connection.execute 'DROP INDEX IF EXISTS index_collections_on_name_btree'
22     ActiveRecord::Base.connection.execute 'DROP INDEX IF EXISTS index_groups_on_name_btree'
23   end
24 end