dyna 0.2.0 → 0.2.1.beta1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4c57e85bcc9f5bce4b084da7b9c6c7338529d1b83512b1549bc31f47d48bc1e
4
- data.tar.gz: 5a14ba531ff8a96bb56ccd09af7db82d8c9e6a3024f3051be520203a890d382e
3
+ metadata.gz: 669330ed5cbadd2aea1b3e817c75ba8722b4f748263e46f2fd34646f0f845077
4
+ data.tar.gz: 6c7328927257bb47470f73d0ea1321f862d51e78b288c63cb116adb5e9255e42
5
5
  SHA512:
6
- metadata.gz: cf9547e5373b6b690623732de1c70a2efce0128863f53a92a1cbffcc7539ca5294299a993ecf587af339a1fce3fd7ef3f549e5f4313e3b3283003ccb9a54f28c
7
- data.tar.gz: cbefd166bad5e80202ef3d0f9e5f73da90642fbb0dbce0e6a1c406e85143cae539fc0f7464c0240c88d6c31a21c1f1f6c3c6d4d2d654e069342243c14c7a0d67
6
+ metadata.gz: 33231b298694a199242a453677490991888e52bf34e4e117224c052a00a014b0858b9105affa7bc1ebd8d14d93345fa226bef4eb7e1e555205ec54bdc7679396
7
+ data.tar.gz: b196f73160cc775568cf8ee6b75973ebeea8d65629312bf14566c2502ba9e72f11ce8f70059ba85d0a4cc91071dfa1841cbc7cd87635f6a891095df58dedf0bb
data/README.md CHANGED
@@ -74,6 +74,11 @@ dynamo_db "ap-northeast-1" do
74
74
  attribute_type: "S",
75
75
  )
76
76
 
77
+ time_to_live_specification(
78
+ enabled: true,
79
+ attribute_name: "ttl",
80
+ )
81
+
77
82
  provisioned_throughput(
78
83
  read_capacity_units: 1,
79
84
  write_capacity_units: 2,
@@ -13,6 +13,10 @@ module Dyna
13
13
  :table_name => table_name,
14
14
  :scalable_targets => [],
15
15
  :scaling_policies => [],
16
+ :time_to_live_specification => {
17
+ enabled: false,
18
+ attribute_name: nil,
19
+ }
16
20
  })
17
21
  instance_eval(&block)
18
22
  end
@@ -100,6 +104,13 @@ module Dyna
100
104
  }
101
105
  end
102
106
 
107
+ def time_to_live_specification(enabled:, attribute_name:)
108
+ @result.time_to_live_specification = {
109
+ enabled: enabled,
110
+ attribute_name: attribute_name,
111
+ }
112
+ end
113
+
103
114
  class LocalSecondaryIndex
104
115
  attr_accessor :result
105
116
 
data/lib/dyna/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dyna
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1.beta1'
3
3
  end
@@ -23,6 +23,7 @@ module Dyna
23
23
  params = dsl.symbolize_keys
24
24
  params.delete(:scalable_targets)
25
25
  params.delete(:scaling_policies)
26
+ params.delete(:time_to_live_specification)
26
27
  result = @ddb.create_table(params)
27
28
  @options.updated = true
28
29
  result
@@ -31,6 +31,9 @@ module Dyna
31
31
  wait_until_table_is_active
32
32
  update_stream_specification(dsl_stream_specification(dsl))
33
33
  end
34
+ unless time_to_live_eql?(dsl)
35
+ update_time_to_live(dsl)
36
+ end
34
37
  unless auto_scaling_eql?(dsl)
35
38
  update_auto_scaling(dsl)
36
39
  end
@@ -65,6 +68,23 @@ module Dyna
65
68
  end
66
69
 
67
70
  private
71
+
72
+ def aws_time_to_live
73
+ @ttl ||= @ddb.describe_time_to_live(table_name: @table.table_name).time_to_live_description
74
+ end
75
+
76
+ def time_to_live_eql?(dsl)
77
+ wait_until_table_is_active
78
+ ttl = aws_time_to_live
79
+ unless %w/ENABLED DISABLED/.include?(ttl.time_to_live_status)
80
+ raise "time to live status is #{ttl.time_to_live_status} and must be ENABLED or DISABLED to apply"
81
+ end
82
+ same_status = dsl.time_to_live_specification.enabled.to_s == 'false' && ttl.time_to_live_status == 'DISABLED' || dsl.time_to_live_specification.enabled.to_s == 'true' && ttl.time_to_live_status == 'ENABLED'
83
+ same_name = dsl.time_to_live_specification.attribute_name.to_s == ttl.attribute_name
84
+
85
+ same_status && same_name
86
+ end
87
+
68
88
  def auto_scaling_eql?(dsl)
69
89
  scalable_targets_eql?(dsl) && scaling_policies_eql?(dsl)
70
90
  end
@@ -302,6 +322,31 @@ module Dyna
302
322
  @options.updated = true
303
323
  end
304
324
  end
325
+
326
+ def update_time_to_live(dsl)
327
+ params = { table_name: @table.table_name }
328
+ if dsl.time_to_live_specification.enabled.to_s == 'true'
329
+ params[:time_to_live_specification] = {
330
+ enabled: dsl.time_to_live_specification.enabled,
331
+ attribute_name: dsl.time_to_live_specification.attribute_name,
332
+ }
333
+ else
334
+ params[:time_to_live_specification] = {
335
+ enabled: false,
336
+ attribute_name: aws_time_to_live.attribute_name,
337
+ }
338
+ end
339
+
340
+ log(:info, " table: #{@table.table_name}(update time to live)".green, false)
341
+ log(:info, " => enabled: #{params[:time_to_live_specification][:enabled]}".cyan, false)
342
+ log(:info, " => attribute_name: #{params[:time_to_live_specification][:attribute_name]}".cyan, false)
343
+
344
+ unless @options.dry_run
345
+ log(:debug, params, false)
346
+ @ddb.update_time_to_live(params)
347
+ @options.updated = true
348
+ end
349
+ end
305
350
  end
306
351
  end
307
352
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - wata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -183,9 +183,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
- - - ">="
186
+ - - ">"
187
187
  - !ruby/object:Gem::Version
188
- version: '0'
188
+ version: 1.3.1
189
189
  requirements: []
190
190
  rubyforge_project:
191
191
  rubygems_version: 2.7.6