When applying a script, make sure we ONLY record the script if it applies correctly

 - This is a bit subtle as we need to set the ON_ERROR_STOP variable
   in the psql session - otherwise the psql command returns a
   result code of 0 even if the script had errors