Skip to content

Instantly share code, notes, and snippets.

@RajatGoyal
Created May 5, 2019 10:32
Show Gist options
  • Save RajatGoyal/2029f26de9a957475e7256c8793d369b to your computer and use it in GitHub Desktop.
Save RajatGoyal/2029f26de9a957475e7256c8793d369b to your computer and use it in GitHub Desktop.
Monkey patch AbstractMysqlAdapter to set mysql 8 resource group while making a new connection
require 'active_record/connection_adapters/abstract_mysql_adapter'
module ActiveRecord
module ConnectionAdapters
class AbstractMysqlAdapter
alias :old_configure_connection :configure_connection
def configure_connection
begin
execute 'SET RESOURCE GROUP etl'
rescue ActiveRecord::StatementInvalid
Rails.logger.warn "Unable to set resource group 'etl'"
end
old_configure_connection
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment