3036: Fixed migration to migrate modified_by_client_uuid and
[arvados.git] / services / api / db / migrate / 20140811184643_collection_use_regular_uuids.rb
index e5b509c8f54b9d8be3529087ea941da5dd8b7c65..5c21c0bb2d2f090a92fa852cb38db484ed99f4ee 100644 (file)
@@ -5,7 +5,6 @@ class CollectionUseRegularUuids < ActiveRecord::Migration
     add_column :collections, :properties, :text
     add_column :collections, :expire_time, :date
     remove_column :collections, :locator
-    add_column :jobs, :name, :string
 
     say_with_time "Step 1. Move manifest hashes into portable_data_hash field" do
       ActiveRecord::Base.connection.execute("update collections set portable_data_hash=uuid, uuid=null")
@@ -18,19 +17,22 @@ where link_class='name' and collections.uuid is null
 }
       links = ActiveRecord::Base.connection.select_all %{
 select links.uuid, head_uuid, tail_uuid, links.name,
-manifest_text, links.created_at, links.updated_at
+manifest_text, links.created_at, links.modified_at, links.modified_by_client_uuid, links.modified_by_user_uuid
 #{from_clause}
 }
       links.each do |d|
         ActiveRecord::Base.connection.execute %{
-insert into collections (uuid, portable_data_hash, owner_uuid, name, manifest_text, created_at, updated_at)
+insert into collections (uuid, portable_data_hash, owner_uuid, name, manifest_text, created_at, modified_at, modified_by_client_uuid, modified_by_user_uuid, updated_at)
 values (#{ActiveRecord::Base.connection.quote Collection.generate_uuid},
 #{ActiveRecord::Base.connection.quote d['head_uuid']},
 #{ActiveRecord::Base.connection.quote d['tail_uuid']},
 #{ActiveRecord::Base.connection.quote d['name']},
 #{ActiveRecord::Base.connection.quote d['manifest_text']},
 #{ActiveRecord::Base.connection.quote d['created_at']},
-#{ActiveRecord::Base.connection.quote d['updated_at']})
+#{ActiveRecord::Base.connection.quote d['modified_at']},
+#{ActiveRecord::Base.connection.quote d['modified_by_client_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_by_user_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_at']})
 }
       end
       ActiveRecord::Base.connection.execute "delete from links where links.uuid in (select links.uuid #{from_clause})"
@@ -42,18 +44,21 @@ from links inner join collections on head_uuid=collections.portable_data_hash
 where link_class='permission' and links.name='can_read' and collections.uuid is null
 }
       links = ActiveRecord::Base.connection.select_all %{
-select links.uuid, head_uuid, tail_uuid, manifest_text, links.created_at, links.updated_at
+select links.uuid, head_uuid, tail_uuid, manifest_text, links.created_at, links.modified_at
 #{from_clause}
 }
       links.each do |d|
         ActiveRecord::Base.connection.execute %{
-insert into collections (uuid, portable_data_hash, owner_uuid, manifest_text, created_at, updated_at)
+insert into collections (uuid, portable_data_hash, owner_uuid, manifest_text, created_at, modified_at, modified_by_client_uuid, modified_by_user_uuid, updated_at)
 values (#{ActiveRecord::Base.connection.quote Collection.generate_uuid},
 #{ActiveRecord::Base.connection.quote d['head_uuid']},
 #{ActiveRecord::Base.connection.quote d['tail_uuid']},
 #{ActiveRecord::Base.connection.quote d['manifest_text']},
 #{ActiveRecord::Base.connection.quote d['created_at']},
-#{ActiveRecord::Base.connection.quote d['updated_at']})
+#{ActiveRecord::Base.connection.quote d['modified_at']},
+#{ActiveRecord::Base.connection.quote d['modified_by_client_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_by_user_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_at']})
 }
       end
       ActiveRecord::Base.connection.execute "delete from links where links.uuid in (select links.uuid #{from_clause})"
@@ -61,19 +66,22 @@ values (#{ActiveRecord::Base.connection.quote Collection.generate_uuid},
 
     say_with_time "Step 4. Migrate remaining orphan collection objects" do
       links = ActiveRecord::Base.connection.select_all %{
-select portable_data_hash, owner_uuid, manifest_text, created_at, updated_at
+select portable_data_hash, owner_uuid, manifest_text, created_at, modified_at
 from collections
 where uuid is null and portable_data_hash not in (select portable_data_hash from collections where uuid is not null)
 }
       links.each do |d|
         ActiveRecord::Base.connection.execute %{
-insert into collections (uuid, portable_data_hash, owner_uuid, manifest_text, created_at, updated_at)
+insert into collections (uuid, portable_data_hash, owner_uuid, manifest_text, created_at, modified_at, modified_by_client_uuid, modified_by_user_uuid, updated_at)
 values (#{ActiveRecord::Base.connection.quote Collection.generate_uuid},
 #{ActiveRecord::Base.connection.quote d['portable_data_hash']},
 #{ActiveRecord::Base.connection.quote d['owner_uuid']},
 #{ActiveRecord::Base.connection.quote d['manifest_text']},
 #{ActiveRecord::Base.connection.quote d['created_at']},
-#{ActiveRecord::Base.connection.quote d['updated_at']})
+#{ActiveRecord::Base.connection.quote d['modified_at']},
+#{ActiveRecord::Base.connection.quote d['modified_by_client_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_by_user_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_at']})
 }
       end
     end
@@ -96,21 +104,24 @@ from links
 where head_uuid like '________________________________+%' and tail_uuid like '________________________________+%' and links.link_class = 'provenance'
 }
       links = ActiveRecord::Base.connection.select_all %{
-select links.uuid, head_uuid, tail_uuid, links.created_at, links.updated_at, links.owner_uuid
+select links.uuid, head_uuid, tail_uuid, links.created_at, links.modified_at, links.modified_by_client_uuid, links.modified_by_user_uuid, links.owner_uuid
 #{from_clause}
 }
       links.each do |d|
         newuuid = Job.generate_uuid
         ActiveRecord::Base.connection.execute %{
-insert into jobs (uuid, script_parameters, output, running, success, created_at, updated_at, owner_uuid)
+insert into jobs (uuid, script_parameters, output, running, success, created_at, modified_at, modified_by_client_uuid, modified_by_user_uuid, owner_uuid, updated_at)
 values (#{ActiveRecord::Base.connection.quote newuuid},
 #{ActiveRecord::Base.connection.quote "---\ninput: "+d['tail_uuid']},
 #{ActiveRecord::Base.connection.quote d['head_uuid']},
 #{ActiveRecord::Base.connection.quote false},
 #{ActiveRecord::Base.connection.quote true},
 #{ActiveRecord::Base.connection.quote d['created_at']},
-#{ActiveRecord::Base.connection.quote d['updated_at']},
-#{ActiveRecord::Base.connection.quote d['owner_uuid']})
+#{ActiveRecord::Base.connection.quote d['modified_at']},
+#{ActiveRecord::Base.connection.quote d['modified_by_client_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_by_user_uuid']},
+#{ActiveRecord::Base.connection.quote d['owner_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_at']})
 }
       end
       ActiveRecord::Base.connection.execute "delete from links where links.uuid in (select links.uuid #{from_clause})"
@@ -123,12 +134,12 @@ where collections.uuid is not null
 }
       links = ActiveRecord::Base.connection.select_all %{
 select links.uuid, collections.uuid as collectionuuid, tail_uuid, link_class, links.properties,
-links.name, links.created_at, links.updated_at, links.owner_uuid
+links.name, links.created_at, links.modified_at, links.modified_by_client_uuid, links.modified_by_user_uuid, links.owner_uuid
 #{from_clause}
 }
       links.each do |d|
         ActiveRecord::Base.connection.execute %{
-insert into links (uuid, head_uuid, tail_uuid, link_class, name, properties, created_at, updated_at, owner_uuid)
+insert into links (uuid, head_uuid, tail_uuid, link_class, name, properties, created_at, modified_at, modified_by_client_uuid, modified_by_user_uuid, owner_uuid, updated_at)
 values (#{ActiveRecord::Base.connection.quote Link.generate_uuid},
 #{ActiveRecord::Base.connection.quote d['collectionuuid']},
 #{ActiveRecord::Base.connection.quote d['tail_uuid']},
@@ -136,8 +147,11 @@ values (#{ActiveRecord::Base.connection.quote Link.generate_uuid},
 #{ActiveRecord::Base.connection.quote d['name']},
 #{ActiveRecord::Base.connection.quote d['properties']},
 #{ActiveRecord::Base.connection.quote d['created_at']},
-#{ActiveRecord::Base.connection.quote d['updated_at']},
-#{ActiveRecord::Base.connection.quote d['owner_uuid']})
+#{ActiveRecord::Base.connection.quote d['modified_at']},
+#{ActiveRecord::Base.connection.quote d['modified_by_client_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_by_user_uuid']},
+#{ActiveRecord::Base.connection.quote d['owner_uuid']},
+#{ActiveRecord::Base.connection.quote d['modified_at']})
 }
       end
       ActiveRecord::Base.connection.execute "delete from links where links.uuid in (select links.uuid #{from_clause})"