pg_schema_caching.rb

lib/sequel/extensions/pg_schema_caching.rb
Last Update: 2024-11-14 15:28:58 -0800

The pg_schema_caching extension builds on top of the schema_caching extension, and allows it to handle custom PostgreSQL types. On PostgreSQL, column schema hashes include an :oid entry for the OID for the column’s type. For custom types, this OID is dependent on the PostgreSQL database, so in most cases, test and development versions of the same database, created with the same migrations, will have different OIDs.

To fix this case, the pg_schema_caching extension removes custom OIDs from the schema cache when dumping the schema, replacing them with a placeholder. When loading the cached schema, the Database object makes a single query to get the OIDs for all custom types used by the cached schema, and it updates all related column schema hashes to set the correct :oid entry for the current database.

Related module: Sequel::Postgres::SchemaCaching