1 class RenameMetadataAttributes < ActiveRecord::Migration
3 rename_column :metadata, :target_kind, :tail_kind
4 rename_column :metadata, :target_uuid, :tail
5 rename_column :metadata, :value, :head
6 rename_column :metadata, :key, :name
7 add_column :metadata, :head_kind, :string
8 add_index :metadata, :head
9 add_index :metadata, :head_kind
10 add_index :metadata, :tail
11 add_index :metadata, :tail_kind
13 Metadatum.where('head like ?', 'orvos#%').each do |m|
14 kind_uuid = m.head.match /^(orvos\#.*)\#([-0-9a-z]+)$/
16 m.update_attributes(head_kind: kind_uuid[1],
26 Metadatum.where('head_kind is not null and head_kind <> ? and head is not null', '').each do |m|
27 m.update_attributes(head: m.head_kind + '#' + m.head)
31 remove_index :metadata, :tail_kind
32 remove_index :metadata, :tail
33 remove_index :metadata, :head_kind
34 remove_index :metadata, :head
35 rename_column :metadata, :name, :key
36 remove_column :metadata, :head_kind
37 rename_column :metadata, :head, :value
38 rename_column :metadata, :tail, :target_uuid
39 rename_column :metadata, :tail_kind, :target_kind