1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class RenameMetadataAttributes < ActiveRecord::Migration
7 rename_column :metadata, :target_kind, :tail_kind
8 rename_column :metadata, :target_uuid, :tail
9 rename_column :metadata, :value, :head
10 rename_column :metadata, :key, :name
11 add_column :metadata, :head_kind, :string
12 add_index :metadata, :head
13 add_index :metadata, :head_kind
14 add_index :metadata, :tail
15 add_index :metadata, :tail_kind
17 Metadatum.where('head like ?', 'orvos#%').each do |m|
18 kind_uuid = m.head.match /^(orvos\#.*)\#([-0-9a-z]+)$/
20 m.update_attributes(head_kind: kind_uuid[1],
30 Metadatum.where('head_kind is not null and head_kind <> ? and head is not null', '').each do |m|
31 m.update_attributes(head: m.head_kind + '#' + m.head)
35 remove_index :metadata, :tail_kind
36 remove_index :metadata, :tail
37 remove_index :metadata, :head_kind
38 remove_index :metadata, :head
39 rename_column :metadata, :name, :key
40 remove_column :metadata, :head_kind
41 rename_column :metadata, :head, :value
42 rename_column :metadata, :tail, :target_uuid
43 rename_column :metadata, :tail_kind, :target_kind