mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
FIX: Create BaseDropper
functions in a different schema.
https://meta.discourse.org/t/error-when-restore-db-backup/93145/25?u=tgxworld
This commit is contained in:
parent
db05ab1868
commit
212ee15804
@ -65,24 +65,6 @@ module BackupRestore
|
||||
|
||||
BackupRestore.move_tables_between_schemas("public", "backup")
|
||||
|
||||
# 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|
|
||||
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
|
||||
restore_dump
|
||||
migrate_database
|
||||
|
@ -1,5 +1,7 @@
|
||||
module Migration
|
||||
class BaseDropper
|
||||
FUNCTION_SCHEMA_NAME = "discourse_functions".freeze
|
||||
|
||||
def initialize(after_migration, delay, on_drop, after_drop)
|
||||
@after_migration = after_migration
|
||||
@on_drop = on_drop
|
||||
@ -46,6 +48,10 @@ module Migration
|
||||
end
|
||||
|
||||
def self.create_readonly_function(table_name, column_name = nil)
|
||||
DB.exec <<~SQL
|
||||
CREATE SCHEMA IF NOT EXISTS #{FUNCTION_SCHEMA_NAME};
|
||||
SQL
|
||||
|
||||
message = column_name ?
|
||||
"Discourse: #{column_name} in #{table_name} is readonly" :
|
||||
"Discourse: #{table_name} is read only"
|
||||
@ -69,7 +75,14 @@ module Migration
|
||||
end
|
||||
|
||||
def self.readonly_function_name(table_name, column_name = nil)
|
||||
["raise", table_name, column_name, "readonly()"].compact.join("_")
|
||||
function_name = [
|
||||
"raise",
|
||||
table_name,
|
||||
column_name,
|
||||
"readonly()"
|
||||
].compact.join("_")
|
||||
|
||||
"#{FUNCTION_SCHEMA_NAME}.#{function_name}"
|
||||
end
|
||||
|
||||
def self.readonly_trigger_name(table_name, column_name = nil)
|
||||
|
@ -152,19 +152,23 @@ RSpec.describe Migration::ColumnDropper do
|
||||
)
|
||||
|
||||
expect(dropped_proc_called).to eq(true)
|
||||
|
||||
end
|
||||
|
||||
it 'should prevent updates to the readonly column' do
|
||||
expect do
|
||||
begin
|
||||
DB.exec <<~SQL
|
||||
UPDATE #{table_name}
|
||||
SET email = 'testing@email.com'
|
||||
WHERE topic_id = 1;
|
||||
SQL
|
||||
end.to raise_error(
|
||||
PG::RaiseException,
|
||||
/Discourse: email in #{table_name} is readonly/
|
||||
)
|
||||
rescue PG::RaiseException => e
|
||||
[
|
||||
"Discourse: email in #{table_name} is readonly",
|
||||
'discourse_functions.raise_table_with_readonly_column_email_readonly()'
|
||||
].each do |message|
|
||||
expect(e.message).to include(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should allow updates to the other columns' do
|
||||
|
Loading…
Reference in New Issue
Block a user