aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-04 14:25:52 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-04 14:25:52 -0300
commit672864e7387d07207fa4b6ce7f9e54cac9d29e45 (patch)
tree7b28a328e6f8378d954794b3b504904d571f123c /activerecord/lib
parentfb5331f274077281854b55131deb69dd4cc9f9aa (diff)
parent405fd22e70e4c2d1117ace0a834cbcc438ea8ca9 (diff)
downloadrails-672864e7387d07207fa4b6ce7f9e54cac9d29e45.tar.gz
rails-672864e7387d07207fa4b6ce7f9e54cac9d29e45.tar.bz2
rails-672864e7387d07207fa4b6ce7f9e54cac9d29e45.zip
Merge pull request #15504 from sgrif/sg-postgres-defaults
Collapse PG default extractoin of most types to single regex
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb54
1 files changed, 6 insertions, 48 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 67570dad3c..0f20d52879 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -511,58 +511,16 @@ module ActiveRecord
# makes this method very very slow.
return default unless default
- # TODO: The default extraction is related to the cast-type.
- # we should probably make a type_map lookup and cast the default-
- # expression accordingly
- if oid.type == :enum && default =~ /\A'(.*)'::/
- return $1
- end
-
case default
- when /\A'(.*)'::(num|date|tstz|ts|int4|int8)range\z/m
- $1
+ # Quoted types
+ when /\A[\(B]?'(.*)'::/m
+ $1.gsub(/''/, "'")
+ # Boolean types
+ when 'true', 'false'
+ default
# Numeric types
when /\A\(?(-?\d+(\.\d*)?\)?(::bigint)?)\z/
$1
- # Character types
- when /\A\(?'(.*)'::.*\b(?:character varying|bpchar|text)\z/m
- $1.gsub(/''/, "'")
- # Binary data types
- when /\A'(.*)'::bytea\z/m
- $1
- # Date/time types
- when /\A'(.+)'::(?:time(?:stamp)? with(?:out)? time zone|date)\z/
- $1
- when /\A'(.*)'::interval\z/
- $1
- # Boolean type
- when 'true'
- true
- when 'false'
- false
- # Geometric types
- when /\A'(.*)'::(?:point|line|lseg|box|"?path"?|polygon|circle)\z/
- $1
- # Network address types
- when /\A'(.*)'::(?:cidr|inet|macaddr)\z/
- $1
- # Bit string types
- when /\AB'(.*)'::"?bit(?: varying)?"?\z/
- $1
- # XML type
- when /\A'(.*)'::xml\z/m
- $1
- # Arrays
- when /\A'(.*)'::"?\D+"?\[\]\z/
- $1
- # Hstore
- when /\A'(.*)'::hstore\z/
- $1
- # JSON
- when /\A'(.*)'::json\z/
- $1
- when /\A'(.*)'::money\z/
- $1
# Object identifier types
when /\A-?\d+\z/
$1