Skip to content

Configuring app to use Valkyrie with Postgres

E. Lynette Rayle edited this page Dec 18, 2019 · 10 revisions

Terminology

  • metadata adapter
    • provides access to persister and query service for a datasource (e.g. postgres, solr, etc.) See definitions for persister and query service under [Saving a resource] and [Retrieving resources], respectively.

Set up app to use Postgres adapter

Create/Edit config/initializers/valkyrie.rb and add...

Valkyrie::MetadataAdapter.register(
  Valkyrie::Persistence::Postgres::MetadataAdapter.new,
  :postgres
)

NOTE: If you are also using the solr adapter, you can add a registration for it here as well.

Set up quick access to persister and query service

This is optional, but can be a useful shortcut. If you do not create these, you would use Valkyrie::MetadataAdapter.find(:postgres) everywhere you want to use the persister or query service for postgres.

Create/Edit config/initializers/valkyrie_pg_demo.rb and add...

module ValkyriePgDemo
  def self.pg_persister
    Valkyrie::MetadataAdapter.find(:postgres).persister
  end

  def self.pg_query_service
    Valkyrie::MetadataAdapter.find(:postgres).query_service
  end
end

NOTE: These are prefixed with pg_ to establish a pattern for adding methods for another adapter with a different prefix (e.g. solr_).

SPOTCHECK

Run the following in rails console to test setup of Valkyrie metadata adapter and quick access methods...

>> ValkyriePgDemo.pg_persister
=> #<Valkyrie::Persistence::Postgres::Persister:0x00007f8a100cbe98 @adapter=#<Valkyrie::Persistence::Postgres::MetadataAdapter:0x00007f8a46319a70>>
>>
>> ValkyriePgDemo.pg_query_service
=> #<Valkyrie::Persistence::Postgres::QueryService:0x00007f8a100c90a8 @resource_factory=#<Valkyrie::Persistence::Postgres::ResourceFactory:0x00007f8a100c9120 @adapter=#<Valkyrie::Persistence::Postgres::MetadataAdapter:0x00007f8a46319a70 @resource_factory=#<Valkyrie::Persistence::Postgres::ResourceFactory:0x00007f8a100c9120 ...>, @query_service=#<Valkyrie::Persistence::Postgres::QueryService:0x00007f8a100c90a8 ...>>>, @adapter=#<Valkyrie::Persistence::Postgres::MetadataAdapter:0x00007f8a46319a70 @resource_factory=#<Valkyrie::Persistence::Postgres::ResourceFactory:0x00007f8a100c9120 @adapter=#<Valkyrie::Persistence::Postgres::MetadataAdapter:0x00007f8a46319a70 ...>>, @query_service=#<Valkyrie::Persistence::Postgres::QueryService:0x00007f8a100c90a8 ...>>>

Previous | Next