2 require 'kind_and_etag'
4 class BackwardCompatibilityForUserRepositories < ActiveRecord::Migration
5 include CurrentApiClient
7 class ArvadosModel < ActiveRecord::Base
8 self.abstract_class = true
9 extend HasUuid::ClassMethods
10 include CurrentApiClient
12 before_create do |record|
13 record.uuid ||= record.class.generate_uuid
14 record.owner_uuid ||= system_user_uuid
16 serialize :properties, Hash
19 # Clean up the name of the stub model class so we generate correct UUIDs.
20 super.rpartition("::").last
24 class Log < ArvadosModel
25 def self.log_for(thing, age="old")
26 { "#{age}_etag" => thing.etag,
27 "#{age}_attributes" => thing.attributes,
31 def self.log_create(thing)
32 new_log("create", thing, log_for(thing, "new"))
35 def self.log_update(thing, start_state)
36 new_log("update", thing, start_state.merge(log_for(thing, "new")))
39 def self.log_destroy(thing)
40 new_log("destroy", thing, log_for(thing, "old"))
45 def self.new_log(event_type, thing, properties)
46 create!(event_type: event_type,
48 object_uuid: thing.uuid,
49 object_owner_uuid: thing.owner_uuid,
50 properties: properties)
54 class Link < ArvadosModel
57 class Repository < ArvadosModel
61 remove_index :repositories, name: "repositories_search_index"
62 add_index(:repositories, %w(uuid owner_uuid modified_by_client_uuid
63 modified_by_user_uuid name),
64 name: "repositories_search_index")
65 remove_column :repositories, :fetch_url
66 remove_column :repositories, :push_url
68 [Link, Log, Repository].each { |m| m.reset_column_information }
69 Repository.where("owner_uuid != ?", system_user_uuid).find_each do |repo|
71 tail_uuid: repo.owner_uuid,
72 link_class: "permission", name: "can_manage", head_uuid: repo.uuid,
74 if Link.where(link_attrs).first.nil?
75 manage_link = Link.create!(link_attrs)
76 Log.log_create(manage_link)
78 start_log = Log.log_for(repo)
79 repo.owner_uuid = system_user_uuid
81 Log.log_update(repo, start_log)
86 raise ActiveRecord::IrreversibleMigration.
87 new("can't restore prior fetch and push URLs")