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

Version Path
iqvoc-4.12.1 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.12.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.11.1 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.11.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.10.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.9.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.8.2 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.8.1 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.8.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.7.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.6.1 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.5.2 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.6.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.5.1 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.5.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.4.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb