From fd22ccc787957d9a30942281f0a2c1e05b474646 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Mon, 12 Dec 2016 16:56:42 +0100 Subject: Update to rails 4.2.7 refs #2070 --- config/initializers/postgresql_adapter_patch.rb | 68 ++++++++++++------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'config/initializers/postgresql_adapter_patch.rb') diff --git a/config/initializers/postgresql_adapter_patch.rb b/config/initializers/postgresql_adapter_patch.rb index 2e4d73f85..3c6530bef 100644 --- a/config/initializers/postgresql_adapter_patch.rb +++ b/config/initializers/postgresql_adapter_patch.rb @@ -14,41 +14,41 @@ # Add missing double-quote to write array of daterange in SQL query # See #1782 -class ActiveRecord::ConnectionAdapters::PostgreSQLColumn +# class ActiveRecord::ConnectionAdapters::PostgreSQLColumn - def self.array_to_string(value, column, adapter) - casted_values = value.map do |val| - if String === val - if val == "NULL" - "\"#{val}\"" - else - quote_and_escape(adapter.type_cast(val, column, true)) - end - elsif Range === val - casted_value = adapter.type_cast(val, column, true) - "\"#{casted_value}\"" - else - adapter.type_cast(val, column, true) - end - end - "{#{casted_values.join(',')}}" - end +# def self.array_to_string(value, column, adapter) +# casted_values = value.map do |val| +# if String === val +# if val == "NULL" +# "\"#{val}\"" +# else +# quote_and_escape(adapter.type_cast(val, column, true)) +# end +# elsif Range === val +# casted_value = adapter.type_cast(val, column, true) +# "\"#{casted_value}\"" +# else +# adapter.type_cast(val, column, true) +# end +# end +# "{#{casted_values.join(',')}}" +# end -end +# end -module ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID - class DateRange < Range - # Unnormalize daterange - # [2016-11-19,2016-12-26) -> 2016-11-19..2016-12-25 - def type_cast(value) - result = super value +# module ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID +# class DateRange < Range +# # Unnormalize daterange +# # [2016-11-19,2016-12-26) -> 2016-11-19..2016-12-25 +# def type_cast(value) +# result = super value - if result.respond_to?(:exclude_end?) && result.exclude_end? - ::Range.new(result.begin, result.end - 1, false) - else - result - end - end - end - register_type 'daterange', DateRange.new(:date) -end +# if result.respond_to?(:exclude_end?) && result.exclude_end? +# ::Range.new(result.begin, result.end - 1, false) +# else +# result +# end +# end +# end +# register_type 'daterange', DateRange.new(:date) +# end -- cgit v1.2.3 From 2e90dd524049c7bd982bbcddf6e62c2c36635aa3 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Mon, 20 Feb 2017 11:12:45 +0100 Subject: Update DateRange custom OID to Rails 4.2 API. Refs #2070 --- config/initializers/postgresql_adapter_patch.rb | 71 +++++++------------------ 1 file changed, 20 insertions(+), 51 deletions(-) (limited to 'config/initializers/postgresql_adapter_patch.rb') diff --git a/config/initializers/postgresql_adapter_patch.rb b/config/initializers/postgresql_adapter_patch.rb index 3c6530bef..bb8dbe17b 100644 --- a/config/initializers/postgresql_adapter_patch.rb +++ b/config/initializers/postgresql_adapter_patch.rb @@ -1,54 +1,23 @@ -# module ::ArJdbc -# module PostgreSQL -# def quote_column_name(name) -# if name.is_a?(Array) -# name.collect { |n| %("#{n.to_s.gsub("\"", "\"\"")}") }.join(',') -# else -# %("#{name.to_s.gsub("\"", "\"\"")}") -# end -# end -# end -# end -# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:primary_key] = "bigserial primary key" +# Transform Wed, 22 Feb 2017...Fri, 24 Feb 201 into Wed, 22 Feb 2017..Thu, 23 Feb 201 +module ActiveRecord::ConnectionAdapters::PostgreSQL::OID + class DateRange < Range + def cast_value(value) + result = super value -# Add missing double-quote to write array of daterange in SQL query -# See #1782 + if result.respond_to?(:exclude_end?) && result.exclude_end? + ::Range.new(result.begin, result.end - 1, false) + else + result + end + end + end +end -# class ActiveRecord::ConnectionAdapters::PostgreSQLColumn +ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do + def initialize_type_map_with_daterange mapping + initialize_type_map_without_daterange mapping + mapping.register_type 3912, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateRange.new(mapping.lookup('date'), :daterange) + end -# def self.array_to_string(value, column, adapter) -# casted_values = value.map do |val| -# if String === val -# if val == "NULL" -# "\"#{val}\"" -# else -# quote_and_escape(adapter.type_cast(val, column, true)) -# end -# elsif Range === val -# casted_value = adapter.type_cast(val, column, true) -# "\"#{casted_value}\"" -# else -# adapter.type_cast(val, column, true) -# end -# end -# "{#{casted_values.join(',')}}" -# end - -# end - -# module ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID -# class DateRange < Range -# # Unnormalize daterange -# # [2016-11-19,2016-12-26) -> 2016-11-19..2016-12-25 -# def type_cast(value) -# result = super value - -# if result.respond_to?(:exclude_end?) && result.exclude_end? -# ::Range.new(result.begin, result.end - 1, false) -# else -# result -# end -# end -# end -# register_type 'daterange', DateRange.new(:date) -# end + alias_method_chain :initialize_type_map, :daterange +end -- cgit v1.2.3 From f590d7b18c7e980ce7e93e96ae3b45fce310675f Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 20 Apr 2017 08:19:12 +0200 Subject: custom attribute daterange for referential_metadata --- config/initializers/postgresql_adapter_patch.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'config/initializers/postgresql_adapter_patch.rb') diff --git a/config/initializers/postgresql_adapter_patch.rb b/config/initializers/postgresql_adapter_patch.rb index bb8dbe17b..46066fbbf 100644 --- a/config/initializers/postgresql_adapter_patch.rb +++ b/config/initializers/postgresql_adapter_patch.rb @@ -16,7 +16,8 @@ end ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do def initialize_type_map_with_daterange mapping initialize_type_map_without_daterange mapping - mapping.register_type 3912, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateRange.new(mapping.lookup('date'), :daterange) + # mapping.register_type 3912, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateRange.new(mapping.lookup('date'), :daterange) + mapping.register_type 'daterange', ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateRange.new(mapping.lookup('date'), :daterange) end alias_method_chain :initialize_type_map, :daterange -- cgit v1.2.3 From dc4e32c712606787c119587c7b7127841a79ab85 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 21 Apr 2017 11:00:02 +0200 Subject: pushed postrges range semantics -> Ruby range semantics transformation - [) -> [] - into the model --- config/initializers/postgresql_adapter_patch.rb | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 config/initializers/postgresql_adapter_patch.rb (limited to 'config/initializers/postgresql_adapter_patch.rb') diff --git a/config/initializers/postgresql_adapter_patch.rb b/config/initializers/postgresql_adapter_patch.rb deleted file mode 100644 index 46066fbbf..000000000 --- a/config/initializers/postgresql_adapter_patch.rb +++ /dev/null @@ -1,24 +0,0 @@ -# Transform Wed, 22 Feb 2017...Fri, 24 Feb 201 into Wed, 22 Feb 2017..Thu, 23 Feb 201 -module ActiveRecord::ConnectionAdapters::PostgreSQL::OID - class DateRange < Range - def cast_value(value) - result = super value - - if result.respond_to?(:exclude_end?) && result.exclude_end? - ::Range.new(result.begin, result.end - 1, false) - else - result - end - end - end -end - -ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do - def initialize_type_map_with_daterange mapping - initialize_type_map_without_daterange mapping - # mapping.register_type 3912, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateRange.new(mapping.lookup('date'), :daterange) - mapping.register_type 'daterange', ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateRange.new(mapping.lookup('date'), :daterange) - end - - alias_method_chain :initialize_type_map, :daterange -end -- cgit v1.2.3