Backward compatibility for dropping functions in ColumnDropper.

https://meta.discourse.org/t/launcher-rebuild-error-pg-error-schema-discourse-functions-does-not-exist/96209
This commit is contained in:
Guo Xiang Tan 2018-09-17 14:44:29 +08:00
parent 6659417807
commit b71af05d62
3 changed files with 22 additions and 1 deletions

View File

@ -82,7 +82,22 @@ module Migration
"readonly()"
].compact.join("_")
"#{FUNCTION_SCHEMA_NAME}.#{function_name}"
if DB.exec(<<~SQL).to_s == '1'
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name = '#{FUNCTION_SCHEMA_NAME}'
SQL
"#{FUNCTION_SCHEMA_NAME}.#{function_name}"
else
function_name
end
end
def self.old_readonly_function_name(table_name, column_name = nil)
readonly_function_name(table_name, column_name).sub(
"#{FUNCTION_SCHEMA_NAME}.", ''
)
end
def self.readonly_trigger_name(table_name, column_name = nil)

View File

@ -57,6 +57,9 @@ module Migration
DB.exec <<~SQL
DROP TRIGGER IF EXISTS #{BaseDropper.readonly_trigger_name(@table, column)} ON #{@table};
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
# safe cause it is protected on method entry, can not be passed in params

View File

@ -75,6 +75,9 @@ module Migration
DB.exec <<~SQL
DROP FUNCTION IF EXISTS #{BaseDropper.readonly_function_name(@old_name)} CASCADE;
-- Backward compatibility for old functions created in the public
-- schema
DROP FUNCTION IF EXISTS #{BaseDropper.old_readonly_function_name(@old_name)} CASCADE;
SQL
end
end