From 8f1db615db35a82b9adcbb001acf149e09ffa65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 30 Jul 2018 22:11:38 +0200 Subject: [PATCH] FIX: don't break restore if function does not exist --- lib/backup_restore/restorer.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb index f3b7ffbe5a0..56d37480fe3 100644 --- a/lib/backup_restore/restorer.rb +++ b/lib/backup_restore/restorer.rb @@ -65,18 +65,22 @@ module BackupRestore BackupRestore.move_tables_between_schemas("public", "backup") - # This is a temp fix to allow restores to work again. @tgxworld is - # current working on a fix that namespaces functions created by Discourse - # so that we can alter the schema of those functions before restoring. + # This is a temp fix to allow restores to work again. + # @tgxworld is currently working on a fix that namespaces functions + # created by Discourse so that we can alter the schema of those + # functions before restoring. %w{ raise_email_logs_reply_key_readonly raise_email_logs_skipped_reason_readonly }.each do |function| - DB.exec(<<~SQL) - DROP FUNCTION IF EXISTS backup.#{function}; - ALTER FUNCTION public.#{function} - SET SCHEMA "backup"; - SQL + begin + DB.exec(<<~SQL) + DROP FUNCTION IF EXISTS backup.#{function}; + ALTER FUNCTION public.#{function} SET SCHEMA "backup"; + SQL + rescue PG::UndefinedFunction + # the function does not exist, no need to worry about this + end end @db_was_changed = true