valkyrie-sequel 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -2
- data/.rubocop.yml +2 -1
- data/lib/valkyrie/sequel/metadata_adapter.rb +9 -9
- data/lib/valkyrie/sequel/persister.rb +23 -23
- data/lib/valkyrie/sequel/query_service.rb +111 -97
- data/lib/valkyrie/sequel/resource_factory/orm_converter.rb +42 -42
- data/lib/valkyrie/sequel/resource_factory/resource_converter.rb +36 -37
- data/lib/valkyrie/sequel/version.rb +1 -1
- data/valkyrie-sequel.gemspec +4 -5
- metadata +22 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd54c1445fecd7ace70e07607d27da780bf9c47d6ac97c8681ab319908e1c36b
|
4
|
+
data.tar.gz: bce2c0e04e1c6aae88d0dfae9bcbb35fc0a4055c2223284526165fb71a34adde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7b5a2524a6c10a7b49757ceb360560f2aac259c7376ff0abe51c456eaa8750b4dfdc9185dd692b1041a04bfaa649a047b240427ac4bc5be802fd7de4ebbff05
|
7
|
+
data.tar.gz: 789f2e2931f1c8ea9552124e1119a9582e2c703261782b1f4d242191391f01f5725994c70bb8d4653f5525b60bd8d0d7221177116eacde9862b05aa2e6ecc4a3
|
data/.circleci/config.yml
CHANGED
@@ -3,9 +3,10 @@ version: 2
|
|
3
3
|
jobs:
|
4
4
|
build:
|
5
5
|
docker:
|
6
|
-
- image: circleci/ruby:2.
|
6
|
+
- image: circleci/ruby:2.7.2-node-browsers
|
7
7
|
environment:
|
8
8
|
RAILS_ENV: test
|
9
|
+
BUNDLE_PATH: vendor/bundle
|
9
10
|
DB_HOST: localhost
|
10
11
|
DB_USERNAME: valkyrie_sequel
|
11
12
|
DB_PASSWORD: ""
|
@@ -23,7 +24,7 @@ jobs:
|
|
23
24
|
key: valkyrie-sequel-{{ checksum "Gemfile" }}
|
24
25
|
- run: gem install bundler -v '~> 2.0'
|
25
26
|
# Bundle install dependencies
|
26
|
-
- run: bundle install
|
27
|
+
- run: bundle install
|
27
28
|
# Cache Dependencies
|
28
29
|
- type: cache-save
|
29
30
|
name: Store bundle cache
|
data/.rubocop.yml
CHANGED
@@ -2,7 +2,6 @@ inherit_gem:
|
|
2
2
|
bixby: bixby_default.yml
|
3
3
|
AllCops:
|
4
4
|
DisplayCopNames: true
|
5
|
-
TargetRubyVersion: 2.3
|
6
5
|
Exclude:
|
7
6
|
- 'bin/*'
|
8
7
|
- 'db/schema.rb'
|
@@ -24,3 +23,5 @@ Metrics/ParameterLists:
|
|
24
23
|
RSpec/ExampleLength:
|
25
24
|
Exclude:
|
26
25
|
- 'spec/valkyrie/sequel/persister_spec.rb'
|
26
|
+
Rails/RakeEnvironment:
|
27
|
+
Enabled: false
|
@@ -48,16 +48,16 @@ module Valkyrie::Sequel
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
def host
|
52
|
+
connection.opts[:host]
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
def port
|
56
|
+
connection.opts[:port]
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
def database
|
60
|
+
connection.opts[:database]
|
61
|
+
end
|
62
62
|
end
|
63
63
|
end
|
@@ -121,32 +121,32 @@ module Valkyrie::Sequel
|
|
121
121
|
|
122
122
|
private
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
124
|
+
def create_or_update(resource:, attributes:)
|
125
|
+
attributes[:updated_at] = Time.now.utc
|
126
|
+
attributes[:created_at] ||= Time.now.utc
|
127
|
+
return create(resource: resource, attributes: attributes) unless resource.persisted? && !exists?(id: attributes[:id])
|
128
|
+
update(resource: resource, attributes: attributes)
|
129
|
+
end
|
130
130
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
131
|
+
def create(resource:, attributes:)
|
132
|
+
attributes[:lock_version] = 0 if resource.optimistic_locking_enabled? && resources.columns.include?(:lock_version)
|
133
|
+
Array(resources.returning.insert(attributes)).first
|
134
|
+
end
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
142
|
-
attributes.delete(:lock_version) if attributes[:lock_version].nil?
|
143
|
-
output = relation.returning.update(attributes)
|
144
|
-
raise Valkyrie::Persistence::StaleObjectError, "The object #{resource.id} has been updated by another process." if output.blank? && resource.optimistic_locking_enabled?
|
145
|
-
Array(output).first
|
136
|
+
def update(resource:, attributes:)
|
137
|
+
relation = resources.where(id: attributes[:id])
|
138
|
+
if resource.optimistic_locking_enabled?
|
139
|
+
relation = relation.where(Sequel.function(:coalesce, :lock_version, 0) => attributes[:lock_version] || 0)
|
140
|
+
attributes[:lock_version] = (Sequel.function(:coalesce, :lock_version, 0) + 1)
|
146
141
|
end
|
142
|
+
attributes.delete(:lock_version) if attributes[:lock_version].nil?
|
143
|
+
output = relation.returning.update(attributes)
|
144
|
+
raise Valkyrie::Persistence::StaleObjectError, "The object #{resource.id} has been updated by another process." if output.blank? && resource.optimistic_locking_enabled?
|
145
|
+
Array(output).first
|
146
|
+
end
|
147
147
|
|
148
|
-
|
149
|
-
|
150
|
-
|
148
|
+
def exists?(id:)
|
149
|
+
resources.select(1).first(id: id).nil?
|
150
|
+
end
|
151
151
|
end
|
152
152
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Valkyrie::Sequel
|
3
3
|
class QueryService
|
4
|
+
# ACCEPTABLE_UUID is deprecated and unused.
|
5
|
+
# which IDs are acceptable is now decided by the database.
|
4
6
|
ACCEPTABLE_UUID = %r{\A(\{)?([a-fA-F0-9]{4}-?){8}(?(1)\}|)\z}.freeze
|
7
|
+
DEFAULT_ID_TYPE = :uuid
|
8
|
+
|
5
9
|
attr_reader :adapter
|
6
10
|
delegate :resources, :resource_factory, :connection, to: :adapter
|
7
11
|
def initialize(adapter:)
|
@@ -14,14 +18,27 @@ module Valkyrie::Sequel
|
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
21
|
+
# rubocop:disable Metrics/MethodLength
|
17
22
|
def find_by(id:)
|
18
23
|
id = Valkyrie::ID.new(id.to_s) if id.is_a?(String)
|
19
24
|
validate_id(id)
|
20
|
-
|
21
|
-
|
25
|
+
attributes = nil
|
26
|
+
# Create a nested transaction so it can rollback to a non-essential
|
27
|
+
# savepoint if the query fails, not wrecking upstream transactions.
|
28
|
+
connection.transaction(savepoint: true) do
|
29
|
+
attributes = resources.first(id: id.to_s)
|
30
|
+
end
|
22
31
|
raise Valkyrie::Persistence::ObjectNotFoundError unless attributes
|
23
32
|
resource_factory.to_resource(object: attributes)
|
33
|
+
rescue Sequel::DatabaseError => err
|
34
|
+
case err.cause
|
35
|
+
when PG::InvalidTextRepresentation
|
36
|
+
raise Valkyrie::Persistence::ObjectNotFoundError
|
37
|
+
else
|
38
|
+
raise err
|
39
|
+
end
|
24
40
|
end
|
41
|
+
# rubocop:enable Metrics/MethodLength
|
25
42
|
|
26
43
|
def find_all_of_model(model:)
|
27
44
|
resources.where(internal_resource: model.to_s).map do |attributes|
|
@@ -42,11 +59,8 @@ module Valkyrie::Sequel
|
|
42
59
|
validate_id(id)
|
43
60
|
id.to_s
|
44
61
|
end
|
45
|
-
ids = ids.select do |id|
|
46
|
-
ACCEPTABLE_UUID.match?(id)
|
47
|
-
end
|
48
62
|
|
49
|
-
resources.where(id
|
63
|
+
resources.where(Sequel.lit('(id::varchar) IN ?', ids)).map do |attributes|
|
50
64
|
resource_factory.to_resource(object: attributes)
|
51
65
|
end
|
52
66
|
end
|
@@ -111,149 +125,149 @@ module Valkyrie::Sequel
|
|
111
125
|
|
112
126
|
private
|
113
127
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
128
|
+
# Generate the SQL query for retrieving member resources in PostgreSQL using a
|
129
|
+
# resource ID as an argument.
|
130
|
+
# @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
|
131
|
+
# @note this uses a CROSS JOIN for all combinations of member IDs with the
|
132
|
+
# IDs of their parents
|
133
|
+
# @see https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM
|
134
|
+
# This also uses JSON functions in order to retrieve JSON property values
|
135
|
+
# @see https://www.postgresql.org/docs/current/static/functions-json.html
|
136
|
+
# @return [String]
|
137
|
+
def find_members_query
|
138
|
+
<<-SQL
|
125
139
|
SELECT member.* FROM orm_resources a,
|
126
140
|
jsonb_array_elements(a.metadata->'member_ids') WITH ORDINALITY AS b(member, member_pos)
|
127
141
|
JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
|
128
142
|
ORDER BY b.member_pos
|
129
143
|
SQL
|
130
|
-
|
144
|
+
end
|
131
145
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
146
|
+
# Generate the SQL query for retrieving member resources in PostgreSQL using a
|
147
|
+
# resource ID and resource type as arguments.
|
148
|
+
# @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
|
149
|
+
# @note this uses a CROSS JOIN for all combinations of member IDs with the
|
150
|
+
# IDs of their parents
|
151
|
+
# @see https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM
|
152
|
+
# This also uses JSON functions in order to retrieve JSON property values
|
153
|
+
# @see https://www.postgresql.org/docs/current/static/functions-json.html
|
154
|
+
# @return [String]
|
155
|
+
def find_members_with_type_query
|
156
|
+
<<-SQL
|
143
157
|
SELECT member.* FROM orm_resources a,
|
144
158
|
jsonb_array_elements(a.metadata->'member_ids') WITH ORDINALITY AS b(member, member_pos)
|
145
159
|
JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
|
146
160
|
AND member.internal_resource = ?
|
147
161
|
ORDER BY b.member_pos
|
148
162
|
SQL
|
149
|
-
|
163
|
+
end
|
150
164
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
165
|
+
# Generate the SQL query for retrieving member resources in PostgreSQL using a
|
166
|
+
# JSON object literal as an argument (e. g. { "alternate_ids": [{"id": "d6e88f80-41b3-4dbf-a2a0-cd79e20f6d10"}] }).
|
167
|
+
# @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
|
168
|
+
# This uses JSON functions in order to retrieve JSON property values
|
169
|
+
# @see https://www.postgresql.org/docs/current/static/functions-json.html
|
170
|
+
# @return [String]
|
171
|
+
def find_inverse_references_query
|
172
|
+
<<-SQL
|
159
173
|
SELECT * FROM orm_resources WHERE
|
160
174
|
metadata @> ?
|
161
175
|
SQL
|
162
|
-
|
176
|
+
end
|
163
177
|
|
164
|
-
|
165
|
-
|
178
|
+
def find_inverse_references_with_model_query
|
179
|
+
<<-SQL
|
166
180
|
SELECT * FROM orm_resources WHERE
|
167
181
|
metadata @> ?
|
168
182
|
AND internal_resource = ?
|
169
183
|
SQL
|
170
|
-
|
184
|
+
end
|
171
185
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
186
|
+
# Generate the SQL query for retrieving member resources in PostgreSQL using a
|
187
|
+
# JSON object literal and resource ID as arguments.
|
188
|
+
# @see https://guides.rubyonrails.org/active_record_querying.html#array-conditions
|
189
|
+
# @note this uses a CROSS JOIN for all combinations of member IDs with the
|
190
|
+
# IDs of their parents
|
191
|
+
# @see https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM
|
192
|
+
# This also uses JSON functions in order to retrieve JSON property values
|
193
|
+
# @see https://www.postgresql.org/docs/current/static/functions-json.html
|
194
|
+
# @return [String]
|
195
|
+
def find_references_query
|
196
|
+
<<-SQL
|
183
197
|
SELECT DISTINCT member.* FROM orm_resources a,
|
184
198
|
jsonb_array_elements(a.metadata->?) AS b(member)
|
185
199
|
JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
|
186
200
|
SQL
|
187
|
-
|
201
|
+
end
|
188
202
|
|
189
|
-
|
190
|
-
|
203
|
+
def find_references_with_type_query
|
204
|
+
<<-SQL
|
191
205
|
SELECT DISTINCT member.* FROM orm_resources a,
|
192
206
|
jsonb_array_elements(a.metadata->?) AS b(member)
|
193
207
|
JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
|
194
208
|
AND member.internal_resource = ?
|
195
209
|
SQL
|
196
|
-
|
210
|
+
end
|
197
211
|
|
198
|
-
|
199
|
-
|
212
|
+
def find_ordered_references_query
|
213
|
+
<<-SQL
|
200
214
|
SELECT member.* FROM orm_resources a,
|
201
215
|
jsonb_array_elements(a.metadata->?) WITH ORDINALITY AS b(member, member_pos)
|
202
216
|
JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
|
203
217
|
ORDER BY b.member_pos
|
204
218
|
SQL
|
205
|
-
|
219
|
+
end
|
206
220
|
|
207
|
-
|
208
|
-
|
221
|
+
def find_ordered_references_with_type_query
|
222
|
+
<<-SQL
|
209
223
|
SELECT member.* FROM orm_resources a,
|
210
224
|
jsonb_array_elements(a.metadata->?) WITH ORDINALITY AS b(member, member_pos)
|
211
225
|
JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = ?
|
212
226
|
AND member.internal_resource = ?
|
213
227
|
ORDER BY b.member_pos
|
214
228
|
SQL
|
215
|
-
|
229
|
+
end
|
216
230
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
231
|
+
# Accesses the data type in PostgreSQL used for the primary key
|
232
|
+
# (For example, a UUID)
|
233
|
+
# @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaCache.html#method-i-columns_hash
|
234
|
+
# @return [Symbol]
|
235
|
+
def id_type
|
236
|
+
@id_type ||= DEFAULT_ID_TYPE
|
237
|
+
end
|
224
238
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
239
|
+
# Determines whether or not an Object is a Valkyrie ID
|
240
|
+
# @param [Object] id
|
241
|
+
# @raise [ArgumentError]
|
242
|
+
def validate_id(id)
|
243
|
+
raise ArgumentError, 'id must be a Valkyrie::ID' unless id.is_a? Valkyrie::ID
|
244
|
+
end
|
231
245
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
246
|
+
# Determines whether or not a resource has been persisted
|
247
|
+
# @param [Object] resource
|
248
|
+
# @raise [ArgumentError]
|
249
|
+
def ensure_persisted(resource)
|
250
|
+
raise ArgumentError, 'resource is not saved' unless resource.persisted?
|
251
|
+
end
|
238
252
|
|
239
|
-
|
240
|
-
|
241
|
-
|
253
|
+
def ordered_property?(resource:, property:)
|
254
|
+
resource.ordered_attribute?(property)
|
255
|
+
end
|
242
256
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
end
|
257
|
+
def find_ordered_references_by(resource:, property:, model: nil)
|
258
|
+
if model
|
259
|
+
run_query(find_ordered_references_with_type_query, property.to_s, resource.id.to_s, model.to_s)
|
260
|
+
else
|
261
|
+
run_query(find_ordered_references_query, property.to_s, resource.id.to_s)
|
249
262
|
end
|
263
|
+
end
|
250
264
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
end
|
265
|
+
def find_unordered_references_by(resource:, property:, model: nil)
|
266
|
+
if model
|
267
|
+
run_query(find_references_with_type_query, property.to_s, resource.id.to_s, model.to_s)
|
268
|
+
else
|
269
|
+
run_query(find_references_query, property.to_s, resource.id.to_s)
|
257
270
|
end
|
271
|
+
end
|
258
272
|
end
|
259
273
|
end
|
@@ -13,48 +13,48 @@ module Valkyrie::Sequel
|
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
)
|
16
|
+
# Construct a new Valkyrie Resource using the attributes retrieved from the database
|
17
|
+
# @return [Valkyrie::Resource]
|
18
|
+
def resource
|
19
|
+
resource_klass.new(
|
20
|
+
attributes.merge(
|
21
|
+
new_record: false,
|
22
|
+
Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK => lock_token
|
24
23
|
)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Construct the optimistic lock token using the adapter and lock version for the Resource
|
28
|
+
# @return [Valkyrie::Persistence::OptimisticLockToken]
|
29
|
+
def lock_token
|
30
|
+
return nil if object[:lock_version].blank?
|
31
|
+
@lock_token ||=
|
32
|
+
Valkyrie::Persistence::OptimisticLockToken.new(
|
33
|
+
adapter_id: resource_factory.adapter_id,
|
34
|
+
token: object[:lock_version]
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Retrieve the Class used to construct the Valkyrie Resource
|
39
|
+
# @return [Class]
|
40
|
+
def resource_klass
|
41
|
+
internal_resource.constantize
|
42
|
+
end
|
43
|
+
|
44
|
+
# Access the String for the Valkyrie Resource type within the attributes
|
45
|
+
# @return [String]
|
46
|
+
def internal_resource
|
47
|
+
attributes[:internal_resource]
|
48
|
+
end
|
49
|
+
|
50
|
+
def attributes
|
51
|
+
@attributes ||= object.except(:metadata).merge(rdf_metadata).symbolize_keys
|
52
|
+
end
|
53
|
+
|
54
|
+
# Generate a Hash derived from Valkyrie Resource metadata encoded in the RDF
|
55
|
+
# @return [Hash]
|
56
|
+
def rdf_metadata
|
57
|
+
@rdf_metadata ||= Valkyrie::Persistence::Shared::JSONValueMapper.new(object[:metadata]).result
|
58
|
+
end
|
59
59
|
end
|
60
60
|
end
|
@@ -8,7 +8,7 @@ module Valkyrie::Sequel
|
|
8
8
|
:internal_resource
|
9
9
|
].freeze
|
10
10
|
|
11
|
-
|
11
|
+
DISALLOWED_TERMS = [
|
12
12
|
:new_record
|
13
13
|
].freeze
|
14
14
|
|
@@ -23,53 +23,52 @@ module Valkyrie::Sequel
|
|
23
23
|
def convert!
|
24
24
|
output = database_hash
|
25
25
|
output[:id] = resource.id.to_s if resource.id
|
26
|
-
output.delete(:id) unless !output[:id] || QueryService::ACCEPTABLE_UUID.match?(output[:id].to_s)
|
27
26
|
process_lock_token(output)
|
28
27
|
output
|
29
28
|
end
|
30
29
|
|
31
30
|
private
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
return unless postgres_token
|
43
|
-
orm_object[:lock_version] = postgres_token.token
|
44
|
-
end
|
45
|
-
|
46
|
-
def database_hash
|
47
|
-
resource_hash.select do |k, _v|
|
48
|
-
PRIMARY_TERMS.include?(k)
|
49
|
-
end.compact.merge(
|
50
|
-
metadata: ::Sequel.pg_json(metadata_hash)
|
51
|
-
)
|
32
|
+
# Retrieves the optimistic lock token from the Valkyrie attribute value and
|
33
|
+
# sets it to the lock_version on ORM resource
|
34
|
+
# @see https://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html
|
35
|
+
# @param [ORM::Resource] orm_object
|
36
|
+
def process_lock_token(orm_object)
|
37
|
+
return unless resource.respond_to?(Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK)
|
38
|
+
postgres_token = (resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK] || []).find do |token|
|
39
|
+
token.adapter_id == resource_factory.adapter_id
|
52
40
|
end
|
41
|
+
return unless postgres_token
|
42
|
+
orm_object[:lock_version] = postgres_token.token
|
43
|
+
end
|
53
44
|
|
54
|
-
|
55
|
-
|
56
|
-
|
45
|
+
def database_hash
|
46
|
+
resource_hash.select do |k, _v|
|
47
|
+
PRIMARY_TERMS.include?(k)
|
48
|
+
end.compact.merge(
|
49
|
+
metadata: ::Sequel.pg_json(metadata_hash)
|
50
|
+
)
|
51
|
+
end
|
57
52
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def metadata_hash
|
62
|
-
Hash[
|
63
|
-
selected_resource_attributes.compact.map do |k, v|
|
64
|
-
[k, Array.wrap(v)]
|
65
|
-
end
|
66
|
-
]
|
67
|
-
end
|
53
|
+
def resource_hash
|
54
|
+
@resource_hash ||= resource.__attributes__
|
55
|
+
end
|
68
56
|
|
69
|
-
|
70
|
-
|
71
|
-
|
57
|
+
# Convert attributes to all be arrays to better enable querying and
|
58
|
+
# "changing of minds" later on.
|
59
|
+
# @return [Hash]
|
60
|
+
def metadata_hash
|
61
|
+
Hash[
|
62
|
+
selected_resource_attributes.compact.map do |k, v|
|
63
|
+
[k, Array.wrap(v)]
|
72
64
|
end
|
65
|
+
]
|
66
|
+
end
|
67
|
+
|
68
|
+
def selected_resource_attributes
|
69
|
+
resource_hash.select do |k, _v|
|
70
|
+
!PRIMARY_TERMS.include?(k) && !DISALLOWED_TERMS.include?(k)
|
73
71
|
end
|
72
|
+
end
|
74
73
|
end
|
75
74
|
end
|
data/valkyrie-sequel.gemspec
CHANGED
@@ -20,16 +20,15 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_dependency "sequel"
|
24
|
-
spec.add_dependency "sequel_pg"
|
23
|
+
spec.add_dependency "sequel", "~> 5.0"
|
24
|
+
spec.add_dependency "sequel_pg", "~> 1.0"
|
25
25
|
spec.add_dependency "valkyrie", '~> 2.1.0'
|
26
|
-
spec.add_dependency "oj"
|
26
|
+
spec.add_dependency "oj", "~> 3.0"
|
27
27
|
spec.add_development_dependency "bundler", "~> 2.0"
|
28
28
|
spec.add_development_dependency "rake"
|
29
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
30
30
|
spec.add_development_dependency "bixby"
|
31
31
|
spec.add_development_dependency "pry-byebug"
|
32
|
-
spec.add_development_dependency "database_cleaner"
|
33
|
-
spec.add_development_dependency "coveralls"
|
32
|
+
spec.add_development_dependency "database_cleaner", "< 2"
|
34
33
|
spec.add_development_dependency "simplecov"
|
35
34
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valkyrie-sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trey Pendragon
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sequel_pg
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: valkyrie
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: oj
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '3.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '3.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,30 +140,16 @@ dependencies:
|
|
140
140
|
name: database_cleaner
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: coveralls
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
143
|
+
- - "<"
|
158
144
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
145
|
+
version: '2'
|
160
146
|
type: :development
|
161
147
|
prerelease: false
|
162
148
|
version_requirements: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
|
-
- - "
|
150
|
+
- - "<"
|
165
151
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
152
|
+
version: '2'
|
167
153
|
- !ruby/object:Gem::Dependency
|
168
154
|
name: simplecov
|
169
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,7 +197,7 @@ files:
|
|
211
197
|
homepage: https://github.com/samvera-labs/valkyrie-sequel
|
212
198
|
licenses: []
|
213
199
|
metadata: {}
|
214
|
-
post_install_message:
|
200
|
+
post_install_message:
|
215
201
|
rdoc_options: []
|
216
202
|
require_paths:
|
217
203
|
- lib
|
@@ -226,8 +212,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
212
|
- !ruby/object:Gem::Version
|
227
213
|
version: '0'
|
228
214
|
requirements: []
|
229
|
-
rubygems_version: 3.
|
230
|
-
signing_key:
|
215
|
+
rubygems_version: 3.1.4
|
216
|
+
signing_key:
|
231
217
|
specification_version: 4
|
232
218
|
summary: Valkyrie::MetadataAdapter for Postgres using Sequel.
|
233
219
|
test_files: []
|