Sha256: 31425bb110ae9bd9ca767b9024ffa51f6483e08edb95ac48c25dc20bcf5d41f3
Contents?: true
Size: 948 Bytes
Versions: 16
Compression:
Stored size: 948 Bytes
Contents
class SeparateNoteAnnotationPredicates < ActiveRecord::Migration def self.up rename_column :note_annotations, :identifier, :predicate add_column :note_annotations, :namespace, :string, limit: 50 annotations = select_rows('SELECT id, predicate FROM note_annotations') annotations.each do |annotation| namespace, predicate = annotation[1].split(':', 2) execute "UPDATE note_annotations SET namespace = '#{namespace}', predicate = '#{predicate}' WHERE id = #{annotation[0]}" end end def self.down annotations = select_rows('SELECT id, predicate, namespace FROM note_annotations') annotations.each do |annotation| identifier = [annotation[2], annotation[1]].join(':') execute "UPDATE note_annotations SET predicate = '#{identifier}' WHERE id = #{annotation[0]}" end rename_column :note_annotations, :predicate, :identifier remove_column :note_annotations, :namespace end end
Version data entries
16 entries across 16 versions & 1 rubygems