From 315cc23f0e0ea8ffc22b3ba5d0c605dd3c758777 Mon Sep 17 00:00:00 2001 From: Thomas Hareau Date: Thu, 2 Nov 2023 13:09:51 +0100 Subject: [PATCH] Fix: options not propagated in blocking activity logger --- .../plugins/blocking_activity_logger.rb | 5 +++++ test/StatementInsurer/remove_column_test.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/safe-pg-migrations/plugins/blocking_activity_logger.rb b/lib/safe-pg-migrations/plugins/blocking_activity_logger.rb index a887ecfb..9f03665c 100644 --- a/lib/safe-pg-migrations/plugins/blocking_activity_logger.rb +++ b/lib/safe-pg-migrations/plugins/blocking_activity_logger.rb @@ -11,6 +11,11 @@ module BlockingActivityLogger RETRIABLE_SCHEMA_STATEMENTS.each do |method| define_method method do |*args, **options, &block| + args, options = if args.last.is_a?(Hash) + [args[..-2], args.last] + else + [args, {}] + end log_context = lambda do break unless SafePgMigrations.config.sensitive_logger diff --git a/test/StatementInsurer/remove_column_test.rb b/test/StatementInsurer/remove_column_test.rb index 1c55abbb..1cfd0e64 100644 --- a/test/StatementInsurer/remove_column_test.rb +++ b/test/StatementInsurer/remove_column_test.rb @@ -55,5 +55,20 @@ def change assert_equal ['ALTER TABLE "users" DROP COLUMN "name"'], calls[2] end + + def test_remove_column_with_default_arguments + @connection.create_table(:users) { |t| t.string :name } + + @migration = + Class.new(ActiveRecord::Migration::Current) do + def change + remove_column(:users, :name, :string, null: false, default: 'Benaaaa') + end + end.new + + calls = record_calls(@connection, :execute) { run_migration } + + assert_equal ['ALTER TABLE "users" DROP COLUMN "name"'], calls[2] + end end end