Merge branch '15133-remove-jobs-api' refs #15133
[arvados.git] / services / api / db / migrate / 20141208164553_owner_uuid_index.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class OwnerUuidIndex < ActiveRecord::Migration[4.2]
6   def tables_with_owner_uuid
7     %w{api_clients authorized_keys collections groups humans
8        job_tasks jobs keep_disks keep_services links logs
9        nodes pipeline_instances pipeline_templates repositories
10        specimens traits users virtual_machines}
11   end
12
13   def up
14     tables_with_owner_uuid.each do |table|
15       add_index table.to_sym, :owner_uuid
16     end
17   end
18
19   def down
20     tables_with_owner_uuid.each do |table|
21       indexes = ActiveRecord::Base.connection.indexes(table)
22       owner_uuid_index = indexes.select do |index|
23         index.columns == ['owner_uuid']
24       end
25       if !owner_uuid_index.empty?
26         remove_index table.to_sym, :owner_uuid
27       end
28     end
29   end
30 end