summaryrefslogtreecommitdiff
path: root/doc/development/rails_initializers.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/development/rails_initializers.md')
-rw-r--r--doc/development/rails_initializers.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/development/rails_initializers.md b/doc/development/rails_initializers.md
index ee73dac2b72..9bf4109f1cb 100644
--- a/doc/development/rails_initializers.md
+++ b/doc/development/rails_initializers.md
@@ -20,3 +20,21 @@ Some examples where you would need to do this are:
1. Modifying Rails' `config.autoload_paths`
1. Changing configuration that Zeitwerk uses, for example, inflections
+
+## Database connections in initializers
+
+Ideally, database connections are not opened from Rails initializers. Opening a
+database connection (e.g. checking the database exists, or making a database
+query) from an initializer means that tasks like `db:drop`, and
+`db:test:prepare` will fail because an active session prevents the database from
+being dropped.
+
+To help detect when database connections are opened from initializers, we now
+warn in stderr. For example:
+
+```shell
+DEPRECATION WARNING: Database connection should not be called during initializers (called from block in <module:HasVariable> at app/models/concerns/ci/has_variable.rb:22)
+```
+
+If you wish to print out the full backtrace, set the
+`DEBUG_INITIALIZER_CONNECTIONS` environment variable.