Sha256: fc4e10f0b711c2b7450e2768ddd99e834426e95d4039881bc05b16a5f3596676

Contents?: true

Size: 1.13 KB

Versions: 30

Compression:

Stored size: 1.13 KB

Contents

class SeparateNoteAnnotationPredicates < ActiveRecord::Migration
  def self.up
    rename_column :note_annotations, :identifier, :predicate
    add_column :note_annotations, :namespace, :string, :limit => 50

    total = Note::Annotated::Base.count
    i = 0

    puts "starting #{total} note annotation conversions..."
    reset = "\r" + "\e[0K" # adapted from http://snippets.dzone.com/posts/show/3760

    Note::Annotated::Base.find_each do |annotation|
      print "#{reset}#{i += 1} / #{total}"

      old_identifier = annotation.predicate
      namespace, predicate = old_identifier.split(":", 2)
      annotation.predicate = predicate
      annotation.namespace = namespace
      annotation.save!

      $stdout.flush
    end

    print "#{reset}"
    $stdout.flush
    puts "note annotation conversion complete"
  end

  def self.down
    Note::Annotated::Base.find_each do |annotation|
      identifier = [annotation.namespace, annotation.predicate].join(":")
      annotation.predicate = identifier
      annotation.save!
    end
    rename_column :note_annotations, :predicate, :identifier
    remove_column :note_annotations, :namespace
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
iqvoc-3.2.11 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.2.10 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.2.9 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.0.6 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.0.5 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.0.4 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.0.3 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.0.2 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.2.8 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.0.1 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-4.0.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.5.7 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.5.6 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.5.5 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.5.4 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.2.7 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.5.3 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.5.2 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.5.1 db/migrate/20110525103100_separate_note_annotation_predicates.rb
iqvoc-3.5.0 db/migrate/20110525103100_separate_note_annotation_predicates.rb