diff --git a/lib/safe-pg-migrations/plugins/statement_insurer.rb b/lib/safe-pg-migrations/plugins/statement_insurer.rb index 4e82d64..bab7caf 100644 --- a/lib/safe-pg-migrations/plugins/statement_insurer.rb +++ b/lib/safe-pg-migrations/plugins/statement_insurer.rb @@ -85,42 +85,21 @@ def change_column_null(table_name, column_name, null, default = nil) remove_check_constraint table_name, "#{column_name} IS NOT NULL" end - def remove_column(table_name, column_name, *) foreign_key = foreign_key_for(table_name, column: column_name) - with_setting(:statement_timeout, SafePgMigrations.config.pg_statement_timeout) do - remove_foreign_key(table_name, name: foreign_key.name) if foreign_key - super - end - end - - ruby2_keywords def drop_table(table_name, *args) - foreign_keys(table_name).each do |foreign_key| - with_setting(:statement_timeout, SafePgMigrations.config.pg_statement_timeout) do - remove_foreign_key(table_name, name: foreign_key.name) - end - end - - Helpers::Logger.say_method_call :drop_table, table_name, *args - - with_setting(:statement_timeout, SafePgMigrations.config.pg_statement_timeout) do - super(table_name, *args) - end + remove_foreign_key(table_name, name: foreign_key.name) if foreign_key + super end ruby2_keywords def drop_table(table_name, *args) foreign_keys(table_name).each do |foreign_key| - with_setting(:statement_timeout, SafePgMigrations.config.pg_statement_timeout) do - remove_foreign_key(table_name, name: foreign_key.name) - end + remove_foreign_key(table_name, name: foreign_key.name) end Helpers::Logger.say_method_call :drop_table, table_name, *args - with_setting(:statement_timeout, SafePgMigrations.config.pg_statement_timeout) do - super(table_name, *args) - end + super(table_name, *args) end end end diff --git a/test/IdempotentStatements/drop_table_test.rb b/test/IdempotentStatements/drop_table_test.rb index 832ee7e..3ace1d0 100644 --- a/test/IdempotentStatements/drop_table_test.rb +++ b/test/IdempotentStatements/drop_table_test.rb @@ -29,12 +29,8 @@ def test_first_fk_already_removed calls = record_calls(@connection, :execute) { run_migration } assert_calls <<~CALLS.strip.split("\n"), calls - SET statement_timeout TO '5s' ALTER TABLE "users" DROP CONSTRAINT "fk_rails_d15efa01b1" - SET statement_timeout TO '70s' - SET statement_timeout TO '5s' DROP TABLE "users" - SET statement_timeout TO '70s' CALLS end @@ -44,11 +40,7 @@ def test_fks_already_removed calls = record_calls(@connection, :execute) { run_migration } - assert_calls <<~CALLS.strip.split("\n"), calls - SET statement_timeout TO '5s' - DROP TABLE "users" - SET statement_timeout TO '70s' - CALLS + assert_calls ['DROP TABLE "users"'], calls end end end diff --git a/test/StatementInsurer/drop_table_test.rb b/test/StatementInsurer/drop_table_test.rb index 7ca46c8..868a60f 100644 --- a/test/StatementInsurer/drop_table_test.rb +++ b/test/StatementInsurer/drop_table_test.rb @@ -16,8 +16,9 @@ def change calls = record_calls(@connection, :execute) { run_migration } - assert_calls ["SET statement_timeout TO '5s'", 'DROP TABLE "users"', "SET statement_timeout TO '70s'"], - calls + assert_calls <<~CALLS.strip.split("\n"), calls + DROP TABLE "users" + CALLS end def test_can_drop_table_with_foreign_key @@ -36,14 +37,10 @@ def change calls = record_calls(@connection, :execute) { run_migration } - assert_calls [ - "SET statement_timeout TO '5s'", - 'ALTER TABLE "users" DROP CONSTRAINT "fk_rails_253ea793f9"', - "SET statement_timeout TO '70s'", - "SET statement_timeout TO '5s'", - 'DROP TABLE "users"', - "SET statement_timeout TO '70s'", - ], calls + assert_calls <<~CALLS.strip.split("\n"), calls + ALTER TABLE "users" DROP CONSTRAINT "fk_rails_253ea793f9" + DROP TABLE "users" + CALLS end def test_can_drop_table_with_several_foreign_keys @@ -64,17 +61,11 @@ def change calls = record_calls(@connection, :execute) { run_migration } - assert_calls [ - "SET statement_timeout TO '5s'", - 'ALTER TABLE "users" DROP CONSTRAINT "fk_rails_253ea793f9"', - "SET statement_timeout TO '70s'", - "SET statement_timeout TO '5s'", - 'ALTER TABLE "users" DROP CONSTRAINT "fk_rails_d15efa01b1"', - "SET statement_timeout TO '70s'", - "SET statement_timeout TO '5s'", - 'DROP TABLE "users"', - "SET statement_timeout TO '70s'", - ], calls + assert_calls <<~CALLS.strip.split("\n"), calls + ALTER TABLE "users" DROP CONSTRAINT "fk_rails_253ea793f9" + ALTER TABLE "users" DROP CONSTRAINT "fk_rails_d15efa01b1" + DROP TABLE "users" + CALLS end end end diff --git a/test/StatementInsurer/remove_column_test.rb b/test/StatementInsurer/remove_column_test.rb index 7e2a6fb..1c55abb 100644 --- a/test/StatementInsurer/remove_column_test.rb +++ b/test/StatementInsurer/remove_column_test.rb @@ -18,8 +18,10 @@ def change calls = record_calls(@connection, :execute) { run_migration } - assert_equal ['ALTER TABLE "users" DROP CONSTRAINT "fk_rails_baad13daec"'], calls[2] - assert_equal ['ALTER TABLE "users" DROP COLUMN "password_id"'], calls[3] + assert_calls <<~CALLS.strip.split("\n"), calls + ALTER TABLE "users" DROP CONSTRAINT "fk_rails_baad13daec" + ALTER TABLE "users" DROP COLUMN "password_id" + CALLS end def test_can_remove_column_with_foreign_key_on_other_column