Sha256: f9f2c153a24ef1752d4c334068b2e42ce7a6e85fba06619f2c404e0cab63e9b7
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
module CouchTomato class Migration class << self # Execute this migration in the named direction def migrate(direction, db) return unless respond_to?(direction) case direction when :up then announce "migrating" when :down then announce "reverting" end time = Benchmark.measure do docs = db.get('_all_docs', :include_docs => true)['rows'] docs.each do |doc| next if /^_design/ =~ doc['id'] send(direction, doc['doc']) end db.bulk_save(docs) end case direction when :up then announce "migrated (%.4fs)" % time.real; write when :down then announce "reverted (%.4fs)" % time.real; write end end def write(text="") puts(text) end def announce(message) text = "#{@version} #{name}: #{message}" length = [0, 75 - text.length].max write "== %s %s" % [text, "=" * length] end def say(message, subitem=false) write "#{subitem ? " ->" : "--"} #{message}" end def say_with_time(message) say(message) result = nil time = Benchmark.measure { result = yield } say "%.4fs" % time.real, :subitem say("#{result} rows", :subitem) if result.is_a?(Integer) result end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
couch_tomato-0.1.3 | lib/couch_tomato/migration.rb |
couch_tomato-0.1.2 | lib/couch_tomato/migration.rb |