lib/wyrm/dump_schema.rb in wyrm-0.1.4 vs lib/wyrm/dump_schema.rb in wyrm-0.2.0

- old
+ new

@@ -1,37 +1,26 @@ require 'logger' -require 'wyrm/db_pump' +require 'wyrm/pump_maker' -class Object - def call_or_self( maybe_callable ) - if maybe_callable.respond_to? :call - maybe_callable.call( self ) - else - maybe_callable - end - end -end - # Dump a schema and compressed data from a db to a set of files # src_db = Sequel.connect "postgres://localhost:5454/lots" # ds = DumpSchema.new src_db, Pathname('/var/data/lots') # ds.dump_schema # ds.dump_tables class DumpSchema + include PumpMaker + def initialize( src_db, container = nil, pump: nil ) - src_db.extension :schema_dumper - @src_db = src_db - @container = Pathname(container) - @pump = make_pump( pump ) + @src_db = maybe_deebe src_db + @container = Pathname.new container + @pump = make_pump( @src_db, pump ) + + @src_db.extension :schema_dumper end attr_reader :src_db, :container, :pump - def make_pump( pump_thing ) - call_or_self(pump_thing) || DbPump.new( src_db, nil ) - end - def schema_migration @schema_migration ||= src_db.dump_schema_migration(:indexes=>false, :same_db => same_db) end def index_migration @@ -114,14 +103,20 @@ zio.close unless zio.closed? fio.close unless fio.closed? end def dump_table( table_name ) + pump.table_name = table_name + if pump.table_dataset.empty? + logger.info "No records in #{table_name}" + return + end + filename = container + "#{table_name}.dbp.bz2" logger.info "dumping #{table_name} to #{filename}" + open_bz2 filename do |zio| # generate the dump - pump.table_name = table_name pump.io = zio pump.dump end rescue logger.error "failed dumping #{table_name}: #{$!.message}"