Sha256: 6a1bb75002b0a829ed883228f5cdadc580e8360151fd53540274e877c30c63c2

Contents?: true

Size: 953 Bytes

Versions: 4

Compression:

Stored size: 953 Bytes

Contents

class SeparateNoteAnnotationPredicates < ActiveRecord::Migration[4.2]
  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

4 entries across 4 versions & 1 rubygems

Version Path
iqvoc-4.14.5 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.14.4 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.13.2 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.13.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb