From aedc5f692144aa36245fe47c277bb5ad4766a335 Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Mon, 5 May 2025 15:01:16 +0200
Subject: [PATCH] Add warning for REDIS_NAMESPACE deprecation at startup
 (#34581)

---
 config/initializers/deprecations.rb | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 config/initializers/deprecations.rb

diff --git a/config/initializers/deprecations.rb b/config/initializers/deprecations.rb
new file mode 100644
index 0000000000..e0ad54d8c3
--- /dev/null
+++ b/config/initializers/deprecations.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+if ENV['REDIS_NAMESPACE']
+  es_configured = ENV['ES_ENABLED'] == 'true' || ENV.fetch('ES_HOST', 'localhost') != 'localhost' || ENV.fetch('ES_PORT', '9200') != '9200' || ENV.fetch('ES_PASS', 'password') != 'password'
+
+  warn <<~MESSAGE
+    WARNING: the REDIS_NAMESPACE environment variable is deprecated and will be removed in Mastodon 4.4.0.
+
+    Please see documentation at https://github.com/mastodon/redis_namespace_migration
+  MESSAGE
+
+  warn <<~MESSAGE if es_configured && !ENV['ES_PREFIX']
+
+    In addition, as REDIS_NAMESPACE is being used as a prefix for Elasticsearch, please do not forget to set ES_PREFIX to "#{ENV.fetch('REDIS_NAMESPACE')}".
+  MESSAGE
+end