From a69364b7805fe6b35dea285b9aeffcd415dabb20 Mon Sep 17 00:00:00 2001
From: maru <marllonwes@hotmail.com>
Date: Tue, 14 Sep 2021 11:50:21 -0300
Subject: [PATCH] Fixed> db:drop task, old migration, password recovery

---
 .../initializers/postgresql_database_tasks.rb | 12 ++++++++--
 db/migrate/20160512143532_create_versions.rb  |  5 ++--
 ...20210902130554_add_user_password_change.rb | 23 +++++++++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)
 create mode 100644 db/migrate/20210902130554_add_user_password_change.rb

diff --git a/config/initializers/postgresql_database_tasks.rb b/config/initializers/postgresql_database_tasks.rb
index 192d73e09..83e3b543d 100644
--- a/config/initializers/postgresql_database_tasks.rb
+++ b/config/initializers/postgresql_database_tasks.rb
@@ -20,10 +20,18 @@
 module ActiveRecord
   module Tasks
     class PostgreSQLDatabaseTasks
+      
+      def initialize(db_config)
+        @db_config = db_config
+        @configuration_hash = db_config.configuration_hash
+      end
+      
       def drop
         establish_master_connection
-        connection.select_all "select pg_terminate_backend(pg_stat_activity.pid) from pg_stat_activity where datname='#{configuration['database']}' AND state='idle';"
-        connection.drop_database configuration['database']
+        connection.drop_database(db_config.database)
+        # establish_master_connection
+        # connection.select_all "select pg_terminate_backend(pg_stat_activity.pid) from pg_stat_activity where datname='#{configuration_hash['database']}' AND state='idle';"
+        # connection.drop_database configuration_hash['database']
       end
     end
   end
diff --git a/db/migrate/20160512143532_create_versions.rb b/db/migrate/20160512143532_create_versions.rb
index d23847bde..27548ff6b 100644
--- a/db/migrate/20160512143532_create_versions.rb
+++ b/db/migrate/20160512143532_create_versions.rb
@@ -35,7 +35,8 @@ class CreateVersions < ActiveRecord::Migration[4.2]
   TEXT_BYTES = 1_073_741_823
 
   def change
-    create_table :versions, versions_table_options do |t|
+    # create_table :versions, versions_table_options do |t|
+    create_table :versions do |t|
       t.string   :item_type, null: false
       t.integer  :item_id,   null: false
       t.string   :event,     null: false
@@ -81,7 +82,7 @@ class CreateVersions < ActiveRecord::Migration[4.2]
     if MYSQL_ADAPTERS.include?(connection.class.name)
       { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" }
     else
-      {}
+      nil
     end
   end
 end
diff --git a/db/migrate/20210902130554_add_user_password_change.rb b/db/migrate/20210902130554_add_user_password_change.rb
new file mode 100644
index 000000000..81cbc7de6
--- /dev/null
+++ b/db/migrate/20210902130554_add_user_password_change.rb
@@ -0,0 +1,23 @@
+# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
+# Departamento de Informatica - Universidade Federal do Parana
+#
+# This file is part of portalmec.
+#
+# portalmec is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# portalmec is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with portalmec.  If not, see <http://www.gnu.org/licenses/>.
+
+class AddUserPasswordChange < ActiveRecord::Migration[6.1]
+  def change
+    add_column :users, :allow_password_change, :boolean, default: false
+  end
+end
-- 
GitLab