diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-04-01 19:42:22 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-04-01 19:52:34 +0200 |
commit | f7a6b115fea9f675190a79b701c7034214678f19 (patch) | |
tree | e185ba5ab64b915a6d5c630fe35fd40e681ffe24 /activerecord/lib | |
parent | fc0b98da0b83329474922a920a6070d370091228 (diff) | |
download | rails-f7a6b115fea9f675190a79b701c7034214678f19.tar.gz rails-f7a6b115fea9f675190a79b701c7034214678f19.tar.bz2 rails-f7a6b115fea9f675190a79b701c7034214678f19.zip |
PostgreSQL, register custom domains. Closes #14305.
This patch registers custom domains in our OID-type_map.
They will behave exactly as the type specified by `pg_type.typbasetype`.
/cc @matthewd
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index c31fe96842..e8719d5269 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -582,7 +582,7 @@ module ActiveRecord def initialize_type_map(type_map) if supports_ranges? result = execute(<<-SQL, 'SCHEMA') - SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype + SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype FROM pg_type as t LEFT JOIN pg_range as r ON oid = rngtypid SQL @@ -593,6 +593,7 @@ module ActiveRecord SQL end ranges, nodes = result.partition { |row| row['typinput'] == 'range_in' } + domains, nodes = nodes.partition { |row| row['typtype'] == 'd' } leaves, nodes = nodes.partition { |row| row['typelem'] == '0' } arrays, nodes = nodes.partition { |row| row['typinput'] == 'array_in' } @@ -626,6 +627,15 @@ module ActiveRecord range = OID::Range.new subtype type_map[row['oid'].to_i] = range end + + # populate domain types + domains.each do |row| + if base_type = type_map[row["typbasetype"].to_i] + type_map[row['oid'].to_i] = base_type + else + warn "unknown base type (OID: #{row["typbasetype"].to_i}) for domain #{row["typname"]}." + end + end end FEATURE_NOT_SUPPORTED = "0A000" #:nodoc: |