From 592358e182effecebe8c6a4645bd4431f5a73654 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 27 Apr 2020 02:50:44 +0900 Subject: [PATCH] Update pg gem required version to 1.1 This is required for #39063 to use `PG::TextDecoder::Numeric`. Ref https://github.com/ged/ruby-pg/pull/25. The pg gem 1.1.0 was released at August 24, 2018, so I think it is good timing to bump the required version for improving and cleaning up the code base. https://rubygems.org/gems/pg/versions --- Gemfile | 2 +- Gemfile.lock | 2 +- .../subscription_adapter/postgresql.rb | 2 +- .../connection_adapters/postgresql_adapter.rb | 19 +++---------------- railties/lib/rails/generators/database.rb | 2 +- .../test/generators/app_generator_test.rb | 2 +- .../db_system_change_generator_test.rb | 2 +- 7 files changed, 9 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index 75cbddfd776..0cce0ec71b0 100644 --- a/Gemfile +++ b/Gemfile @@ -127,7 +127,7 @@ platforms :ruby, :mswin, :mswin64, :mingw, :x64_mingw do gem "sqlite3", "~> 1.4" group :db do - gem "pg", ">= 0.18.0" + gem "pg", "~> 1.1" gem "mysql2", "~> 0.5" end end diff --git a/Gemfile.lock b/Gemfile.lock index d673fc8d2dd..a7b82d3a4a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -569,7 +569,7 @@ DEPENDENCIES minitest-retry mysql2 (~> 0.5) nokogiri (>= 1.8.1) - pg (>= 0.18.0) + pg (~> 1.1) psych (~> 3.0) puma que diff --git a/actioncable/lib/action_cable/subscription_adapter/postgresql.rb b/actioncable/lib/action_cable/subscription_adapter/postgresql.rb index 84022e2bdcd..3b114d4e545 100644 --- a/actioncable/lib/action_cable/subscription_adapter/postgresql.rb +++ b/actioncable/lib/action_cable/subscription_adapter/postgresql.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -gem "pg", ">= 0.18", "< 2.0" +gem "pg", "~> 1.1" require "pg" require "thread" require "digest/sha1" diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index d13376366ae..42e0ee86c03 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1,17 +1,8 @@ # frozen_string_literal: true -# Make sure we're using pg high enough for type casts and Ruby 2.2+ compatibility -gem "pg", ">= 0.18", "< 2.0" +gem "pg", "~> 1.1" require "pg" -# Use async_exec instead of exec_params on pg versions before 1.1 -class ::PG::Connection # :nodoc: - unless self.public_method_defined?(:async_exec_params) - remove_method :exec_params - alias exec_params async_exec - end -end - require "active_support/core_ext/object/try" require "active_record/connection_adapters/abstract_adapter" require "active_record/connection_adapters/statement_pool" @@ -905,14 +896,10 @@ module ActiveRecord "float4" => PG::TextDecoder::Float, "float8" => PG::TextDecoder::Float, "bool" => PG::TextDecoder::Boolean, + "timestamp" => PG::TextDecoder::TimestampUtc, + "timestamptz" => PG::TextDecoder::TimestampWithTimeZone, } - if defined?(PG::TextDecoder::TimestampUtc) - # Use native PG encoders available since pg-1.1 - coders_by_name["timestamp"] = PG::TextDecoder::TimestampUtc - coders_by_name["timestamptz"] = PG::TextDecoder::TimestampWithTimeZone - end - known_coder_types = coders_by_name.keys.map { |n| quote(n) } query = <<~SQL % known_coder_types.join(", ") SELECT t.oid, t.typname diff --git a/railties/lib/rails/generators/database.rb b/railties/lib/rails/generators/database.rb index 6aa6404323b..d0fcfd2abab 100644 --- a/railties/lib/rails/generators/database.rb +++ b/railties/lib/rails/generators/database.rb @@ -14,7 +14,7 @@ module Rails def gem_for_database(database = options[:database]) case database when "mysql" then ["mysql2", ["~> 0.5"]] - when "postgresql" then ["pg", [">= 0.18", "< 2.0"]] + when "postgresql" then ["pg", ["~> 1.1"]] when "sqlite3" then ["sqlite3", ["~> 1.4"]] when "oracle" then ["activerecord-oracle_enhanced-adapter", nil] when "sqlserver" then ["activerecord-sqlserver-adapter", nil] diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 636eb697beb..3277b70406b 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -547,7 +547,7 @@ class AppGeneratorTest < Rails::Generators::TestCase if defined?(JRUBY_VERSION) assert_gem "activerecord-jdbcpostgresql-adapter" else - assert_gem "pg", "'>= 0.18', '< 2.0'" + assert_gem "pg", "'~> 1.1'" end end diff --git a/railties/test/generators/db_system_change_generator_test.rb b/railties/test/generators/db_system_change_generator_test.rb index 7597fe935af..943a6e874a6 100644 --- a/railties/test/generators/db_system_change_generator_test.rb +++ b/railties/test/generators/db_system_change_generator_test.rb @@ -40,7 +40,7 @@ module Rails assert_file("Gemfile") do |content| assert_match "# Use pg as the database for Active Record", content - assert_match "gem 'pg', '>= 0.18', '< 2.0'", content + assert_match "gem 'pg', '~> 1.1'", content end end