From 8569126c2e52cdde6dba2dd86c9a8e802b0c5e4c Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Wed, 7 Jul 2021 21:13:30 +0200
Subject: [PATCH] Fix upgrade path from 3.4.0 (#16465)

3.4.1 dropped account_stats.lock_version, but in a way breaking the usual
upgrade path by requiring services to be reloaded after the post-migrations.

Indeed, `self.locking_column = nil` was not enough for Rails to ignore the
`lock_version` column when preparing statements on application load, resulting
in some ActiveRecord queries (typically those involving
`includes(:account_stat)`) erroring out with:

  ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column account_stats.lock_version does not exist
---
 app/models/account_stat.rb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/app/models/account_stat.rb b/app/models/account_stat.rb
index 44da4f0d0..e702fa4a4 100644
--- a/app/models/account_stat.rb
+++ b/app/models/account_stat.rb
@@ -15,6 +15,7 @@
 
 class AccountStat < ApplicationRecord
   self.locking_column = nil
+  self.ignored_columns = %w(lock_version)
 
   belongs_to :account, inverse_of: :account_stat