Skip to content

Commit

Permalink
Add cocina-models
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 28, 2019
1 parent 459183f commit c646ac6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/models/orm/resource.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Orm
# ActiveRecord class which the Postgres adapter uses for persisting data.
# @!attribute id
Expand All @@ -11,7 +13,7 @@ module Orm
# @!attribute internal_resource
# @return [String] Name of {Valkyrie::Resource} model - used for casting.
#
class Resource < ActiveRecord::Base
class Resource < ApplicationRecord
self.table_name = 'orm_resources'
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class AddModelTypeToOrmResources < ActiveRecord::Migration[5.2]
def change
add_column :orm_resources, :resource_type, :string
end
end
3 changes: 2 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ CREATE TABLE public.orm_resources (
id uuid DEFAULT public.gen_random_uuid() NOT NULL,
metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
updated_at timestamp without time zone NOT NULL,
resource_type character varying
);


Expand Down
12 changes: 9 additions & 3 deletions lib/tasks/valkyrie.rake
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# frozen_string_literal: true

namespace :valkyrie do
desc "Import resources to valkyie"
desc 'Import resources to valkyie'
task import: :environment do
Dor::Item.all.each do |item|
puts "Item: #{item.pid}"
model = Cocina::Mapper.build(item)
Orm::Resource.create
item.contentMetadata.resource.each do |resource|
puts resource
fileset = Cocina::Models::FileSet.new
Orm::Resource.create(metadata: fileset.as_json, resource_type: 'FileSet')
end
Orm::Resource.create(metadata: model.as_json, resource_type: item.class)
end
end
end

0 comments on commit c646ac6

Please sign in to comment.