diff --git a/gemfiles/5.2.gemfile b/gemfiles/5.2.gemfile new file mode 100644 index 0000000..9ec7a63 --- /dev/null +++ b/gemfiles/5.2.gemfile @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gem "mysql2", "~> 0.4.10" +gem "pg", "~> 0.15" +gem "sqlite3", "~> 1.3.6" +gem "rails", "= 5.2.5" + +gemspec :path => "../" diff --git a/gemfiles/6.0.gemfile b/gemfiles/6.0.gemfile new file mode 100644 index 0000000..5674d9f --- /dev/null +++ b/gemfiles/6.0.gemfile @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gem "mysql2", "~> 0.4.10" +gem "pg", "~> 0.15" +gem "sqlite3", "~> 1.3.6" +gem "rails", "= 6.0.3.6" + +gemspec :path => "../" diff --git a/lib/marginalia/comment.rb b/lib/marginalia/comment.rb index f4a77de..52ac44a 100644 --- a/lib/marginalia/comment.rb +++ b/lib/marginalia/comment.rb @@ -162,6 +162,11 @@ def self.database end end + def self.db_role + return if marginalia_adapter.pool.nil? + ActiveRecord::Base.current_role + end + if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('6.1') def self.connection_config return if marginalia_adapter.pool.nil? diff --git a/test/query_comments_test.rb b/test/query_comments_test.rb index a5cb9c9..2cb06fe 100644 --- a/test/query_comments_test.rb +++ b/test/query_comments_test.rb @@ -9,6 +9,10 @@ def pool_db_config? Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('6.1') end +def database_role_available? + Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('6.0.0') +end + require "minitest/autorun" require "mocha/minitest" require 'logger' @@ -259,6 +263,14 @@ def test_socket end end + if database_role_available? + def test_db_role + Marginalia::Comment.components = [:db_role] + API::V1::PostsController.action(:driver_only).call(@env) + assert_match %r{/\*db_role:writing}, @queries.first + end + end + def test_request_id @env["action_dispatch.request_id"] = "some-uuid" Marginalia::Comment.components = [:request_id]