diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-22 13:59:18 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-22 13:59:18 -0300 |
commit | b343e310970f2dbbee76691bd4ef78983578e9be (patch) | |
tree | 2913057b0572f51c70630d87e0d40ff0afaea072 /activerecord/lib/active_record/connection_adapters/postgresql/oid | |
parent | 71248fc89efe0d73f8dd41bb834917ab469746dd (diff) | |
parent | 4826a4ab348e59c3ac1f6c31fd73f93eabb91a3b (diff) | |
download | rails-b343e310970f2dbbee76691bd4ef78983578e9be.tar.gz rails-b343e310970f2dbbee76691bd4ef78983578e9be.tar.bz2 rails-b343e310970f2dbbee76691bd4ef78983578e9be.zip |
Merge pull request #15249 from sgrif/sg-register-types-in-adapter
Use the generic type map for all PG type registrations
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb index 27829ae1a3..28f7a4eafb 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb @@ -13,7 +13,8 @@ module ActiveRecord end def run(records) - mapped, nodes = records.partition { |row| OID.registered_type? row['typname'] } + nodes = records.reject { |row| @store.key? row['oid'].to_i } + mapped, nodes = nodes.partition { |row| @store.key? row['typname'] } ranges, nodes = nodes.partition { |row| row['typtype'] == 'r' } enums, nodes = nodes.partition { |row| row['typtype'] == 'e' } domains, nodes = nodes.partition { |row| row['typtype'] == 'd' } @@ -30,7 +31,7 @@ module ActiveRecord private def register_mapped_type(row) - register row['oid'], OID::NAMES[row['typname']] + alias_type row['oid'], row['typname'] end def register_enum_type(row) @@ -64,12 +65,18 @@ module ActiveRecord end def register(oid, oid_type) - oid = oid.to_i + oid = assert_valid_registration(oid, oid_type) + @store.register_type(oid, oid_type) + end - raise ArgumentError, "can't register nil type for OID #{oid}" if oid_type.nil? - return if @store.key?(oid) + def alias_type(oid, target) + oid = assert_valid_registration(oid, target) + @store.alias_type(oid, target) + end - @store.register_type(oid, oid_type) + def assert_valid_registration(oid, oid_type) + raise ArgumentError, "can't register nil type for OID #{oid}" if oid_type.nil? + oid.to_i end end end |