aws-record 2.10.1 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +83 -19
- data/VERSION +1 -1
- data/lib/aws-record/record/attribute.rb +8 -8
- data/lib/aws-record/record/attributes.rb +36 -49
- data/lib/aws-record/record/batch.rb +13 -12
- data/lib/aws-record/record/batch_read.rb +10 -12
- data/lib/aws-record/record/batch_write.rb +2 -1
- data/lib/aws-record/record/buildable_search.rb +37 -39
- data/lib/aws-record/record/client_configuration.rb +14 -14
- data/lib/aws-record/record/dirty_tracking.rb +29 -40
- data/lib/aws-record/record/errors.rb +11 -2
- data/lib/aws-record/record/item_collection.rb +7 -7
- data/lib/aws-record/record/item_data.rb +13 -17
- data/lib/aws-record/record/item_operations.rb +150 -138
- data/lib/aws-record/record/key_attributes.rb +0 -2
- data/lib/aws-record/record/marshalers/boolean_marshaler.rb +2 -5
- data/lib/aws-record/record/marshalers/date_marshaler.rb +1 -6
- data/lib/aws-record/record/marshalers/date_time_marshaler.rb +2 -5
- data/lib/aws-record/record/marshalers/epoch_time_marshaler.rb +2 -8
- data/lib/aws-record/record/marshalers/float_marshaler.rb +3 -8
- data/lib/aws-record/record/marshalers/integer_marshaler.rb +3 -8
- data/lib/aws-record/record/marshalers/list_marshaler.rb +4 -7
- data/lib/aws-record/record/marshalers/map_marshaler.rb +4 -7
- data/lib/aws-record/record/marshalers/numeric_set_marshaler.rb +7 -9
- data/lib/aws-record/record/marshalers/string_marshaler.rb +1 -2
- data/lib/aws-record/record/marshalers/string_set_marshaler.rb +5 -7
- data/lib/aws-record/record/marshalers/time_marshaler.rb +1 -5
- data/lib/aws-record/record/model_attributes.rb +17 -29
- data/lib/aws-record/record/query.rb +8 -11
- data/lib/aws-record/record/secondary_indexes.rb +40 -51
- data/lib/aws-record/record/table_config.rb +93 -115
- data/lib/aws-record/record/table_migration.rb +56 -72
- data/lib/aws-record/record/transactions.rb +40 -43
- data/lib/aws-record/record/version.rb +1 -1
- data/lib/aws-record/record.rb +36 -44
- metadata +13 -8
@@ -3,10 +3,9 @@
|
|
3
3
|
module Aws
|
4
4
|
module Record
|
5
5
|
class TableMigration
|
6
|
-
|
7
6
|
# @!attribute [rw] client
|
8
7
|
# @return [Aws::DynamoDB::Client] the
|
9
|
-
# {http://docs.aws.amazon.com/
|
8
|
+
# {http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html Aws::DynamoDB::Client}
|
10
9
|
# class used by this table migration instance.
|
11
10
|
attr_accessor :client
|
12
11
|
|
@@ -14,19 +13,21 @@ module Aws
|
|
14
13
|
# @param [Hash] opts
|
15
14
|
# @option opts [Aws::DynamoDB::Client] :client Allows you to inject your
|
16
15
|
# own
|
17
|
-
# {http://docs.aws.amazon.com/
|
16
|
+
# {http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html Aws::DynamoDB::Client}
|
18
17
|
# class. If this option is not included, a client will be constructed for
|
19
18
|
# you with default parameters.
|
20
19
|
def initialize(model, opts = {})
|
21
20
|
_assert_model_valid(model)
|
22
21
|
@model = model
|
23
22
|
@client = opts[:client] || model.dynamodb_client || Aws::DynamoDB::Client.new
|
23
|
+
@client.config.user_agent_frameworks << 'aws-record'
|
24
24
|
end
|
25
25
|
|
26
26
|
# This method calls
|
27
|
-
# {http://docs.aws.amazon.com/
|
28
|
-
# populating the attribute definitions and
|
29
|
-
# class, as well as passing through other
|
27
|
+
# {http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#create_table-instance_method
|
28
|
+
# Aws::DynamoDB::Client#create_table}, populating the attribute definitions and
|
29
|
+
# key schema based on your model class, as well as passing through other
|
30
|
+
# parameters as provided by you.
|
30
31
|
#
|
31
32
|
# @example Creating a table with a global secondary index named +:gsi+
|
32
33
|
# migration.create!(
|
@@ -63,22 +64,20 @@ module Aws
|
|
63
64
|
gsit = opts.delete(:global_secondary_index_throughput)
|
64
65
|
_validate_billing(opts)
|
65
66
|
|
66
|
-
create_opts = opts.merge(
|
67
|
+
create_opts = opts.merge(
|
67
68
|
table_name: @model.table_name,
|
68
69
|
attribute_definitions: _attribute_definitions,
|
69
70
|
key_schema: _key_schema
|
70
|
-
|
71
|
-
if lsis = @model.local_secondary_indexes_for_migration
|
71
|
+
)
|
72
|
+
if (lsis = @model.local_secondary_indexes_for_migration)
|
72
73
|
create_opts[:local_secondary_indexes] = lsis
|
73
74
|
_append_to_attribute_definitions(lsis, create_opts)
|
74
75
|
end
|
75
|
-
if gsis = @model.global_secondary_indexes_for_migration
|
76
|
+
if (gsis = @model.global_secondary_indexes_for_migration)
|
76
77
|
unless gsit || opts[:billing_mode] == 'PAY_PER_REQUEST'
|
77
|
-
raise ArgumentError
|
78
|
-
|
79
|
-
|
80
|
-
" unless :billing_mode is set to 'PAY_PER_REQUEST'."
|
81
|
-
)
|
78
|
+
raise ArgumentError, 'If you define global secondary indexes, you must also define ' \
|
79
|
+
':global_secondary_index_throughput on table creation, ' \
|
80
|
+
"unless :billing_mode is set to 'PAY_PER_REQUEST'."
|
82
81
|
end
|
83
82
|
gsis_opts = if opts[:billing_mode] == 'PAY_PER_REQUEST'
|
84
83
|
gsis
|
@@ -92,8 +91,8 @@ module Aws
|
|
92
91
|
end
|
93
92
|
|
94
93
|
# This method calls
|
95
|
-
# {http://docs.aws.amazon.com/
|
96
|
-
# using the parameters that you provide.
|
94
|
+
# {http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#update_table-instance_method
|
95
|
+
# Aws::DynamoDB::Client#update_table} using the parameters that you provide.
|
97
96
|
#
|
98
97
|
# @param [Hash] opts options to pass on to the client call to
|
99
98
|
# +#update_table+. See the documentation above in the AWS SDK for Ruby
|
@@ -101,28 +100,24 @@ module Aws
|
|
101
100
|
# @raise [Aws::Record::Errors::TableDoesNotExist] if the table does not
|
102
101
|
# currently exist in Amazon DynamoDB.
|
103
102
|
def update!(opts)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
raise Errors::TableDoesNotExist.new(e)
|
111
|
-
end
|
103
|
+
update_opts = opts.merge(
|
104
|
+
table_name: @model.table_name
|
105
|
+
)
|
106
|
+
@client.update_table(update_opts)
|
107
|
+
rescue DynamoDB::Errors::ResourceNotFoundException
|
108
|
+
raise Errors::TableDoesNotExist
|
112
109
|
end
|
113
110
|
|
114
111
|
# This method calls
|
115
|
-
# {http://docs.aws.amazon.com/
|
116
|
-
# using the table name of your model.
|
112
|
+
# {http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#delete_table-instance_method
|
113
|
+
# Aws::DynamoDB::Client#delete_table} using the table name of your model.
|
117
114
|
#
|
118
115
|
# @raise [Aws::Record::Errors::TableDoesNotExist] if the table did not
|
119
116
|
# exist in Amazon DynamoDB at the time of calling.
|
120
117
|
def delete!
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
raise Errors::TableDoesNotExist.new(e)
|
125
|
-
end
|
118
|
+
@client.delete_table(table_name: @model.table_name)
|
119
|
+
rescue DynamoDB::Errors::ResourceNotFoundException
|
120
|
+
raise Errors::TableDoesNotExist
|
126
121
|
end
|
127
122
|
|
128
123
|
# This method waits on the table specified in the model to exist and be
|
@@ -134,46 +129,37 @@ module Aws
|
|
134
129
|
end
|
135
130
|
|
136
131
|
private
|
132
|
+
|
137
133
|
def _assert_model_valid(model)
|
138
134
|
_assert_required_include(model)
|
139
135
|
model.model_valid?
|
140
136
|
end
|
141
137
|
|
142
138
|
def _assert_required_include(model)
|
143
|
-
|
144
|
-
|
145
|
-
|
139
|
+
return if model.include?(::Aws::Record)
|
140
|
+
|
141
|
+
raise Errors::InvalidModel, 'Table models must include Aws::Record'
|
146
142
|
end
|
147
143
|
|
148
144
|
def _validate_billing(opts)
|
149
145
|
valid_modes = %w[PAY_PER_REQUEST PROVISIONED]
|
150
|
-
if opts.key?(:billing_mode)
|
151
|
-
|
152
|
-
|
153
|
-
":billing_mode option must be one of #{valid_modes.join(', ')}"\
|
154
|
-
" current value is: #{opts[:billing_mode]}"
|
155
|
-
)
|
156
|
-
end
|
146
|
+
if opts.key?(:billing_mode) && !valid_modes.include?(opts[:billing_mode])
|
147
|
+
raise ArgumentError, ":billing_mode option must be one of #{valid_modes.join(', ')} " \
|
148
|
+
"current value is: #{opts[:billing_mode]}"
|
157
149
|
end
|
158
150
|
if opts.key?(:provisioned_throughput)
|
159
151
|
if opts[:billing_mode] == 'PAY_PER_REQUEST'
|
160
|
-
raise ArgumentError
|
161
|
-
|
162
|
-
" must either be unspecified or have a value of 'PROVISIONED'"
|
163
|
-
)
|
164
|
-
end
|
165
|
-
else
|
166
|
-
if opts[:billing_mode] != 'PAY_PER_REQUEST'
|
167
|
-
raise ArgumentError.new(
|
168
|
-
'when :provisioned_throughput option is not specified,'\
|
169
|
-
" :billing_mode must be set to 'PAY_PER_REQUEST'"
|
170
|
-
)
|
152
|
+
raise ArgumentError, 'when :provisioned_throughput option is specified, :billing_mode ' \
|
153
|
+
"must either be unspecified or have a value of 'PROVISIONED'"
|
171
154
|
end
|
155
|
+
elsif opts[:billing_mode] != 'PAY_PER_REQUEST'
|
156
|
+
raise ArgumentError, 'when :provisioned_throughput option is not specified, ' \
|
157
|
+
":billing_mode must be set to 'PAY_PER_REQUEST'"
|
172
158
|
end
|
173
159
|
end
|
174
160
|
|
175
161
|
def _attribute_definitions
|
176
|
-
_keys.map do |
|
162
|
+
_keys.map do |_type, attr|
|
177
163
|
{
|
178
164
|
attribute_name: attr.database_name,
|
179
165
|
attribute_type: attr.dynamodb_type
|
@@ -186,18 +172,18 @@ module Aws
|
|
186
172
|
attr_def = create_opts[:attribute_definitions]
|
187
173
|
secondary_indexes.each do |si|
|
188
174
|
si[:key_schema].each do |key_schema|
|
189
|
-
exists = attr_def.find
|
175
|
+
exists = attr_def.find do |a|
|
190
176
|
a[:attribute_name] == key_schema[:attribute_name]
|
191
|
-
}
|
192
|
-
unless exists
|
193
|
-
attr = attributes.attribute_for(
|
194
|
-
attributes.db_to_attribute_name(key_schema[:attribute_name])
|
195
|
-
)
|
196
|
-
attr_def << {
|
197
|
-
attribute_name: attr.database_name,
|
198
|
-
attribute_type: attr.dynamodb_type
|
199
|
-
}
|
200
177
|
end
|
178
|
+
next if exists
|
179
|
+
|
180
|
+
attr = attributes.attribute_for(
|
181
|
+
attributes.db_to_attribute_name(key_schema[:attribute_name])
|
182
|
+
)
|
183
|
+
attr_def << {
|
184
|
+
attribute_name: attr.database_name,
|
185
|
+
attribute_type: attr.dynamodb_type
|
186
|
+
}
|
201
187
|
end
|
202
188
|
end
|
203
189
|
create_opts[:attribute_definitions] = attr_def
|
@@ -212,12 +198,10 @@ module Aws
|
|
212
198
|
params.merge(provisioned_throughput: throughput)
|
213
199
|
end
|
214
200
|
unless missing_throughput.empty?
|
215
|
-
raise ArgumentError
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
" #{gsi_throughput}"
|
220
|
-
)
|
201
|
+
raise ArgumentError, 'Missing provisioned throughput for the following global secondary ' \
|
202
|
+
"indexes: #{missing_throughput.join(', ')}. GSIs: " \
|
203
|
+
"#{global_secondary_indexes} and defined throughput: " \
|
204
|
+
"#{gsi_throughput}"
|
221
205
|
end
|
222
206
|
ret
|
223
207
|
end
|
@@ -226,13 +210,13 @@ module Aws
|
|
226
210
|
_keys.map do |type, attr|
|
227
211
|
{
|
228
212
|
attribute_name: attr.database_name,
|
229
|
-
key_type: type == :hash ?
|
213
|
+
key_type: type == :hash ? 'HASH' : 'RANGE'
|
230
214
|
}
|
231
215
|
end
|
232
216
|
end
|
233
217
|
|
234
218
|
def _keys
|
235
|
-
@model.keys.
|
219
|
+
@model.keys.each_with_object({}) do |(type, name), acc|
|
236
220
|
acc[type] = @model.attributes.attribute_for(name)
|
237
221
|
acc
|
238
222
|
end
|
@@ -6,7 +6,6 @@ module Aws
|
|
6
6
|
extend ClientConfiguration
|
7
7
|
|
8
8
|
class << self
|
9
|
-
|
10
9
|
# @example Usage Example
|
11
10
|
# class TableOne
|
12
11
|
# include Aws::Record
|
@@ -43,11 +42,11 @@ module Aws
|
|
43
42
|
# * The aggregate size of the items in the transaction cannot exceed 4 MB.
|
44
43
|
#
|
45
44
|
# @param [Hash] opts Options to pass through to
|
46
|
-
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#transact_get_items-instance_method
|
47
|
-
# with the exception of the
|
48
|
-
# {ItemOperations.ItemOperationsClassMethods.tfind_opts #tfind_opts}
|
49
|
-
# on your model class to provide extra metadata
|
50
|
-
# after retrieval.
|
45
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#transact_get_items-instance_method
|
46
|
+
# Aws::DynamoDB::Client#transact_get_items}, with the exception of the
|
47
|
+
# +:transact_items+ array, which uses the {ItemOperations.ItemOperationsClassMethods.tfind_opts #tfind_opts}
|
48
|
+
# operation on your model class to provide extra metadata
|
49
|
+
# used to marshal your items after retrieval.
|
51
50
|
# @option opts [Array] :transact_items A set of +#tfind_opts+ results,
|
52
51
|
# such as those created by the usage example.
|
53
52
|
# @option opts [Aws::DynamoDB::Client] :client Optionally, you can pass
|
@@ -71,7 +70,6 @@ module Aws
|
|
71
70
|
client_resp = client.transact_get_items(
|
72
71
|
request_opts
|
73
72
|
)
|
74
|
-
responses = client_resp.responses
|
75
73
|
index = -1
|
76
74
|
ret = OpenStruct.new
|
77
75
|
ret.consumed_capacity = client_resp.consumed_capacity
|
@@ -187,11 +185,11 @@ module Aws
|
|
187
185
|
# * There is a user error, such as an invalid data format.
|
188
186
|
#
|
189
187
|
# @param [Hash] opts Options to pass through to
|
190
|
-
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#transact_write_items-instance_method
|
191
|
-
# with the exception of
|
192
|
-
# to use your item to populate
|
193
|
-
# :
|
194
|
-
# for a comprehensive set of combinations.
|
188
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#transact_write_items-instance_method
|
189
|
+
# Aws::DynamoDB::Client#transact_write_items} with the exception of
|
190
|
+
# :transact_items array, which is transformed to use your item to populate
|
191
|
+
# the :key, :table_name, :item, and/or :update_expression parameters
|
192
|
+
# as appropriate. See the usage example for a comprehensive set of combinations.
|
195
193
|
# @option opts [Array] :transact_items An array of hashes, accepting
|
196
194
|
# +:save+, +:put+, +:delete+, +:update+, and +:check+ as specified.
|
197
195
|
# @option opts [Aws::DynamoDB::Client] :client Optionally, you can
|
@@ -212,35 +210,35 @@ module Aws
|
|
212
210
|
opts[:transact_items] = transact_items
|
213
211
|
resp = client.transact_write_items(opts)
|
214
212
|
# mark all items clean/destroyed as needed if we didn't raise an exception
|
215
|
-
dirty_items.each
|
216
|
-
delete_items.each { |i| i.instance_variable_get(
|
213
|
+
dirty_items.each(&:clean!)
|
214
|
+
delete_items.each { |i| i.instance_variable_get('@data').destroyed = true }
|
217
215
|
resp
|
218
216
|
end
|
219
217
|
|
220
218
|
private
|
219
|
+
|
221
220
|
def _transform_transact_write_items(transact_items, dirty_items, delete_items)
|
222
221
|
transact_items.map do |item|
|
223
222
|
# this code will assume users only provided one operation, and
|
224
223
|
# will fail down the line if that assumption is wrong
|
225
|
-
if save_record = item.delete(:save)
|
224
|
+
if (save_record = item.delete(:save))
|
226
225
|
dirty_items << save_record
|
227
226
|
_transform_save_record(save_record, item)
|
228
|
-
elsif put_record = item.delete(:put)
|
227
|
+
elsif (put_record = item.delete(:put))
|
229
228
|
dirty_items << put_record
|
230
229
|
_transform_put_record(put_record, item)
|
231
|
-
elsif delete_record = item.delete(:delete)
|
230
|
+
elsif (delete_record = item.delete(:delete))
|
232
231
|
delete_items << delete_record
|
233
232
|
_transform_delete_record(delete_record, item)
|
234
|
-
elsif update_record = item.delete(:update)
|
233
|
+
elsif (update_record = item.delete(:update))
|
235
234
|
dirty_items << update_record
|
236
235
|
_transform_update_record(update_record, item)
|
237
|
-
elsif check_record = item.delete(:check)
|
236
|
+
elsif (check_record = item.delete(:check))
|
238
237
|
_transform_check_record(check_record, item)
|
239
238
|
else
|
240
|
-
raise ArgumentError
|
241
|
-
|
242
|
-
|
243
|
-
)
|
239
|
+
raise ArgumentError, 'Invalid transact write item, must include an operation of ' \
|
240
|
+
"type :save, :update, :delete, :update, or :check - #{item}"
|
241
|
+
|
244
242
|
end
|
245
243
|
end
|
246
244
|
end
|
@@ -251,16 +249,15 @@ module Aws
|
|
251
249
|
if save_record.send(:expect_new_item?)
|
252
250
|
safety_expression = save_record.send(:prevent_overwrite_expression)
|
253
251
|
if opts.include?(:condition_expression)
|
254
|
-
raise Errors::TransactionalSaveConditionCollision
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
)
|
252
|
+
raise Errors::TransactionalSaveConditionCollision,
|
253
|
+
'Transactional write includes a :save operation that would ' \
|
254
|
+
"result in a 'safe put' for the given item, yet a " \
|
255
|
+
'condition expression was also provided. This is not ' \
|
256
|
+
'currently supported. You should rewrite this case to use ' \
|
257
|
+
'a :put transaction, adding the existence check to your ' \
|
258
|
+
"own condition expression if desired.\n" \
|
259
|
+
"\tItem: #{JSON.pretty_unparse(save_record.to_h)}\n" \
|
260
|
+
"\tExtra Options: #{JSON.pretty_unparse(opts)}"
|
264
261
|
else
|
265
262
|
opts = opts.merge(safety_expression)
|
266
263
|
_transform_put_record(save_record, opts)
|
@@ -296,16 +293,16 @@ module Aws
|
|
296
293
|
opts[:key] = update_record.send(:key_values)
|
297
294
|
opts[:update_expression] = uex
|
298
295
|
# need to combine expression attribute names and values
|
299
|
-
if names = opts[:expression_attribute_names]
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
if values = opts[:expression_attribute_values]
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
296
|
+
opts[:expression_attribute_names] = if (names = opts[:expression_attribute_names])
|
297
|
+
exp_attr_names.merge(names)
|
298
|
+
else
|
299
|
+
exp_attr_names
|
300
|
+
end
|
301
|
+
opts[:expression_attribute_values] = if (values = opts[:expression_attribute_values])
|
302
|
+
exp_attr_values.merge(values)
|
303
|
+
else
|
304
|
+
exp_attr_values
|
305
|
+
end
|
309
306
|
{ update: opts }
|
310
307
|
end
|
311
308
|
|
data/lib/aws-record/record.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Aws
|
4
|
-
|
5
4
|
# +Aws::Record+ is the module you include in your model classes in order to
|
6
5
|
# decorate them with the Amazon DynamoDB integration methods provided by this
|
7
6
|
# library. Methods you can use are shown below, in sub-modules organized by
|
@@ -73,9 +72,7 @@ module Aws
|
|
73
72
|
sub_class.send(:include, DirtyTracking)
|
74
73
|
sub_class.send(:include, Query)
|
75
74
|
sub_class.send(:include, SecondaryIndexes)
|
76
|
-
if Aws::Record.extends_record?(sub_class)
|
77
|
-
inherit_track_mutations(sub_class)
|
78
|
-
end
|
75
|
+
inherit_track_mutations(sub_class) if Aws::Record.extends_record?(sub_class)
|
79
76
|
end
|
80
77
|
|
81
78
|
# @api private
|
@@ -83,18 +80,21 @@ module Aws
|
|
83
80
|
klass.superclass.include?(Aws::Record)
|
84
81
|
end
|
85
82
|
|
83
|
+
# @api private
|
84
|
+
def self.inherit_track_mutations(klass)
|
85
|
+
superclass_track_mutations = klass.superclass.instance_variable_get('@track_mutations')
|
86
|
+
klass.instance_variable_set('@track_mutations', superclass_track_mutations)
|
87
|
+
end
|
88
|
+
|
89
|
+
private_class_method :inherit_track_mutations
|
90
|
+
|
86
91
|
private
|
92
|
+
|
87
93
|
def dynamodb_client
|
88
94
|
self.class.dynamodb_client
|
89
95
|
end
|
90
96
|
|
91
|
-
def self.inherit_track_mutations(klass)
|
92
|
-
superclass_track_mutations = klass.superclass.instance_variable_get("@track_mutations")
|
93
|
-
klass.instance_variable_set("@track_mutations", superclass_track_mutations)
|
94
|
-
end
|
95
|
-
|
96
97
|
module RecordClassMethods
|
97
|
-
|
98
98
|
# Returns the Amazon DynamoDB table name for this model class.
|
99
99
|
#
|
100
100
|
# By default, this will simply be the name of the class. However, you can
|
@@ -116,14 +116,15 @@ module Aws
|
|
116
116
|
# MyTable.table_name # => "MyTable"
|
117
117
|
# MyOtherTable.table_name # => "test_MyTable"
|
118
118
|
def table_name
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
119
|
+
# rubocop:disable Style/RedundantSelf
|
120
|
+
@table_name ||= if Aws::Record.extends_record?(self) &&
|
121
|
+
default_table_name(self.superclass) != self.superclass.table_name
|
122
|
+
self.superclass.instance_variable_get('@table_name')
|
123
|
+
else
|
124
|
+
default_table_name(self)
|
125
|
+
end
|
126
|
+
|
127
|
+
# rubocop:enable Style/RedundantSelf
|
127
128
|
end
|
128
129
|
|
129
130
|
# Allows you to set a custom Amazon DynamoDB table name for this model
|
@@ -175,7 +176,7 @@ module Aws
|
|
175
176
|
# end
|
176
177
|
#
|
177
178
|
# Dog.table_name # => "DogTable"
|
178
|
-
def set_table_name(name)
|
179
|
+
def set_table_name(name) # rubocop:disable Naming/AccessorMethodName
|
179
180
|
@table_name = name
|
180
181
|
end
|
181
182
|
|
@@ -187,32 +188,24 @@ module Aws
|
|
187
188
|
# @raise [Aws::Record::Errors::TableDoesNotExist] if the table name does
|
188
189
|
# not exist in DynamoDB.
|
189
190
|
def provisioned_throughput
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
raise Record::Errors::TableDoesNotExist
|
199
|
-
end
|
191
|
+
resp = dynamodb_client.describe_table(table_name: table_name)
|
192
|
+
throughput = resp.table.provisioned_throughput
|
193
|
+
{
|
194
|
+
read_capacity_units: throughput.read_capacity_units,
|
195
|
+
write_capacity_units: throughput.write_capacity_units
|
196
|
+
}
|
197
|
+
rescue DynamoDB::Errors::ResourceNotFoundException
|
198
|
+
raise Record::Errors::TableDoesNotExist
|
200
199
|
end
|
201
200
|
|
202
201
|
# Checks if the model's table name exists in Amazon DynamoDB.
|
203
202
|
#
|
204
203
|
# @return [Boolean] true if the table does exist, false if it does not.
|
205
204
|
def table_exists?
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
else
|
211
|
-
false
|
212
|
-
end
|
213
|
-
rescue DynamoDB::Errors::ResourceNotFoundException
|
214
|
-
false
|
215
|
-
end
|
205
|
+
resp = dynamodb_client.describe_table(table_name: table_name)
|
206
|
+
resp.table.table_status == 'ACTIVE'
|
207
|
+
rescue DynamoDB::Errors::ResourceNotFoundException
|
208
|
+
false
|
216
209
|
end
|
217
210
|
|
218
211
|
# Turns off mutation tracking for all attributes in the model.
|
@@ -246,17 +239,16 @@ module Aws
|
|
246
239
|
end
|
247
240
|
|
248
241
|
def model_valid?
|
249
|
-
if @keys.hash_key.nil?
|
250
|
-
raise Errors::InvalidModel.new("Table models must include a hash key")
|
251
|
-
end
|
242
|
+
raise Errors::InvalidModel, 'Table models must include a hash key' if @keys.hash_key.nil?
|
252
243
|
end
|
253
244
|
|
254
245
|
private
|
246
|
+
|
255
247
|
def default_table_name(klass)
|
256
248
|
return unless klass.name
|
257
|
-
klass.name.split("::").join("_")
|
258
|
-
end
|
259
249
|
|
250
|
+
klass.name.split('::').join('_')
|
251
|
+
end
|
260
252
|
end
|
261
253
|
end
|
262
254
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amazon Web Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-dynamodb
|
@@ -16,18 +16,23 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.85.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
29
|
+
version: '1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.85.0
|
27
33
|
description: Provides an object mapping abstraction for Amazon DynamoDB.
|
28
34
|
email:
|
29
|
-
-
|
30
|
-
- alexwoo@amazon.com
|
35
|
+
- aws-dr-rubygems@amazon.com
|
31
36
|
executables: []
|
32
37
|
extensions: []
|
33
38
|
extra_rdoc_files: []
|
@@ -81,14 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
86
|
requirements:
|
82
87
|
- - ">="
|
83
88
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
89
|
+
version: '2.3'
|
85
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
91
|
requirements:
|
87
92
|
- - ">="
|
88
93
|
- !ruby/object:Gem::Version
|
89
94
|
version: '0'
|
90
95
|
requirements: []
|
91
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.4.10
|
92
97
|
signing_key:
|
93
98
|
specification_version: 4
|
94
99
|
summary: AWS Record library for Amazon DynamoDB
|