diff --git a/gemfiles/5.2.gemfile b/gemfiles/5.2.gemfile index 034c497..9ec7a63 100644 --- a/gemfiles/5.2.gemfile +++ b/gemfiles/5.2.gemfile @@ -3,6 +3,6 @@ source "https://rubygems.org" gem "mysql2", "~> 0.4.10" gem "pg", "~> 0.15" gem "sqlite3", "~> 1.3.6" -gem "rails", "= 5.2.2.1" +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..e0f981e --- /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" + +gemspec :path => "../" diff --git a/lib/marginalia/comment.rb b/lib/marginalia/comment.rb index ae304c1..3a0bf3d 100644 --- a/lib/marginalia/comment.rb +++ b/lib/marginalia/comment.rb @@ -157,6 +157,11 @@ def self.db_host end end + def self.db_role + return if marginalia_adapter.pool.nil? + ActiveRecord::Base.current_role + end + def self.database if self.connection_config.present? self.connection_config[:database] diff --git a/test/query_comments_test.rb b/test/query_comments_test.rb index aad00c2..8744e52 100644 --- a/test/query_comments_test.rb +++ b/test/query_comments_test.rb @@ -17,6 +17,10 @@ def adapter_pool_available? Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('3.2.19') 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' @@ -245,6 +249,14 @@ def test_db_host assert_match %r{/\*db_host:localhost}, @queries.first 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_database Marginalia::Comment.components = [:database] API::V1::PostsController.action(:driver_only).call(@env)