Skip to content

Commit e29ad0b

Browse files
MatheusRichbyroot
authored andcommitted
Enable query log tags by default on development env
This can be used to trace troublesome SQL statements back to the application code that generated these statements.
1 parent fb7ef5e commit e29ad0b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

railties/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Enable query log tags by default on development env
2+
3+
This can be used to trace troublesome SQL statements back to the application
4+
code that generated these statements. It is also useful when using multiple
5+
databases because the query logs can identify which database is being used.
6+
7+
*Matheus Richard*
8+
19
* Defer route drawing to the first request, or when url_helpers are called
210

311
Executes the first routes reload in middleware, or when a route set's

railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Rails.application.configure do
5959
# Highlight code that triggered database queries in logs.
6060
config.active_record.verbose_query_logs = true
6161

62+
# Append comments with runtime information tags to SQL queries in logs.
63+
config.active_record.query_log_tags_enabled = true
64+
6265
<%- end -%>
6366
<%- unless options[:skip_active_job] -%>
6467
# Highlight code that enqueued background job in logs.

railties/test/application/configuration_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4737,6 +4737,14 @@ class Foo < ApplicationRecord
47374737
assert_equal "SQLite", ActiveRecord::Base.lease_connection.adapter_name
47384738
end
47394739

4740+
test "In development mode, config.active_record.query_log_tags_enabled is true by default" do
4741+
restore_default_config
4742+
4743+
app "development"
4744+
4745+
assert Rails.application.config.active_record.query_log_tags_enabled
4746+
end
4747+
47404748
["development", "production"].each do |env|
47414749
test "active job adapter is async in #{env}" do
47424750
app(env)

0 commit comments

Comments
 (0)