FIX: Drop readonly function when dropping table

This commit is contained in:
Gerhard Schlager 2019-08-08 16:58:13 +02:00
parent 7cb51d0e40
commit 74d78e3636
2 changed files with 21 additions and 0 deletions

View File

@ -18,6 +18,7 @@ module Migration
def self.execute_drop(table_name) def self.execute_drop(table_name)
DB.exec("DROP TABLE IF EXISTS #{table_name}") DB.exec("DROP TABLE IF EXISTS #{table_name}")
BaseDropper.drop_readonly_function(table_name)
end end
end end
end end

View File

@ -14,6 +14,16 @@ describe Migration::TableDropper do
SQL SQL
end end
def function_exists?(function_name, schema_name = 'public')
DB.exec(<<~SQL) > 0
SELECT 1
FROM information_schema.routines
WHERE routine_type = 'FUNCTION' AND
routine_name = '#{function_name}' AND
specific_schema = '#{schema_name}'
SQL
end
let(:table_name) { 'table_with_old_name' } let(:table_name) { 'table_with_old_name' }
before do before do
@ -56,6 +66,16 @@ describe Migration::TableDropper do
expect(table_exists?(table_name)).to eq(false) expect(table_exists?(table_name)).to eq(false)
end end
it "should drop the read_only function" do
Migration::TableDropper.execute_drop(table_name)
schema_name, function_name = Migration::BaseDropper
.readonly_function_name(table_name)
.delete_suffix('()').split('.')
expect(function_exists?(function_name, schema_name)).to eq(false)
end
it 'should prevent insertions to the table' do it 'should prevent insertions to the table' do
begin begin
DB.exec <<~SQL DB.exec <<~SQL