Guard ActionRecord::Base.exec_sql against a readonly PostgreSQL cluster.

This commit is contained in:
Guo Xiang Tan 2017-10-19 14:47:29 +08:00
parent 814c7ab503
commit c2a5e603c2

View File

@ -5,6 +5,8 @@ class ActiveRecord::Base
conn = ActiveRecord::Base.connection conn = ActiveRecord::Base.connection
sql = ActiveRecord::Base.send(:sanitize_sql_array, args) sql = ActiveRecord::Base.send(:sanitize_sql_array, args)
conn.raw_connection.exec(sql) conn.raw_connection.exec(sql)
rescue PG::ReadOnlySqlTransaction
Rails.logger.warn("WARN: PostgreSQL is in a readonly state. Performed a noop")
end end
def self.exec_sql_row_count(*args) def self.exec_sql_row_count(*args)