dynamodb_framework 1.5.2 → 1.9.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 +5 -5
- data/lib/dynamodb_framework/dynamodb_attributes_builder.rb +4 -0
- data/lib/dynamodb_framework/dynamodb_index.rb +26 -3
- data/lib/dynamodb_framework/dynamodb_table.rb +43 -2
- data/lib/dynamodb_framework/dynamodb_table_manager.rb +115 -21
- data/lib/dynamodb_framework/version.rb +1 -1
- data/spec/{dynamodb_index_spec.rb → dynamodb_framework/dynamodb_index_spec.rb} +0 -0
- data/spec/{dynamodb_migration_manager_spec.rb → dynamodb_framework/dynamodb_migration_manager_spec.rb} +0 -0
- data/spec/{dynamodb_namespace_migration_manager_spec.rb → dynamodb_framework/dynamodb_namespace_migration_manager_spec.rb} +0 -0
- data/spec/{dynamodb_query_spec.rb → dynamodb_framework/dynamodb_query_spec.rb} +0 -0
- data/spec/{dynamodb_repository_spec.rb → dynamodb_framework/dynamodb_repository_spec.rb} +0 -0
- data/spec/{dynamodb_table_manager_spec.rb → dynamodb_framework/dynamodb_table_manager_spec.rb} +50 -0
- data/spec/{dynamodb_table_spec.rb → dynamodb_framework/dynamodb_table_spec.rb} +52 -0
- data/spec/{hash_helper_spec.rb → dynamodb_framework/hash_helper_spec.rb} +0 -0
- data/spec/example_index.rb +2 -2
- data/spec/example_table.rb +2 -2
- data/spec/spec_helper.rb +6 -6
- metadata +22 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a38a1f91daf2b721a7f09e6f4ff5d9a796f8d0b22f09908d46717f96e9a0661b
|
4
|
+
data.tar.gz: 46d2c82a0ab2042abaf0e3dd317038eda3861e40006ac4eed1067b9da9d4fd01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e4c59111999afe7ae06282a121e0c46c2ac5935dc006e2630d83a4c26a9afd760d9a7f120c720e4471d633f4f4db83d5609bb0b1b48aaebf517b8b8a6698208
|
7
|
+
data.tar.gz: 2e3161f248e86fe8d65145c9b9483b0f7f90f179a8fd1c93e60b4b7c6eaf571387754c9dabb89def3b015755f61d87e9faad66a1267ca5454b9cfce00562f937
|
@@ -46,13 +46,19 @@ module DynamoDbFramework
|
|
46
46
|
self.instance_variable_set(:@range_key, { field: field, type: type })
|
47
47
|
end
|
48
48
|
|
49
|
-
def create(store: DynamoDbFramework.default_store, read_capacity: 25, write_capacity: 25)
|
49
|
+
def create(store: DynamoDbFramework.default_store, read_capacity: 25, write_capacity: 25, submit: true, billing_mode: 'PROVISIONED')
|
50
50
|
unless self.instance_variable_defined?(:@table)
|
51
51
|
raise DynamoDbFramework::Index::InvalidConfigException.new('Table must be specified.')
|
52
52
|
end
|
53
53
|
table = self.instance_variable_get(:@table)
|
54
54
|
table_name = table.config[:table_name]
|
55
55
|
|
56
|
+
#make method idempotent
|
57
|
+
if exists?(store: store)
|
58
|
+
wait_until_active(store: store)
|
59
|
+
return
|
60
|
+
end
|
61
|
+
|
56
62
|
unless self.instance_variable_defined?(:@partition_key)
|
57
63
|
raise DynamoDbFramework::Index::InvalidConfigException.new('Partition key must be specified.')
|
58
64
|
end
|
@@ -78,9 +84,13 @@ module DynamoDbFramework
|
|
78
84
|
|
79
85
|
range_key_field = range_key[:field] unless range_key == nil
|
80
86
|
|
81
|
-
index =table_manager.create_global_index(full_index_name, partition_key[:field], range_key_field, read_capacity, write_capacity)
|
87
|
+
index =table_manager.create_global_index(full_index_name, partition_key[:field], range_key_field, read_capacity, write_capacity, billing_mode)
|
88
|
+
|
89
|
+
if submit
|
90
|
+
table_manager.add_index(table_name, builder.attributes, index, billing_mode)
|
91
|
+
end
|
82
92
|
|
83
|
-
|
93
|
+
index
|
84
94
|
end
|
85
95
|
|
86
96
|
def update(store: DynamoDbFramework.default_store, read_capacity:, write_capacity:)
|
@@ -99,6 +109,10 @@ module DynamoDbFramework
|
|
99
109
|
table = self.instance_variable_get(:@table)
|
100
110
|
table_name = table.config[:table_name]
|
101
111
|
|
112
|
+
unless exists?(store: store)
|
113
|
+
return
|
114
|
+
end
|
115
|
+
|
102
116
|
DynamoDbFramework::TableManager.new(store).drop_index(table_name, full_index_name)
|
103
117
|
end
|
104
118
|
|
@@ -111,6 +125,15 @@ module DynamoDbFramework
|
|
111
125
|
DynamoDbFramework::TableManager.new(store).has_index?(table_name, full_index_name)
|
112
126
|
end
|
113
127
|
|
128
|
+
def wait_until_active(store: DynamoDbFramework.default_store)
|
129
|
+
unless self.instance_variable_defined?(:@table)
|
130
|
+
raise DynamoDbFramework::Index::InvalidConfigException.new('Table must be specified.')
|
131
|
+
end
|
132
|
+
table = self.instance_variable_get(:@table)
|
133
|
+
table_name = table.config[:table_name]
|
134
|
+
DynamoDbFramework::TableManager.new(store).wait_until_index_active(table_name, full_index_name)
|
135
|
+
end
|
136
|
+
|
114
137
|
def query(partition:)
|
115
138
|
DynamoDbFramework::Query.new(index_name: config[:index_name], table_name: config[:table].config[:table_name], partition_key: config[:partition_key][:field], partition_value: partition)
|
116
139
|
end
|
@@ -41,7 +41,14 @@ module DynamoDbFramework
|
|
41
41
|
self.instance_variable_set(:@range_key, { field: field, type: type })
|
42
42
|
end
|
43
43
|
|
44
|
-
def create(store: DynamoDbFramework.default_store, read_capacity: 25, write_capacity: 25)
|
44
|
+
def create(store: DynamoDbFramework.default_store, read_capacity: 25, write_capacity: 25, indexes: [])
|
45
|
+
|
46
|
+
#make method idempotent
|
47
|
+
if exists?(store: store)
|
48
|
+
wait_until_active(store: store)
|
49
|
+
return
|
50
|
+
end
|
51
|
+
|
45
52
|
unless self.instance_variable_defined?(:@partition_key)
|
46
53
|
raise DynamoDbFramework::Table::InvalidConfigException.new('Partition key must be specified.')
|
47
54
|
end
|
@@ -57,7 +64,26 @@ module DynamoDbFramework
|
|
57
64
|
builder.add({ name: range_key[:field], type: range_key[:type], key: :range })
|
58
65
|
end
|
59
66
|
|
60
|
-
|
67
|
+
global_indexes = nil
|
68
|
+
if indexes != nil && indexes.length > 0
|
69
|
+
global_indexes = []
|
70
|
+
indexes.each do |i|
|
71
|
+
global_indexes << i.create(store: store, submit: false, read_capacity: read_capacity, write_capacity: write_capacity)
|
72
|
+
index_partition_key = i.instance_variable_get(:@partition_key)
|
73
|
+
unless builder.contains(name: index_partition_key[:field])
|
74
|
+
builder.add({ name: index_partition_key[:field], type: index_partition_key[:type] })
|
75
|
+
end
|
76
|
+
if i.instance_variable_defined?(:@range_key)
|
77
|
+
index_range_key = i.instance_variable_get(:@range_key)
|
78
|
+
unless builder.contains(name: index_range_key[:field])
|
79
|
+
builder.add({ name: index_range_key[:field], type: index_range_key[:type] })
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
DynamoDbFramework::TableManager.new(store).create_table({ name: full_table_name, attributes: builder.attributes, read_capacity: read_capacity, write_capacity: write_capacity, global_indexes: global_indexes })
|
61
87
|
end
|
62
88
|
|
63
89
|
def update(store: DynamoDbFramework.default_store, read_capacity:, write_capacity:)
|
@@ -65,6 +91,9 @@ module DynamoDbFramework
|
|
65
91
|
end
|
66
92
|
|
67
93
|
def drop(store: DynamoDbFramework.default_store)
|
94
|
+
unless exists?(store: store)
|
95
|
+
return
|
96
|
+
end
|
68
97
|
DynamoDbFramework::TableManager.new(store).drop(full_table_name)
|
69
98
|
end
|
70
99
|
|
@@ -72,6 +101,18 @@ module DynamoDbFramework
|
|
72
101
|
DynamoDbFramework::TableManager.new(store).exists?(full_table_name)
|
73
102
|
end
|
74
103
|
|
104
|
+
def wait_until_active(store: DynamoDbFramework.default_store)
|
105
|
+
DynamoDbFramework::TableManager.new(store).wait_until_active(full_table_name)
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_status(store: DynamoDbFramework.default_store)
|
109
|
+
DynamoDbFramework::TableManager.new(store).get_status(full_table_name)
|
110
|
+
end
|
111
|
+
|
112
|
+
def active?(store: DynamoDbFramework.default_store)
|
113
|
+
DynamoDbFramework::TableManager.new(store).get_status(full_table_name) == 'ACTIVE'
|
114
|
+
end
|
115
|
+
|
75
116
|
def query(partition:)
|
76
117
|
DynamoDbFramework::Query.new(table_name: config[:table_name], partition_key: config[:partition_key][:field], partition_value: partition)
|
77
118
|
end
|
@@ -66,7 +66,7 @@ module DynamoDbFramework
|
|
66
66
|
|
67
67
|
end
|
68
68
|
|
69
|
-
def add_index(table_name, attributes, global_index)
|
69
|
+
def add_index(table_name, attributes, global_index, billing_mode = 'PROVISIONED')
|
70
70
|
|
71
71
|
attribute_definitions = []
|
72
72
|
|
@@ -79,7 +79,8 @@ module DynamoDbFramework
|
|
79
79
|
:attribute_definitions => attribute_definitions,
|
80
80
|
:global_secondary_index_updates => [
|
81
81
|
:create => global_index
|
82
|
-
]
|
82
|
+
],
|
83
|
+
:billing_mode => billing_mode
|
83
84
|
}
|
84
85
|
|
85
86
|
dynamodb.client.update_table(table)
|
@@ -115,7 +116,38 @@ module DynamoDbFramework
|
|
115
116
|
DynamoDbFramework.logger.info "[#{self.class}] -Table: [#{table_name}] updated."
|
116
117
|
end
|
117
118
|
|
119
|
+
def update_ttl_attribute(table_name, enabled, attribute_name)
|
120
|
+
table = {
|
121
|
+
:table_name => table_name,
|
122
|
+
:time_to_live_specification => {
|
123
|
+
:enabled => enabled,
|
124
|
+
:attribute_name => attribute_name
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
DynamoDbFramework.logger.info "[#{self.class}] -Updating TTL Attribute: #{attribute_name}."
|
129
|
+
dynamodb.client.update_time_to_live(table)
|
130
|
+
|
131
|
+
# wait for table to be updated
|
132
|
+
DynamoDbFramework.logger.info "[#{self.class}] -Waiting for table: [#{table_name}] to be updated."
|
133
|
+
wait_until_ttl_changed(table_name)
|
134
|
+
|
135
|
+
DynamoDbFramework.logger.info "[#{self.class}] -Table: [#{table_name}] updated."
|
136
|
+
end
|
137
|
+
|
138
|
+
def get_ttl_status(table_name)
|
139
|
+
table = {
|
140
|
+
:table_name => table_name
|
141
|
+
}
|
142
|
+
|
143
|
+
dynamodb.client.describe_time_to_live(table)['time_to_live_description']
|
144
|
+
end
|
145
|
+
|
118
146
|
def drop_index(table_name, index_name)
|
147
|
+
unless has_index?(table_name, index_name)
|
148
|
+
return
|
149
|
+
end
|
150
|
+
|
119
151
|
table = {
|
120
152
|
:table_name => table_name,
|
121
153
|
:global_secondary_index_updates => [
|
@@ -130,6 +162,7 @@ module DynamoDbFramework
|
|
130
162
|
# wait for table to be updated
|
131
163
|
DynamoDbFramework.logger.info "[#{self.class}] -Deleting global index: #{index_name}."
|
132
164
|
wait_until_index_dropped(table_name, index_name)
|
165
|
+
|
133
166
|
DynamoDbFramework.logger.info "[#{self.class}] -Index: [#{index_name}] dropped."
|
134
167
|
end
|
135
168
|
|
@@ -154,9 +187,13 @@ module DynamoDbFramework
|
|
154
187
|
return nil
|
155
188
|
end
|
156
189
|
|
190
|
+
def wait_timeout
|
191
|
+
Time.now + 900 #15 minutes
|
192
|
+
end
|
193
|
+
|
157
194
|
def wait_until_active(table_name)
|
158
195
|
|
159
|
-
end_time =
|
196
|
+
end_time = wait_timeout
|
160
197
|
while Time.now < end_time do
|
161
198
|
|
162
199
|
status = get_status(table_name)
|
@@ -168,13 +205,31 @@ module DynamoDbFramework
|
|
168
205
|
sleep(5)
|
169
206
|
end
|
170
207
|
|
171
|
-
raise "Timeout
|
208
|
+
raise "Timeout occurred while waiting for table: #{table_name}, to become active."
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
def wait_until_dropped(table_name)
|
213
|
+
|
214
|
+
end_time = wait_timeout
|
215
|
+
while Time.now < end_time do
|
216
|
+
|
217
|
+
status = get_status(table_name)
|
218
|
+
|
219
|
+
if status == nil
|
220
|
+
return
|
221
|
+
end
|
222
|
+
|
223
|
+
sleep(5)
|
224
|
+
end
|
225
|
+
|
226
|
+
raise "Timeout occurred while waiting for table: #{table_name}, to be dropped."
|
172
227
|
|
173
228
|
end
|
174
229
|
|
175
230
|
def wait_until_index_active(table_name, index_name)
|
176
231
|
|
177
|
-
end_time =
|
232
|
+
end_time = wait_timeout
|
178
233
|
while Time.now < end_time do
|
179
234
|
|
180
235
|
status = get_index_status(table_name, index_name)
|
@@ -186,13 +241,13 @@ module DynamoDbFramework
|
|
186
241
|
sleep(5)
|
187
242
|
end
|
188
243
|
|
189
|
-
raise "Timeout
|
244
|
+
raise "Timeout occurred while waiting for table: #{table_name}, index: #{index_name}, to become active."
|
190
245
|
|
191
246
|
end
|
192
247
|
|
193
248
|
def wait_until_index_dropped(table_name, index_name)
|
194
249
|
|
195
|
-
end_time =
|
250
|
+
end_time = wait_timeout
|
196
251
|
while Time.now < end_time do
|
197
252
|
|
198
253
|
status = get_index_status(table_name, index_name)
|
@@ -204,11 +259,29 @@ module DynamoDbFramework
|
|
204
259
|
sleep(5)
|
205
260
|
end
|
206
261
|
|
207
|
-
raise "Timeout
|
262
|
+
raise "Timeout occurred while waiting for table: #{table_name}, index: #{index_name}, to be dropped."
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
def wait_until_ttl_changed(table_name)
|
267
|
+
|
268
|
+
end_time = wait_timeout
|
269
|
+
while Time.now < end_time do
|
270
|
+
|
271
|
+
status = get_ttl_status(table_name)['time_to_live_status']
|
272
|
+
|
273
|
+
if status == 'ENABLED' || status == 'DISABLED'
|
274
|
+
return
|
275
|
+
end
|
276
|
+
|
277
|
+
sleep(5)
|
278
|
+
end
|
279
|
+
|
280
|
+
raise "Timeout occurred while waiting for table: #{table_name}, to update TTL status."
|
208
281
|
|
209
282
|
end
|
210
283
|
|
211
|
-
def create(table_name, attributes, partition_key, range_key = nil, read_capacity = 20, write_capacity = 10, global_indexes = nil)
|
284
|
+
def create(table_name, attributes, partition_key, range_key = nil, read_capacity = 20, write_capacity = 10, global_indexes = nil, billing_mode = 'PROVISIONED')
|
212
285
|
|
213
286
|
if exists?(table_name)
|
214
287
|
return
|
@@ -230,11 +303,17 @@ module DynamoDbFramework
|
|
230
303
|
:table_name => table_name,
|
231
304
|
:attribute_definitions => attribute_definitions,
|
232
305
|
:key_schema => key_schema,
|
306
|
+
:billing_mode => billing_mode
|
307
|
+
}
|
308
|
+
|
309
|
+
unless billing_mode == 'PAY_PER_REQUEST'
|
310
|
+
table = table.merge(
|
233
311
|
:provisioned_throughput => {
|
234
|
-
|
235
|
-
|
312
|
+
:read_capacity_units => read_capacity,
|
313
|
+
:write_capacity_units => write_capacity
|
236
314
|
}
|
237
|
-
|
315
|
+
)
|
316
|
+
end
|
238
317
|
|
239
318
|
if global_indexes != nil
|
240
319
|
table[:global_secondary_indexes] = global_indexes
|
@@ -289,17 +368,27 @@ module DynamoDbFramework
|
|
289
368
|
:table_name => table_name,
|
290
369
|
:attribute_definitions => attribute_definitions,
|
291
370
|
:key_schema => key_schema,
|
371
|
+
:billing_mode => options[:billing_mode] || 'PROVISIONED'
|
372
|
+
}
|
373
|
+
|
374
|
+
unless options[:billing_mode] == 'PAY_PER_REQUEST'
|
375
|
+
table = table.merge(
|
292
376
|
:provisioned_throughput => {
|
293
|
-
|
294
|
-
|
377
|
+
:read_capacity_units => options[:read_capacity],
|
378
|
+
:write_capacity_units => options[:write_capacity]
|
295
379
|
}
|
296
|
-
|
380
|
+
)
|
381
|
+
end
|
297
382
|
|
298
383
|
if options[:global_indexes] != nil
|
299
384
|
table[:global_secondary_indexes] = options[:global_indexes]
|
300
385
|
end
|
301
386
|
|
302
|
-
|
387
|
+
begin
|
388
|
+
dynamodb.client.create_table(table)
|
389
|
+
rescue Aws::DynamoDB::Errors::ResourceInUseException => e
|
390
|
+
DynamoDbFramework.logger.warn "[#{self.class}] - Table #{table_name} already exists!"
|
391
|
+
end
|
303
392
|
|
304
393
|
# wait for table to be created
|
305
394
|
DynamoDbFramework.logger.info "[#{self.class}] - Waiting for table: [#{table_name}] to be created."
|
@@ -307,7 +396,7 @@ module DynamoDbFramework
|
|
307
396
|
DynamoDbFramework.logger.info "[#{self.class}] - Table: [#{table_name}] created."
|
308
397
|
end
|
309
398
|
|
310
|
-
def create_global_index(name, partition_key, range_key = nil, read_capacity = 20, write_capacity = 10)
|
399
|
+
def create_global_index(name, partition_key, range_key = nil, read_capacity = 20, write_capacity = 10, billing_mode = 'PROVISIONED')
|
311
400
|
|
312
401
|
key_schema = []
|
313
402
|
|
@@ -321,13 +410,18 @@ module DynamoDbFramework
|
|
321
410
|
:key_schema => key_schema,
|
322
411
|
:projection => {
|
323
412
|
:projection_type => :ALL
|
324
|
-
},
|
325
|
-
:provisioned_throughput => {
|
326
|
-
:read_capacity_units => read_capacity,
|
327
|
-
:write_capacity_units => write_capacity,
|
328
413
|
}
|
329
414
|
}
|
330
415
|
|
416
|
+
if billing_mode == 'PROVISIONED'
|
417
|
+
index = index.merge(
|
418
|
+
:provisioned_throughput => {
|
419
|
+
:read_capacity_units => read_capacity,
|
420
|
+
:write_capacity_units => write_capacity,
|
421
|
+
}
|
422
|
+
)
|
423
|
+
end
|
424
|
+
|
331
425
|
return index
|
332
426
|
end
|
333
427
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/{dynamodb_table_manager_spec.rb → dynamodb_framework/dynamodb_table_manager_spec.rb}
RENAMED
@@ -117,6 +117,56 @@ RSpec.describe DynamoDbFramework::TableManager do
|
|
117
117
|
|
118
118
|
end
|
119
119
|
|
120
|
+
it 'can update the TTL attribute' do
|
121
|
+
|
122
|
+
exists = subject.exists?('update_ttl_test')
|
123
|
+
|
124
|
+
if exists
|
125
|
+
subject.drop('update_ttl_test')
|
126
|
+
end
|
127
|
+
|
128
|
+
builder = DynamoDbFramework::AttributesBuilder.new
|
129
|
+
builder.add(:ttl_date, :N)
|
130
|
+
|
131
|
+
subject.create('update_ttl_test', builder.attributes, :ttl_date)
|
132
|
+
|
133
|
+
subject.update_ttl_attribute('update_ttl_test', true, 'ttl_date')
|
134
|
+
|
135
|
+
expect(subject.get_ttl_status('update_ttl_test')['time_to_live_status']).to eq('ENABLED')
|
136
|
+
|
137
|
+
subject.drop('update_ttl_test')
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'can disable the TTL attribute' do
|
142
|
+
|
143
|
+
exists = subject.exists?('update_ttl_test')
|
144
|
+
|
145
|
+
if exists
|
146
|
+
subject.drop('update_ttl_test')
|
147
|
+
end
|
148
|
+
|
149
|
+
builder = DynamoDbFramework::AttributesBuilder.new
|
150
|
+
builder.add(:ttl_date, :N)
|
151
|
+
|
152
|
+
subject.create('update_ttl_test', builder.attributes, :ttl_date)
|
153
|
+
|
154
|
+
subject.update_ttl_attribute('update_ttl_test', true, 'ttl_date')
|
155
|
+
|
156
|
+
subject.update_ttl_attribute('update_ttl_test', false, 'ttl_date')
|
157
|
+
|
158
|
+
expect(subject.get_ttl_status('update_ttl_test')['time_to_live_status']).to eq('DISABLED')
|
159
|
+
|
160
|
+
subject.drop('update_ttl_test')
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'handles timeouts when dynamodb fails to respond' do
|
165
|
+
allow(subject).to receive('wait_timeout').and_return(Time.now)
|
166
|
+
|
167
|
+
expect{subject.wait_until_ttl_changed('update_ttl_test')}.to raise_error("Timeout occurred while waiting for table: update_ttl_test, to update TTL status.")
|
168
|
+
end
|
169
|
+
|
120
170
|
it 'can drop an existing global secondary index' do
|
121
171
|
|
122
172
|
exists = subject.exists?('drop_index_test')
|
@@ -22,6 +22,22 @@ RSpec.describe DynamoDbFramework::Table do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
context 'with an index specified' do
|
26
|
+
let(:table_name) { ExampleTable.config[:table_name] }
|
27
|
+
let(:index_name) { ExampleIndex.config[:index_name] }
|
28
|
+
before do
|
29
|
+
table_manager.drop(table_name)
|
30
|
+
table_manager.drop_index(table_name, index_name)
|
31
|
+
end
|
32
|
+
it 'should create the table and index' do
|
33
|
+
expect(table_manager.exists?(table_name)).to be false
|
34
|
+
expect(ExampleIndex.exists?(store: store)).to be false
|
35
|
+
ExampleTable.create(store: store, indexes: [ExampleIndex])
|
36
|
+
expect(table_manager.exists?(table_name)).to be true
|
37
|
+
expect(ExampleIndex.exists?(store: store)).to be true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
25
41
|
context 'without a range key' do
|
26
42
|
let(:table_name) { ExampleTableWithoutRangeKey.config[:table_name] }
|
27
43
|
before do
|
@@ -33,6 +49,19 @@ RSpec.describe DynamoDbFramework::Table do
|
|
33
49
|
expect(table_manager.exists?(table_name)).to be true
|
34
50
|
end
|
35
51
|
end
|
52
|
+
|
53
|
+
context 'when already exists' do
|
54
|
+
let(:table_name) { ExampleTableWithoutRangeKey.config[:table_name] }
|
55
|
+
before do
|
56
|
+
table_manager.drop(table_name)
|
57
|
+
ExampleTableWithoutRangeKey.create(store: store)
|
58
|
+
end
|
59
|
+
it 'should return without error' do
|
60
|
+
expect(table_manager.exists?(table_name)).to be true
|
61
|
+
expect { ExampleTableWithoutRangeKey.create(store: store) }.not_to raise_error
|
62
|
+
expect(table_manager.exists?(table_name)).to be true
|
63
|
+
end
|
64
|
+
end
|
36
65
|
end
|
37
66
|
context 'when an invalid table class calls the create method' do
|
38
67
|
context 'without a table_name specified' do
|
@@ -111,6 +140,29 @@ RSpec.describe DynamoDbFramework::Table do
|
|
111
140
|
end
|
112
141
|
end
|
113
142
|
|
143
|
+
describe '#wait_until_active' do
|
144
|
+
context 'when a table exists' do
|
145
|
+
let(:table_name) { ExampleTable.config[:table_name] }
|
146
|
+
before do
|
147
|
+
table_manager.drop(table_name)
|
148
|
+
ExampleTable.create(store: store)
|
149
|
+
end
|
150
|
+
it 'should not raise timeout error' do
|
151
|
+
expect { ExampleTable.wait_until_active(store: store) }.not_to raise_error
|
152
|
+
end
|
153
|
+
end
|
154
|
+
context 'when a table does NOT exist' do
|
155
|
+
let(:table_name) { ExampleTable.config[:table_name] }
|
156
|
+
before do
|
157
|
+
table_manager.drop(table_name)
|
158
|
+
allow_any_instance_of(DynamoDbFramework::TableManager).to receive(:wait_timeout).and_return(Time.now)
|
159
|
+
end
|
160
|
+
it 'should raise timeout error' do
|
161
|
+
expect { ExampleTable.wait_until_active(store: store) }.to raise_error
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
114
166
|
describe '#query' do
|
115
167
|
|
116
168
|
let(:repository) do
|
File without changes
|
data/spec/example_index.rb
CHANGED
@@ -30,7 +30,7 @@ class ExampleIndexWithoutPartitionKey
|
|
30
30
|
extend DynamoDbFramework::Index
|
31
31
|
|
32
32
|
table ExampleTable
|
33
|
-
index_name 'example_index'
|
33
|
+
index_name 'example_index.without.partition'
|
34
34
|
range_key :id, :S
|
35
35
|
|
36
36
|
end
|
@@ -38,7 +38,7 @@ end
|
|
38
38
|
class ExampleIndexWithoutRangeKey
|
39
39
|
extend DynamoDbFramework::Index
|
40
40
|
|
41
|
-
index_name 'example_index'
|
41
|
+
index_name 'example_index.without.range'
|
42
42
|
table ExampleTable
|
43
43
|
partition_key :name, :S
|
44
44
|
|
data/spec/example_table.rb
CHANGED
@@ -27,7 +27,7 @@ end
|
|
27
27
|
class ExampleTableWithoutPartitionKey
|
28
28
|
extend DynamoDbFramework::Table
|
29
29
|
|
30
|
-
table_name 'example'
|
30
|
+
table_name 'example.without.partition'
|
31
31
|
range_key :timestamp, :N
|
32
32
|
|
33
33
|
end
|
@@ -35,7 +35,7 @@ end
|
|
35
35
|
class ExampleTableWithoutRangeKey
|
36
36
|
extend DynamoDbFramework::Table
|
37
37
|
|
38
|
-
table_name 'example'
|
38
|
+
table_name 'example.without.range'
|
39
39
|
partition_key :id, :S
|
40
40
|
|
41
41
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter '/spec/'
|
4
|
+
end
|
5
|
+
|
1
6
|
require "rubygems"
|
2
7
|
require "bundler"
|
3
8
|
require 'aws-sdk-core'
|
@@ -9,12 +14,7 @@ require_relative '../spec/example_table'
|
|
9
14
|
require_relative '../spec/example_index'
|
10
15
|
require 'pry'
|
11
16
|
|
12
|
-
|
13
|
-
SimpleCov.start do
|
14
|
-
add_filter '/spec/'
|
15
|
-
end
|
16
|
-
|
17
|
-
DYNAMODB_STORE_ENDPOINT = 'http://dynamodb:8000'
|
17
|
+
DYNAMODB_STORE_ENDPOINT = ENV.fetch('DYNAMODB_ENDPOINT', 'http://localhost:8000')
|
18
18
|
|
19
19
|
Aws.config[:credentials] = Aws::Credentials.new('test_key', 'test_secret')
|
20
20
|
Aws.config[:region] = 'eu-west-1'
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamodb_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonsage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.6'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.6'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: json
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,20 +98,20 @@ dependencies:
|
|
98
98
|
name: aws-sdk-core
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '2.10'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '2.10'
|
111
111
|
description: A lightweight framework to provide managers for working with aws dynamodb
|
112
112
|
(incuding local version).
|
113
113
|
email:
|
114
|
-
-
|
114
|
+
- vaughan.britton@sage.com
|
115
115
|
executables: []
|
116
116
|
extensions: []
|
117
117
|
extra_rdoc_files: []
|
@@ -132,16 +132,16 @@ files:
|
|
132
132
|
- lib/dynamodb_framework/dynamodb_table_manager.rb
|
133
133
|
- lib/dynamodb_framework/hash_helper.rb
|
134
134
|
- lib/dynamodb_framework/version.rb
|
135
|
-
- spec/dynamodb_index_spec.rb
|
136
|
-
- spec/dynamodb_migration_manager_spec.rb
|
137
|
-
- spec/dynamodb_namespace_migration_manager_spec.rb
|
138
|
-
- spec/dynamodb_query_spec.rb
|
139
|
-
- spec/dynamodb_repository_spec.rb
|
140
|
-
- spec/dynamodb_table_manager_spec.rb
|
141
|
-
- spec/dynamodb_table_spec.rb
|
135
|
+
- spec/dynamodb_framework/dynamodb_index_spec.rb
|
136
|
+
- spec/dynamodb_framework/dynamodb_migration_manager_spec.rb
|
137
|
+
- spec/dynamodb_framework/dynamodb_namespace_migration_manager_spec.rb
|
138
|
+
- spec/dynamodb_framework/dynamodb_query_spec.rb
|
139
|
+
- spec/dynamodb_framework/dynamodb_repository_spec.rb
|
140
|
+
- spec/dynamodb_framework/dynamodb_table_manager_spec.rb
|
141
|
+
- spec/dynamodb_framework/dynamodb_table_spec.rb
|
142
|
+
- spec/dynamodb_framework/hash_helper_spec.rb
|
142
143
|
- spec/example_index.rb
|
143
144
|
- spec/example_table.rb
|
144
|
-
- spec/hash_helper_spec.rb
|
145
145
|
- spec/spec_helper.rb
|
146
146
|
- spec/test_item.rb
|
147
147
|
- spec/test_migration_script1.rb
|
@@ -165,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
|
-
|
169
|
-
rubygems_version: 2.5.1
|
168
|
+
rubygems_version: 3.0.8
|
170
169
|
signing_key:
|
171
170
|
specification_version: 4
|
172
171
|
summary: A lightweight framework to provide managers for working with aws dynamodb
|