diff --git a/CHANGELOG.md b/CHANGELOG.md index d249696ac..35da98a87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ #### Changed -- ... +- [#941](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/941) No longer support configuring the application name by overriding the 'configure_application_name' method. #### Added diff --git a/README.md b/README.md index 9c6727c88..9ac67f0b7 100644 --- a/README.md +++ b/README.md @@ -82,28 +82,34 @@ end ``` -#### Configure Connection & App Name +#### Configure Connection -We currently conform to an unpublished and non-standard AbstractAdapter interface to configure connections made to the database. To do so, just override the `configure_connection` method in an initializer like so. In this case below we are setting the `TEXTSIZE` to 64 megabytes. Also, TinyTDS supports an application name when it logs into SQL Server. This can be used to identify the connection in SQL Server's activity monitor. By default it will use the `appname` from your database.yml file or a lowercased version of your Rails::Application name. It is now possible to define a `configure_application_name` method that can give you per instance details. Below shows how you might use this to get the process id and thread id of the current connection. +We currently conform to an unpublished and non-standard AbstractAdapter interface to configure connections made to the database. To do so, just override the `configure_connection` method in an initializer like so. In this case below we are setting the `TEXTSIZE` to 64 megabytes. ```ruby module ActiveRecord module ConnectionAdapters class SQLServerAdapter < AbstractAdapter - def configure_connection raw_connection_do "SET TEXTSIZE #{64.megabytes}" end - - def configure_application_name - "myapp_#{$$}_#{Thread.current.object_id}".to(29) - end - end end end ``` +#### Configure Application Name + +TinyTDS supports an application name when it logs into SQL Server. This can be used to identify the connection in SQL Server's activity monitor. By default it will use the `appname` from your database.yml file or your Rails::Application name. + +Below shows how you might use the database.yml file to use the process ID in your application name. + +```yaml +development: + adapter: sqlserver + appname: <%= myapp_#{Process.pid} %> +``` + #### Executing Stored Procedures Every class that sub classes ActiveRecord::Base will now have an execute_procedure class method to use. This method takes the name of the stored procedure which can be a string or symbol and any number of variables to pass to the procedure. Arguments will automatically be quoted per the connection's standards as normal. For example: diff --git a/lib/active_record/connection_adapters/sqlserver_adapter.rb b/lib/active_record/connection_adapters/sqlserver_adapter.rb index adc5f0c0b..22b420b8c 100644 --- a/lib/active_record/connection_adapters/sqlserver_adapter.rb +++ b/lib/active_record/connection_adapters/sqlserver_adapter.rb @@ -105,7 +105,23 @@ def dblib_connect(config) end def config_appname(config) - config[:appname] || configure_application_name || Rails.application.class.name.split("::").first rescue nil + if self.instance_methods.include?(:configure_application_name) + ActiveSupport::Deprecation.warn <<~MSG.squish + Configuring the application name used by TinyTDS by overriding the + `ActiveRecord::ConnectionAdapters::SQLServerAdapter#configure_application_name` + instance method is no longer supported. The application name should configured + using the `appname` setting in the `database.yml` file instead. Consult the + README for further information." + MSG + end + + config[:appname] || rails_application_name + end + + def rails_application_name + return nil if Rails.application.nil? + + Rails.application.class.name.split("::").first end def config_login_timeout(config) @@ -483,8 +499,6 @@ def connection_errors end end - def configure_application_name; end - def initialize_dateformatter @database_dateformat = user_options_dateformat a, b, c = @database_dateformat.each_char.to_a