Sha256: a3bc43d58fa59478c4085e2393968d6b5c90d617c63b6f042be22b76b01419c1
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
module Prick class Diff def initialize(db1, db2) @db1, @db2 = db1, db2 @diffed = false @diff = nil @result = nil end def self.same?(db1, db2) Diff.new(db1, db2).same? end # Return true if the two databases are equal. Named #same? to avoid name # collision with the built in #equal? def same? do_diff if @result.nil? @result end # Return the diff between the two databases or nil if they're equal def read @diffed ? @diff : do_diff end # Write the diff between the databases to the given file. Return true if # the databases are equal def write(file) if @diffed IO.write(file, @diff) else do_diff(file) end @result end private def do_diff(file = nil) file_arg = file ? ">#{file}" : "" command = "migra --unsafe postgres:///#{@db1} postgres:///#{@db2} #{file_arg}" stdout = Command.command command, fail: false [0,2].include? Command.status or raise Fail, "migra command failed with status #{Command.status}: #{command}" @result = Command.status == 0 @diffed = !file @diff = @diffed && !@result ? stdout : nil end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
prick-0.4.0 | lib/prick/diff.rb |
prick-0.3.0 | lib/prick/diff.rb |