Skip to content

Commit

Permalink
Added more debugging around restore.
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneeseguin committed Apr 27, 2012
1 parent 9f6f582 commit ad47f32
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/psql-cm/restore.rb
Expand Up @@ -19,16 +19,15 @@ def restore!
schema = cm_file.sub(".sql",'')
ensure_schema_exists(database,schema)


psqlrc_file = File.join(ENV['HOME'],'.psqlrc')
FileUtils.touch(psqlrc_file) unless File.exists?(psqlrc_file)
psqlrc = File.read(psqlrc_file)
File.open(psqlrc_file,'w') do |file|
file.rewind
file.write "SET search_path TO #{schema}; "
end
begin

begin
debug "restore> #{database}:#{schema} < #{cm_file}"
sh "psql #{db(database).psql_args} #{database} < #{cm_file}"

Expand All @@ -38,15 +37,18 @@ def restore!
WHERE is_base = $1 ORDER BY created_at ASC;"

Tempfile.open('base.sql') do |temp_file|
debug "restore:base:sql> #{sql.sub('$1','true')}"
row = db(database).exec(sql, ['true'])
temp_file.write(row)
sh "psql #{db(database).psql_args} #{database} < #{temp_file.path}"
end

debug "sql> #{sql}"
db(database).exec(sql,['false']).each do |row|
debug "change>\n#{row['content']}"
Tempfile.open('base.sql') do |temp_file|
debug "restore:changes:sql> #{sql.sub('$1','false')}"
changes = db(database).exec(sql,['false'])
debug "restore:change:count>#{changes.cmd_tuples}"
changes.each do |row|
debug "restore:change:content>\n#{row['content']}"
Tempfile.open('change.sql') do |temp_file|
temp_file.write(row['content'])
temp_file.close
sh "psql #{db(database).psql_args} #{database} < #{temp_file.path}"
Expand Down

0 comments on commit ad47f32

Please sign in to comment.