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:
Gerhard Schlager
2019-08-08 16:06:27 +02:00
parent 8aa5df69f0
commit 7cb51d0e40
11 changed files with 164 additions and 43 deletions

View File

@ -32,4 +32,36 @@ describe 'Coding style' do
MSG
end
end
describe 'Post Migrations' do
def check_offenses(files, method_name, constant_name)
method_name_regex = /#{Regexp.escape(method_name)}/
constant_name_regex = /#{Regexp.escape(constant_name)}/
offenses = files.reject { |file| is_valid?(file, method_name_regex, constant_name_regex) }
expect(offenses).to be_empty, <<~MSG
You need to use the constant #{constant_name} when you use
#{method_name} in order to help with restoring backups.
Please take a look at existing migrations to see how to use it correctly.
Offenses:
#{offenses.join("\n")}
MSG
end
def is_valid?(file, method_name_regex, constant_name_regex)
contains_method_name = File.open(file).grep(method_name_regex).any?
contains_constant_name = File.open(file).grep(constant_name_regex).any?
contains_method_name ? contains_constant_name : true
end
it 'ensures dropped tables and columns are stored in constants' do
migration_files = list_files('db/post_migrate', '**/*.rb')
check_offenses(migration_files, "ColumnDropper.execute_drop", "DROPPED_COLUMNS")
check_offenses(migration_files, "TableDropper.execute_drop", "DROPPED_TABLES")
end
end
end