From 0751e87fee6f8a2b58c7d10fb2d9648401e57e29 Mon Sep 17 00:00:00 2001 From: Amy Gurski Date: Wed, 12 May 2021 14:16:00 -0400 Subject: [PATCH 1/3] Update how payload config is fetched Rails 6.1 removed the connection id from the sql.active_record notification. With the current payload starting in rails 6.0, we can get config directly from the connection and in turn the database name that we care about. --- lib/sql_footprint.rb | 4 +--- sql_footprint.gemspec | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/sql_footprint.rb b/lib/sql_footprint.rb index f18e297..c008117 100644 --- a/lib/sql_footprint.rb +++ b/lib/sql_footprint.rb @@ -8,9 +8,7 @@ module SqlFootprint ActiveSupport::Notifications.subscribe('sql.active_record') do |_, _, _, _, payload| if @capture - adapter = ObjectSpace._id2ref(payload.fetch(:connection_id)) - config = adapter.instance_variable_get(:@config) || - adapter.instance_variable_get(:@connection_options) + config = payload.fetch(:connection).instance_variable_get(:@config) database_name = config.fetch(:database) capturers[database_name].capture payload.fetch(:sql) end diff --git a/sql_footprint.gemspec b/sql_footprint.gemspec index 267dedf..b660bc0 100644 --- a/sql_footprint.gemspec +++ b/sql_footprint.gemspec @@ -24,8 +24,8 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_dependency 'activerecord', ['>= 3.0'] - spec.add_dependency 'activesupport', ['>= 3.0'] + spec.add_dependency 'activerecord', ['>= 6.0', '< 7.0'] + spec.add_dependency 'activesupport', ['>= 6.0', '< 7.0'] spec.add_development_dependency 'bundler', ['>= 1.7', '< 3.0'] spec.add_development_dependency 'rake', '~> 10.0' From 0b43975c2712ded1c93a08cad9249510c1cc1458 Mon Sep 17 00:00:00 2001 From: Amy Gurski Date: Wed, 12 May 2021 14:56:25 -0400 Subject: [PATCH 2/3] Update readme and changelog --- History.md | 5 +++++ README.md | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/History.md b/History.md index 8e1f113..5ddae23 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +3.0.0 / 2021-05-12 +================== + + * Changes to support Rails 6.1. + * Fetch config for database name differently because rails removed the connection_id key from the sql.active_record notification. 1.0.0 / 2016-05-04 ================== diff --git a/README.md b/README.md index a72a523..d1e909a 100644 --- a/README.md +++ b/README.md @@ -60,16 +60,20 @@ before do end ``` -Or if you're using FactoryGirl you could do something like this: +Or if you're using FactoryBot you could do something like this: ```ruby RSpec.configure do |config| - module FactoryBoy + module FactoryKid def create(*args) - SqlFootprint.exclude { FactoryGirl.create(*args) } + SqlFootprint.exclude { FactoryBot.create(*args) } end end - config.include FactoryBoy + config.include FactoryKid end ``` +## Compatibility +- For Rails < 6.0 compatibility, please use v2.0.1. +- For Rails >= 6.0 compatibility, please use v3.0.0. + DO NOT run SqlFootprint in production! From 360c7f2e9a4f8786cb0fb8079b26e6706c9f5a34 Mon Sep 17 00:00:00 2001 From: Amy Gurski Date: Wed, 12 May 2021 14:56:38 -0400 Subject: [PATCH 3/3] Bump version to 3.0.0 --- lib/sql_footprint/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sql_footprint/version.rb b/lib/sql_footprint/version.rb index 86b784d..5a4fcd2 100644 --- a/lib/sql_footprint/version.rb +++ b/lib/sql_footprint/version.rb @@ -1,3 +1,3 @@ module SqlFootprint - VERSION = '2.0.1'.freeze + VERSION = '3.0.0'.freeze end