mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Restoring backup from PG12 could fail on PG10
The `EXECUTE FUNCTION` syntax for `CREATE TRIGGER` statements was introduced in PostgreSQL 11. We need to replace `EXECUTE FUNCTION` with `EXECUTE PROCEDURE` in order to be able to restore backups created with PG12 on PG10.
This commit is contained in:
@ -95,7 +95,8 @@ module BackupRestore
|
||||
raise DatabaseRestoreError.new("psql failed: #{last_line}") if Process.last_status&.exitstatus != 0
|
||||
end
|
||||
|
||||
# Removes unwanted SQL added by certain versions of pg_dump.
|
||||
# Removes unwanted SQL added by certain versions of pg_dump and modifies
|
||||
# the dump so that it works on the current version of PostgreSQL.
|
||||
def sed_command
|
||||
unwanted_sql = [
|
||||
"DROP SCHEMA", # Discourse <= v1.5
|
||||
@ -104,11 +105,15 @@ module BackupRestore
|
||||
"SET default_table_access_method" # PostgreSQL 12
|
||||
].join("|")
|
||||
|
||||
"sed -E '/^(#{unwanted_sql})/d'"
|
||||
command = "sed -E '/^(#{unwanted_sql})/d' #{@db_dump_path}"
|
||||
if BackupRestore.postgresql_major_version < 11
|
||||
command = "#{command} | sed -E 's/^(CREATE TRIGGER.+EXECUTE) FUNCTION/\\1 PROCEDURE/'"
|
||||
end
|
||||
command
|
||||
end
|
||||
|
||||
def restore_dump_command
|
||||
"#{sed_command} #{@db_dump_path} | #{self.class.psql_command} 2>&1"
|
||||
"#{sed_command} | #{self.class.psql_command} 2>&1"
|
||||
end
|
||||
|
||||
def self.psql_command
|
||||
|
Reference in New Issue
Block a user