[ARVADOS] updated: 18cc8023e777c9b577ea8751b9f8b5fc652c505e
git at public.curoverse.com
git at public.curoverse.com
Fri Mar 6 11:22:29 EST 2015
Summary of changes:
...tion_portable_data_hash_with_hinted_manifest.rb | 89 +++++++++++++++++-----
1 file changed, 69 insertions(+), 20 deletions(-)
via 18cc8023e777c9b577ea8751b9f8b5fc652c505e (commit)
from 0b9975ce9bb35c4a34d23f83bb8c4e7376fa1eb1 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 18cc8023e777c9b577ea8751b9f8b5fc652c505e
Author: Brett Smith <brett at curoverse.com>
Date: Fri Mar 6 11:22:25 2015 -0500
5319: Migration fixups from code review.
diff --git a/services/api/db/migrate/20150303210106_fix_collection_portable_data_hash_with_hinted_manifest.rb b/services/api/db/migrate/20150303210106_fix_collection_portable_data_hash_with_hinted_manifest.rb
index 2a5570a..e0c9dce 100644
--- a/services/api/db/migrate/20150303210106_fix_collection_portable_data_hash_with_hinted_manifest.rb
+++ b/services/api/db/migrate/20150303210106_fix_collection_portable_data_hash_with_hinted_manifest.rb
@@ -1,9 +1,56 @@
+require 'has_uuid'
+require 'kind_and_etag'
+
class FixCollectionPortableDataHashWithHintedManifest < ActiveRecord::Migration
include CurrentApiClient
+ class ArvadosModel < ActiveRecord::Base
+ self.abstract_class = true
+ include HasUuid::ClassMethods
+ include KindAndEtag
+ before_create do |record|
+ record.uuid ||= generate_uuid
+ record.owner_uuid ||= system_user_uuid
+ end
+ serialize :properties, Hash
+ end
+
+ class Collection < ArvadosModel
+ end
+
+ class Log < ArvadosModel
+ def self.log_for(thing, age="old")
+ { "#{age}_etag" => thing.etag,
+ "#{age}_attributes" => thing.attributes,
+ }
+ end
+
+ def self.log_create(thing)
+ new_log("create", thing, log_for(thing, "new"))
+ end
+
+ def self.log_update(thing, start_state)
+ new_log("update", thing, start_state.merge(log_for(thing, "new")))
+ end
+
+ def self.log_destroy(thing)
+ new_log("destroy", thing, log_for(thing, "old"))
+ end
+
+ private
+
+ def self.new_log(event_type, thing, properties)
+ create!(event_type: event_type,
+ event_at: Time.now,
+ object_uuid: thing.uuid,
+ object_owner_uuid: thing.owner_uuid,
+ properties: properties)
+ end
+ end
+
def each_bad_collection
Collection.find_each do |coll|
- next unless (coll.manifest_text =~ /\+[B-Z]/)
+ next unless (coll.manifest_text =~ /\+[A-Z]/)
stripped_manifest = coll.manifest_text.
gsub(/( [0-9a-f]{32}(\+\d+)?)(\+\S+)/, '\1')
stripped_pdh = sprintf("%s+%i",
@@ -14,44 +61,46 @@ class FixCollectionPortableDataHashWithHintedManifest < ActiveRecord::Migration
end
def up
+ Collection.reset_column_information
+ Log.reset_column_information
copied_attr_names =
- [:owner_uuid, :created_at, :modified_by_client_uuid,
+ [:owner_uuid, :created_at, :modified_by_client_uuid, :manifest_text,
:modified_by_user_uuid, :modified_at, :updated_at, :name,
:description, :portable_data_hash, :replication_desired,
- :replication_confirmed, :replication_confirmed_at]
+ :replication_confirmed, :replication_confirmed_at, :expires_at]
new_expiry = Date.new(2038, 1, 31)
- act_as_system_user
each_bad_collection do |coll, stripped_pdh|
# Create a copy of the collection including bad portable data hash,
# with an expiration. This makes it possible to resolve the bad
# portable data hash, but the expiration can hide the Collection
# from more user-friendly interfaces like Workbench.
- properties = coll.properties.dup
- properties["migrated_from"] ||= coll.uuid
- coll_copy = Collection.
- create!(manifest_text: coll.manifest_text,
- properties: properties,
- expires_at: coll.expires_at || new_expiry)
- # update_column skips validations and callbacks, which lets us
- # set an "invalid" portable_data_hash and avoid messing with
- # modification metadata.
- copied_attr_names.each do |attr_sym|
- coll_copy.update_column(attr_sym, coll.send(attr_sym))
- end
- coll.update_column(:portable_data_hash, stripped_pdh)
+ start_log = Log.log_for(coll)
+ attributes = Hash[copied_attr_names.map { |key| [key, coll.send(key)] }]
+ attributes[:expires_at] ||= new_expiry
+ attributes[:properties] = (coll.properties.dup rescue {})
+ attributes[:properties]["migrated_from"] ||= coll.uuid
+ coll_copy = Collection.create!(attributes)
+ Log.log_create(coll_copy)
+ coll.update_attributes(portable_data_hash: stripped_pdh)
+ Log.log_update(coll, start_log)
end
end
def down
- act_as_system_user
+ Collection.reset_column_information
+ Log.reset_column_information
each_bad_collection do |coll, stripped_pdh|
if ((src_uuid = coll.properties["migrated_from"]) and
(src_coll = Collection.where(uuid: src_uuid).first) and
(src_coll.portable_data_hash == stripped_pdh))
- src_coll.update_column(:portable_data_hash, coll.portable_data_hash)
+ start_log = Log.log_for(src_coll)
+ src_coll.portable_data_hash = coll.portable_data_hash
+ src_coll.save!
+ Log.log_update(src_coll, start_log)
+ coll.destroy or raise Exception.new("failed to destroy old collection")
+ Log.log_destroy(coll)
end
- coll.delete
end
end
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list