mirror of
https://github.com/discourse/discourse.git
synced 2026-09-05 04:40:41 -05:00
FIX: Create readonly functions during backup
Temporarily recreate already dropped functions in the discourse_functions schema in order to allow restoring of backups which still reference dropped functions.
This commit is contained in:
@@ -22,7 +22,11 @@ module Migration
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.readonly_function_name(table_name, column_name = nil)
|
||||
def self.drop_readonly_function(table_name, column_name = nil)
|
||||
DB.exec("DROP FUNCTION IF EXISTS #{readonly_function_name(table_name, column_name)} CASCADE")
|
||||
end
|
||||
|
||||
def self.readonly_function_name(table_name, column_name = nil, with_schema: true)
|
||||
function_name = [
|
||||
"raise",
|
||||
table_name,
|
||||
@@ -30,12 +34,7 @@ module Migration
|
||||
"readonly()"
|
||||
].compact.join("_")
|
||||
|
||||
if DB.exec(<<~SQL).to_s == '1'
|
||||
SELECT schema_name
|
||||
FROM information_schema.schemata
|
||||
WHERE schema_name = '#{FUNCTION_SCHEMA_NAME}'
|
||||
SQL
|
||||
|
||||
if with_schema && function_schema_exists?
|
||||
"#{FUNCTION_SCHEMA_NAME}.#{function_name}"
|
||||
else
|
||||
function_name
|
||||
@@ -51,5 +50,21 @@ module Migration
|
||||
def self.readonly_trigger_name(table_name, column_name = nil)
|
||||
[table_name, column_name, "readonly"].compact.join("_")
|
||||
end
|
||||
|
||||
def self.function_schema_exists?
|
||||
DB.exec(<<~SQL).to_s == '1'
|
||||
SELECT schema_name
|
||||
FROM information_schema.schemata
|
||||
WHERE schema_name = '#{FUNCTION_SCHEMA_NAME}'
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.existing_discourse_function_names
|
||||
DB.query_single(<<~SQL)
|
||||
SELECT routine_name
|
||||
FROM information_schema.routines
|
||||
WHERE routine_type = 'FUNCTION' AND specific_schema = '#{FUNCTION_SCHEMA_NAME}'
|
||||
SQL
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,13 +28,11 @@ module Migration
|
||||
end
|
||||
end
|
||||
|
||||
def self.drop_readonly(table, column)
|
||||
DB.exec <<~SQL
|
||||
DROP FUNCTION IF EXISTS #{BaseDropper.readonly_function_name(table, column)} CASCADE;
|
||||
-- Backward compatibility for old functions created in the public
|
||||
-- schema
|
||||
DROP FUNCTION IF EXISTS #{BaseDropper.old_readonly_function_name(table, column)} CASCADE;
|
||||
SQL
|
||||
def self.drop_readonly(table_name, column_name)
|
||||
BaseDropper.drop_readonly_function(table_name, column_name)
|
||||
|
||||
# Backward compatibility for old functions created in the public schema
|
||||
DB.exec("DROP FUNCTION IF EXISTS #{BaseDropper.old_readonly_function_name(table_name, column_name)} CASCADE")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user