Merge branch '8784-dir-listings'
[arvados.git] / services / api / db / migrate / 20141208174653_collection_file_names.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class CollectionFileNames < ActiveRecord::Migration
6   include CurrentApiClient
7
8   def up
9     add_column :collections, :file_names, :string, :limit => 2**13
10
11     act_as_system_user do
12       Collection.find_each(batch_size: 20) do |c|
13         file_names = c.manifest_files
14         ActiveRecord::Base.connection.execute "UPDATE collections
15                     SET file_names = #{ActiveRecord::Base.connection.quote(file_names)}
16                     WHERE uuid = '#{c.uuid}'"
17       end
18     end
19   end
20
21   def down
22     remove_column :collections, :file_names
23   end
24 end