summaryrefslogtreecommitdiff
path: root/doc/development/rails_initializers.md
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /doc/development/rails_initializers.md
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
downloadgitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
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.