Merge branch '8784-dir-listings'
[arvados.git] / services / api / db / migrate / 20141208174653_collection_file_names.rb
index 8b182e9025bd975832cee13e6d1979c611409ef7..50ab30c39a89b4955f7cc943502211d2ec7112d9 100644 (file)
@@ -1,5 +1,24 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 class CollectionFileNames < ActiveRecord::Migration
-  def change
-    add_column :collections, :file_names, :string, :limit => 2**16
+  include CurrentApiClient
+
+  def up
+    add_column :collections, :file_names, :string, :limit => 2**13
+
+    act_as_system_user do
+      Collection.find_each(batch_size: 20) do |c|
+        file_names = c.manifest_files
+        ActiveRecord::Base.connection.execute "UPDATE collections
+                    SET file_names = #{ActiveRecord::Base.connection.quote(file_names)}
+                    WHERE uuid = '#{c.uuid}'"
+      end
+    end
+  end
+
+  def down
+    remove_column :collections, :file_names
   end
 end