Merge branch '8784-dir-listings'
[arvados.git] / services / api / db / migrate / 20140325175653_remove_kind_columns.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class RemoveKindColumns < ActiveRecord::Migration
6   include CurrentApiClient
7
8   def up
9     remove_column :links, :head_kind
10     remove_column :links, :tail_kind
11     remove_column :logs, :object_kind
12   end
13
14   def down
15     add_column :links, :head_kind, :string
16     add_column :links, :tail_kind, :string
17     add_column :logs, :object_kind, :string
18
19     act_as_system_user do
20       Link.all.each do |l|
21         l.head_kind = ArvadosModel::resource_class_for_uuid(l.head_uuid).kind if l.head_uuid
22         l.tail_kind = ArvadosModel::resource_class_for_uuid(l.tail_uuid).kind if l.tail_uuid
23         l.save
24       end
25       Log.all.each do |l|
26         l.object_kind = ArvadosModel::resource_class_for_uuid(l.object_uuid).kind if l.object_uuid
27         l.save
28       end
29     end
30   end
31 end