FIX: Do not dump schema during production database migrations (#12785)

FIX: Do not dump schema during production database migrations (#12785)

It’s important that we don’t perform pg_dumps against databases running behind pgbouncer.

We had an old monkey-patch to prevent this, but following some recent internal rails refactoring, the patch no longer works. Instead, we can use the official config.active_record.dump_schema_after_migration option.

Setting this to false in production is recommended by Rails, and is the default for newly generated Rails applications.

diff --git a/Rakefile b/Rakefile
index dc7fdf2..d0e674f 100755
--- a/Rakefile
+++ b/Rakefile
@@ -7,7 +7,3 @@
 require File.expand_path('../config/application', __FILE__)
-# this prevents crashes when migrating a database in production in certain
-# PostgreSQL configuations when trying to create structure.sql
-Rake::Task["db:structure:dump"].clear if Rails.env.production?
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 2f0b0d5..a523888 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -67,4 +67,5 @@ Discourse::Application.configure do
     config.developer_emails = emails.split(",").map(&:downcase).map(&:strip)
+  config.active_record.dump_schema_after_migration = false

GitHub sha: 65164bf1

This commit appears in #12785 which was approved by ZogStriP. It was merged by davidtaylorhq.