aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-22 09:39:16 -0700
committerSean Griffin <sean@thoughtbot.com>2014-05-22 09:43:30 -0700
commit4826a4ab348e59c3ac1f6c31fd73f93eabb91a3b (patch)
tree053d88e831c9b6c95fecc29a32bd5f21c7b3b488 /activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb
parent110d3d0c0bceddd05cab86c0463f0aa71df815cb (diff)
downloadrails-4826a4ab348e59c3ac1f6c31fd73f93eabb91a3b.tar.gz
rails-4826a4ab348e59c3ac1f6c31fd73f93eabb91a3b.tar.bz2
rails-4826a4ab348e59c3ac1f6c31fd73f93eabb91a3b.zip
Use the generic type map for all PG type registrations
We're going to want all of the benefits of the type map object for registrations, including block registration and real aliasing. Moves type name registrations to the adapter, and aliases the OIDs to the named types
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb19
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