File obs-server-2.10-0121-ci-Make-db-structire-dump-task-compatible-with-Rails.patch of Package obs-server

From 29e561df9866d1a1185134f75ef2e868ceab54a9 Mon Sep 17 00:00:00 2001
From: Oleg Girko <ol@infoserver.lv>
Date: Sun, 27 Jun 2021 23:28:21 +0100
Subject: [PATCH] [ci] Make db:structire:dump task compatible with Rails 6.1.

The old method of extracting database configurations is deprecated,
using new one the way compatible with both Rails 6.0 and 6.1.

Signed-off-by: Oleg Girko <ol@infoserver.lv>
---
 src/api/lib/tasks/databases.rake | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/api/lib/tasks/databases.rake b/src/api/lib/tasks/databases.rake
index 4fa8eff846..1089ef3d5a 100644
--- a/src/api/lib/tasks/databases.rake
+++ b/src/api/lib/tasks/databases.rake
@@ -31,10 +31,19 @@ namespace :db do
     desc 'Dump the database structure to a SQL file'
     task dump: :environment do
       structure = ''
-      abcs = ActiveRecord::Base.configurations
-      case abcs[Rails.env]['adapter']
+      abcs = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env)
+      adapter = if abcs[0].respond_to?(:adapter)
+                  abcs[0].adapter
+                else
+                  abcs[0].config['adapter']
+                end
+      case adapter
       when 'mysql2'
-        ActiveRecord::Base.establish_connection(abcs[Rails.env])
+        begin
+          ActiveRecord::Base.establish_connection(abcs[0])
+        rescue TypeError
+          ActiveRecord::Base.establish_connection(abcs[0].config)
+        end
         con = ActiveRecord::Base.connection
 
         sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"
-- 
2.31.1