db_preferences_postgresql.rb 963 B

1234567891011121314151617181920212223242526272829
  1. return if ActiveRecord::Base.connection_config[:adapter] != 'postgresql'
  2. Rails.application.config.db_case_sensitive = true
  3. Rails.application.config.db_like = 'ILIKE'
  4. Rails.application.config.db_null_byte = false
  5. # rubocop:disable Rails/Output
  6. # rubocop:disable Rails/Exit
  7. # rubocop:disable Layout/IndentHeredoc
  8. # Version check --------------------------------------------------------------
  9. # example output: "9.5.0"
  10. # "10.3 (Debian 10.3-2)"
  11. server_version = ActiveRecord::Base.connection.execute('SHOW server_version;').first['server_version']
  12. version_number = Gem::Version.new(server_version.split.first)
  13. if version_number < Gem::Version.new('9.1')
  14. printf "\e[31m" # ANSI red
  15. puts <<~MSG
  16. Error: Incompatible database backend version
  17. (PostgreSQL 9.1+ required; #{version_number} found)
  18. MSG
  19. printf "\e[0m" # ANSI normal
  20. exit 1
  21. end
  22. # rubocop:enable Rails/Exit
  23. # rubocop:enable Rails/Output
  24. # rubocop:enable Layout/IndentHeredoc