-class NormalizeCollectionUuid < ActiveRecord::Migration
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+class NormalizeCollectionUuid < ActiveRecord::Migration[4.2]
def count_orphans
%w(head tail).each do |ht|
results = ActiveRecord::Base.connection.execute(<<-EOS)
update_sql <<-EOS
UPDATE collections
SET uuid = regexp_replace(uuid,'\\+.*','') || '+' || length(manifest_text)
- WHERE uuid !~ '^[0-9a-f]{32,}\\+[0-9]+'
+ WHERE uuid !~ '^[0-9a-f]{32,}\\+[0-9]+$'
AND (regexp_replace(uuid,'\\+.*','') || '+' || length(manifest_text))
NOT IN (SELECT uuid FROM collections)
EOS
AND (#{ht}_kind='arvados#collection' or #{ht}_uuid ~ '^[0-9a-f]{32,}')
AND #{ht}_uuid NOT IN (SELECT uuid FROM collections)
AND regexp_replace(#{ht}_uuid,'\\+.*','') = regexp_replace(c.uuid,'\\+.*','')
- AND c.uuid ~ '^[0-9a-f]{32,}\\+[0-9]+'
+ AND c.uuid ~ '^[0-9a-f]{32,}\\+[0-9]+$'
EOS
end