Skip to content

Configuring app to use Valkyrie with Postgres

E. Lynette Rayle edited this page Oct 22, 2020 · 10 revisions

back to Introduction

Goals

  • Configure the application to use the Valkyrie Postgres metadata adapter.
  • Define application-specific reference methods for the Postgres persister and query_service methods.
  • Test these reference methods.

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
)

Set up quick access to persister and query service

Define ValkyriePgDemo.pg_persister and ValkyriePgDemo.pg_query_service to make references to the persister and query services more concise by saving the results of Valkyrie::MetadataAdapter.find(: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 a new rails console (bundle exec 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