How to disable prepared statement in heroku with postgres database

后端 未结 6 1254
-上瘾入骨i
-上瘾入骨i 2021-02-20 12:13

I fixed an issue on my rails project locally (with postgres config) while adding in database.yml this statement:

test:
  prepared_statements: false
6条回答
  •  庸人自扰
    2021-02-20 12:32

    We were worried about brittleness and maintaining consistency between staging/production (using DATABASE_URL on Heroku) and development/test (using database.yml/database.example.yml).

    Inspired by Rails' tests, we put this in config/initializers/disable_prepared_statements.rb:

    ActiveRecord::Base.establish_connection(
      ActiveRecord::Base.remove_connection.merge(
        :prepared_statements => false
      )
    )
    

    remove_connection returns a hash of the connection parameters of the connection being removed. This should let any database.yml or DATABASE_URL continue working.

提交回复
热议问题