FIX: sed on OSX sucks and doesn't work with the same commands as on

most Linux machines. This regexp is compatible with both.
This commit is contained in:
Robin Ward 2014-03-21 11:57:33 -04:00
parent e8c53d171a
commit c1b4f5b80b

View file

@ -199,19 +199,19 @@ module Export
# - create the "restore" schema
# - prepend the "restore" schema into the search_path
regexp = "^SET search_path = public, pg_catalog;$"
regexp = "SET search_path = public, pg_catalog;"
replacement = [ "DROP SCHEMA IF EXISTS restore CASCADE;",
"CREATE SCHEMA restore;",
"SET search_path = restore, public, pg_catalog;",
].join("\\n")
].join(" ")
# we only want to replace the VERY first occurence of the search_path command
expression = "0,/#{regexp}/s//#{replacement}/"
expression = "1,/^#{regexp}$/s/#{regexp}/#{replacement}/"
# I tried to use the --in-place argument but it was SLOOOWWWWwwwwww
# so I output the result into another file and rename it back afterwards
[ "sed --expression='#{expression}' < #{@dump_filename} > #{@dump_filename}.tmp",
[ "sed -e '#{expression}' < #{@dump_filename} > #{@dump_filename}.tmp",
"&&",
"mv #{@dump_filename}.tmp #{@dump_filename}",
].join(" ")