module Sequel::Postgres::SchemaCaching
Private Instance Methods
Source
# File lib/sequel/extensions/pg_schema_caching.rb 72 def dumpable_schema_cache 73 sch = super 74 75 sch.each_value do |cols| 76 cols.each do |_, h| 77 if (oid = h[:oid]) && oid >= 10000 78 h[:oid] = :custom 79 end 80 end 81 end 82 83 sch 84 end
Replace :oid entries for custom types with :custom.
Calls superclass method
Sequel::SchemaCaching#dumpable_schema_cache
Source
# File lib/sequel/extensions/pg_schema_caching.rb 31 def load_schema_cache_file(file) 32 set_custom_oids_for_cached_schema(super) 33 end
Load custom oids from database when loading schema cache file.
Calls superclass method
Sequel::SchemaCaching#load_schema_cache_file
Source
# File lib/sequel/extensions/pg_schema_caching.rb 38 def set_custom_oids_for_cached_schema(schemas) 39 custom_oid_rows = {} 40 41 schemas.each_value do |cols| 42 cols.each do |_, h| 43 if h[:oid] == :custom 44 (custom_oid_rows[h[:db_type]] ||= []) << h 45 end 46 end 47 end 48 49 unless custom_oid_rows.empty? 50 from(:pg_type).where(:typname=>custom_oid_rows.keys).select_hash(:typname, :oid).each do |name, oid| 51 custom_oid_rows.delete(name).each do |row| 52 row[:oid] = oid 53 end 54 end 55 end 56 57 unless custom_oid_rows.empty? 58 warn "Could not load OIDs for the following custom types: #{custom_oid_rows.keys.sort.join(", ")}", uplevel: 3 59 60 schemas.keys.each do |k| 61 if schemas[k].any?{|_,h| h[:oid] == :custom} 62 # Remove schema entry for table, so it will be queried at runtime to get the correct oids 63 schemas.delete(k) 64 end 65 end 66 end 67 68 schemas 69 end
Find all column schema hashes that use custom types. Load the oids for custom types in a single query, and update each related column schema hash with the correct oid.