dynomite 1.0.9 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/docs/migrations/short-example.rb +13 -9
- data/lib/dynomite/migration/dsl.rb +48 -26
- data/lib/dynomite/migration/dsl/base_secondary_index.rb +2 -1
- data/lib/dynomite/migration/executor.rb +9 -1
- data/lib/dynomite/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b15b33b315b312ab9d3b277d49b91601a2a873de2f381a2cc12085b30f784df0
|
4
|
+
data.tar.gz: 46636c01df3e78e6470e01b81fb829e1a379d3193dd276b0905ebd1af36ff94d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50bc0730c3dad8654ae6323c98984e8c492d8d3bbccd9bf119ca1454ed50e9f4d183f51a822143e2e0bfa88902807d3d52497f913b736c0f126a748d065c0713
|
7
|
+
data.tar.gz: f54b0f900e63317ea9dfc9cc68ef6ccda244939f146497d5d783dcf1abc24526b7da0334dbcc67fd5d05a8c0cdd167b324e4b247c6cfe447a9d8faf83dfddb12
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [1.1.0]
|
7
|
+
- Merge pull request #5 from tongueroo/fix-index-creation
|
8
|
+
- fix index creation dsl among other things
|
9
|
+
|
6
10
|
## [1.0.9]
|
7
11
|
- allow item.replace(hash) to work
|
8
12
|
- Merge pull request #3 from mveer99/patch-1 Update comments: Fixed typo in project_name
|
@@ -3,14 +3,19 @@ class CreateCommentsMigration < Dynomite::Migration
|
|
3
3
|
create_table :comments do |t|
|
4
4
|
t.partition_key "post_id:string" # required
|
5
5
|
t.sort_key "created_at:string" # optional
|
6
|
-
t.provisioned_throughput(
|
6
|
+
t.provisioned_throughput(1) # sets both read and write, defaults to 5 when not set
|
7
7
|
|
8
8
|
t.lsi do |i|
|
9
|
-
i.partition_key "
|
10
|
-
i.sort_key "updated_at:string" #
|
11
|
-
|
12
|
-
i.provisioned_throughput(10)
|
9
|
+
i.partition_key "post_id:string"
|
10
|
+
i.sort_key "updated_at:string" # required for lsi
|
11
|
+
i.provisioned_throughput(2)
|
13
12
|
end
|
13
|
+
|
14
|
+
# t.gsi do |i|
|
15
|
+
# i.partition_key "post_id:string"
|
16
|
+
# i.sort_key "deleted_at:string" # optional for gsi
|
17
|
+
# i.provisioned_throughput(2)
|
18
|
+
# end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -20,13 +25,12 @@ class UpdateCommentsMigration < Dynomite::Migration
|
|
20
25
|
update_table :comments do |t|
|
21
26
|
t.gsi(:create) do |i|
|
22
27
|
i.partition_key "post_id:string"
|
23
|
-
i.sort_key "
|
24
|
-
|
25
|
-
i.provisioned_throughput(10)
|
28
|
+
i.sort_key "flagged_at:string" # optional for gsi
|
29
|
+
i.provisioned_throughput(3)
|
26
30
|
end
|
27
31
|
|
28
32
|
t.gsi(:update, "update-me-index") do |i|
|
29
|
-
i.provisioned_throughput(
|
33
|
+
i.provisioned_throughput(5)
|
30
34
|
end
|
31
35
|
|
32
36
|
t.gsi(:delete, "delete-me-index")
|
@@ -35,7 +35,7 @@ class Dynomite::Migration
|
|
35
35
|
# i.partition_key = "category:string"
|
36
36
|
# i.sort_key = "created_at:string" # optional
|
37
37
|
# end
|
38
|
-
def gsi(action, index_name=nil, &block)
|
38
|
+
def gsi(action=:create, index_name=nil, &block)
|
39
39
|
gsi_index = GlobalSecondaryIndex.new(action, index_name, &block)
|
40
40
|
@gsi_indexes << gsi_index # store @gsi_index for the parent Dsl to use
|
41
41
|
end
|
@@ -50,7 +50,7 @@ class Dynomite::Migration
|
|
50
50
|
lsi_index = LocalSecondaryIndex.new(index_name, &block)
|
51
51
|
@lsi_indexes << lsi_index # store @lsi_index for the parent Dsl to use
|
52
52
|
end
|
53
|
-
alias_method :local_secondary_index, :
|
53
|
+
alias_method :local_secondary_index, :lsi
|
54
54
|
|
55
55
|
def evaluate
|
56
56
|
return if @evaluated
|
@@ -74,6 +74,9 @@ class Dynomite::Migration
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def params_create_table
|
77
|
+
merge_lsi_attribute_definitions!
|
78
|
+
merge_gsi_attribute_definitions!
|
79
|
+
|
77
80
|
params = {
|
78
81
|
table_name: namespaced_table_name,
|
79
82
|
key_schema: @key_schema,
|
@@ -81,14 +84,31 @@ class Dynomite::Migration
|
|
81
84
|
provisioned_throughput: @provisioned_throughput
|
82
85
|
}
|
83
86
|
|
84
|
-
params[:
|
87
|
+
params[:local_secondary_indexes] = lsi_secondary_index_creates unless @lsi_indexes.empty?
|
88
|
+
params[:global_secondary_indexes] = gsi_secondary_index_creates unless @gsi_indexes.empty?
|
89
|
+
params
|
90
|
+
end
|
91
|
+
|
92
|
+
def params_update_table
|
93
|
+
merge_gsi_attribute_definitions!
|
94
|
+
|
95
|
+
params = {
|
96
|
+
table_name: namespaced_table_name,
|
97
|
+
attribute_definitions: @attribute_definitions,
|
98
|
+
# update table take values only some values for the "parent" table
|
99
|
+
# no key_schema, update_table does not handle key_schema for the "parent" table
|
100
|
+
}
|
101
|
+
# only set "parent" table provisioned_throughput if user actually invoked
|
102
|
+
# it in the dsl
|
103
|
+
params[:provisioned_throughput] = @provisioned_throughput if @provisioned_throughput_set_called
|
104
|
+
params[:global_secondary_index_updates] = global_secondary_index_updates
|
85
105
|
params
|
86
106
|
end
|
87
107
|
|
88
108
|
# Goes thorugh all the lsi_indexes that have been built up in memory.
|
89
109
|
# Find the lsi object that creates an index and then grab the
|
90
110
|
# attribute_definitions from it.
|
91
|
-
def
|
111
|
+
def merge_lsi_attribute_definitions!
|
92
112
|
lsi = @lsi_indexes.first # DynamoDB only supports adding one index at a time anyway. The reason @lsi_indexes is an Array is because we're sharing the same class code for LSI and GSI
|
93
113
|
if lsi
|
94
114
|
lsi.evaluate # force early evaluate since we need the params to
|
@@ -100,7 +120,7 @@ class Dynomite::Migration
|
|
100
120
|
else
|
101
121
|
@attribute_definitions
|
102
122
|
end
|
103
|
-
all_attrs.uniq
|
123
|
+
@attribute_definitions = all_attrs.uniq
|
104
124
|
end
|
105
125
|
|
106
126
|
# maps each lsi to the hash structure expected by dynamodb update_table
|
@@ -111,40 +131,42 @@ class Dynomite::Migration
|
|
111
131
|
# { delete: {...} }
|
112
132
|
def lsi_secondary_index_creates
|
113
133
|
@lsi_indexes.map do |lsi|
|
114
|
-
|
134
|
+
lsi.params
|
115
135
|
end
|
116
136
|
end
|
117
137
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
params[:global_secondary_index_updates] = global_secondary_index_updates
|
129
|
-
params
|
138
|
+
# maps each lsi to the hash structure expected by dynamodb update_table
|
139
|
+
# under the global_secondary_index_updates key:
|
140
|
+
#
|
141
|
+
# { create: {...} }
|
142
|
+
# { update: {...} }
|
143
|
+
# { delete: {...} }
|
144
|
+
def gsi_secondary_index_creates
|
145
|
+
@gsi_indexes.map do |gsi|
|
146
|
+
gsi.params
|
147
|
+
end
|
130
148
|
end
|
131
149
|
|
132
150
|
# Goes thorugh all the gsi_indexes that have been built up in memory.
|
133
151
|
# Find the gsi object that creates an index and then grab the
|
134
152
|
# attribute_definitions from it.
|
135
|
-
def
|
136
|
-
|
153
|
+
def merge_gsi_attribute_definitions!
|
154
|
+
gsi_attrs = []
|
155
|
+
|
156
|
+
gsi = @gsi_indexes.find { |i| i.action == :create }
|
137
157
|
if gsi
|
138
158
|
gsi.evaluate # force early evaluate since we need the params to
|
139
159
|
# add: gsi_attribute_definitions + gsi_attrs
|
140
160
|
gsi_attrs = gsi.attribute_definitions
|
141
161
|
end
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
162
|
+
|
163
|
+
# Merge existing attributes for update table
|
164
|
+
all_gsi_attrs = @method_name == :update_table ?
|
165
|
+
gsi_attribute_definitions + gsi_attrs :
|
166
|
+
gsi_attrs
|
167
|
+
|
168
|
+
all_attrs = (@attribute_definitions + all_gsi_attrs).uniq
|
169
|
+
@attribute_definitions = all_attrs
|
148
170
|
end
|
149
171
|
|
150
172
|
# maps each gsi to the hash structure expected by dynamodb update_table
|
@@ -62,7 +62,8 @@ class Dynomite::Migration::Dsl
|
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
65
|
-
if [:create, :update].include?(@action)
|
65
|
+
if self.is_a?(GlobalSecondaryIndex) && [:create, :update].include?(@action)
|
66
|
+
# provisioned_throughput is required for gsi index definition
|
66
67
|
params[:provisioned_throughput] = @provisioned_throughput
|
67
68
|
end
|
68
69
|
|
@@ -19,11 +19,19 @@ class Dynomite::Migration
|
|
19
19
|
# Examples:
|
20
20
|
# result = db.create_table(@params)
|
21
21
|
# result = db.update_table(@params)
|
22
|
+
|
23
|
+
# Leaving this verbose output in here until this DSL is more hardened to help debug
|
24
|
+
unless ENV['DYNOMITE_ENV'] == 'test'
|
25
|
+
puts "Calling #{@method_name} with params:"
|
26
|
+
pp @params
|
27
|
+
end
|
28
|
+
|
29
|
+
return if ENV['DYNOMITE_DRY'] # dry run flag
|
22
30
|
result = db.send(@method_name, @params)
|
23
31
|
|
24
32
|
puts "DynamoDB Table: #{@table_name} Status: #{result.table_description.table_status}"
|
25
33
|
rescue Aws::DynamoDB::Errors::ServiceError => error
|
26
|
-
puts "Unable to #{@method_name.to_s.gsub('_',' ')}: #{error.message}"
|
34
|
+
puts "Unable to #{@method_name.to_s.gsub('_',' ')}: #{error.message}".colorize(:red)
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
data/lib/dynomite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynomite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|