dynomite 1.2.5 → 1.2.6
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/.gitignore +1 -0
- data/CHANGELOG.md +3 -0
- data/README.md +13 -7
- data/docs/migrations/long-example.rb +5 -1
- data/lib/dynomite/migration/dsl.rb +25 -5
- data/lib/dynomite/migration/generator.rb +1 -1
- data/lib/dynomite/migration/templates/create_table.rb +1 -0
- data/lib/dynomite/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f80bf11d2121217d52d8ceac89defcd4e738b3ff220847f7421b1337fbc104f
|
4
|
+
data.tar.gz: cd1a4fb8c66678458c8e08b3222064ea3153129f31d1a81ff7ee6d25f1ac3928
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 890d2960cd53cec65a93b81b31fb61da535f123f4718d5e870eb2983813811352e2bbf93043007389ee85224590e2484ec0f2b0c5f377b384c5cf886923a87fd
|
7
|
+
data.tar.gz: 1e2ab49bfc684afe96927971d2a57544b9d4898bb1271b920b88969e267b79f5271c4bf71ed07f45b4b160c5f27ef7ff943250c62e42eb1ce1c1c81d720e78ab
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
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.2.6]
|
7
|
+
- Implement the `PAY_PER_USE` billing mode for table creations and updates. See [DynamoDB On Demand](https://aws.amazon.com/blogs/aws/amazon-dynamodb-on-demand-no-capacity-planning-and-pay-per-request-pricing/).
|
8
|
+
|
6
9
|
## [1.2.5]
|
7
10
|
- use correct color method
|
8
11
|
|
data/README.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
# Dynomite
|
2
2
|
|
3
|
+
[](https://www.boltops.com)
|
4
|
+
|
3
5
|
NOTE: Am looking for maintainers to help with this gem. Send me an email! Also [dynamoid](https://github.com/Dynamoid/dynamoid) seems like a good option that should be considered delegating to or straight using. Learning on delegation so we can have better default behavior for a DynamoDB model layer for Jets.
|
4
6
|
|
5
7
|
A simple wrapper library to make DynamoDB usage a little more friendly. The modeling is ActiveRecord-ish but not exactly because DynamoDB is a different type of database. Examples below explain it best:
|
6
8
|
|
9
|
+
## Jets Docs
|
10
|
+
|
11
|
+
* [Database DynamoDB](https://rubyonjets.com/docs/database/dynamodb/)
|
12
|
+
|
7
13
|
## Examples
|
8
14
|
|
9
15
|
First define a class:
|
@@ -11,7 +17,7 @@ First define a class:
|
|
11
17
|
```ruby
|
12
18
|
class Post < Dynomite::Item
|
13
19
|
# partition_key "id" # optional, defaults to id
|
14
|
-
|
20
|
+
|
15
21
|
column :id, :title, :desc
|
16
22
|
end
|
17
23
|
```
|
@@ -21,7 +27,7 @@ end
|
|
21
27
|
```ruby
|
22
28
|
post = Post.new
|
23
29
|
post = post.replace(title: "test title")
|
24
|
-
post.attrs # {"id" => "generated-id", title" => "
|
30
|
+
post.attrs # {"id" => "generated-id", title" => "test title"}
|
25
31
|
```
|
26
32
|
|
27
33
|
`post.attrs[:id]` now contain a generated unique partition_key id. Usually the partition_key is 'id'. You can set your own unique id also by specifying id.
|
@@ -112,7 +118,7 @@ post.replace
|
|
112
118
|
|
113
119
|
puts post.id # 1962DE7D852298C5CDC809C0FEF50D8262CEDF09
|
114
120
|
puts post.name # "My First Post"
|
115
|
-
```
|
121
|
+
```
|
116
122
|
|
117
123
|
Note that any column not defined using the `column` method can still be accessed using the `attrs`
|
118
124
|
method.
|
@@ -125,15 +131,15 @@ Just add `include ActiveModel::Validations` at the top of your item class.
|
|
125
131
|
```ruby
|
126
132
|
class Post < Dynomite::Item
|
127
133
|
include ActiveModel::Validations
|
128
|
-
|
134
|
+
|
129
135
|
column :id, :name # needed
|
130
|
-
|
136
|
+
|
131
137
|
validates :id, presence: true
|
132
138
|
validates :name, presence: true
|
133
139
|
end
|
134
|
-
```
|
140
|
+
```
|
135
141
|
|
136
|
-
**Be sure to define all validated columns using `column` method**.
|
142
|
+
**Be sure to define all validated columns using `column` method**.
|
137
143
|
|
138
144
|
Validations are executed by default as soon as you call the `replace` method, returning `false` on
|
139
145
|
failure. It also can be ran manually using the `valid?` method just like with ActiveRecord models.
|
@@ -55,6 +55,9 @@ class CreateCommentsMigration < Dynomite::Migration
|
|
55
55
|
# read_capacity_units: 5,
|
56
56
|
# write_capacity_units: 5
|
57
57
|
# )
|
58
|
+
|
59
|
+
# set the billing mode to on-demand (NOTE: this overrides provisioned_throughput)
|
60
|
+
# t.billing_mode(:pay_per_use)
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
@@ -62,6 +65,8 @@ end
|
|
62
65
|
class UpdateCommentsMigration < Dynomite::Migration
|
63
66
|
def up
|
64
67
|
update_table :comments do |t|
|
68
|
+
# You can update from provisioned_throughput to on-demand pricing
|
69
|
+
# t.billing_mode(:pay_per_use)
|
65
70
|
|
66
71
|
# t.global_secondary_index do
|
67
72
|
# t.gsi(METHOD, INDEX_NAME) do
|
@@ -120,4 +125,3 @@ class UpdateCommentsMigration < Dynomite::Migration
|
|
120
125
|
end
|
121
126
|
end
|
122
127
|
end
|
123
|
-
|
@@ -1,5 +1,12 @@
|
|
1
1
|
class Dynomite::Migration
|
2
2
|
class Dsl
|
3
|
+
ATTRIBUTES = %i[
|
4
|
+
key_schema
|
5
|
+
attribute_definitions
|
6
|
+
table_name
|
7
|
+
billing_mode
|
8
|
+
].freeze
|
9
|
+
|
3
10
|
autoload :Common, "dynomite/migration/common"
|
4
11
|
autoload :BaseSecondaryIndex, "dynomite/migration/dsl/base_secondary_index"
|
5
12
|
autoload :LocalSecondaryIndex, "dynomite/migration/dsl/local_secondary_index"
|
@@ -8,15 +15,16 @@ class Dynomite::Migration
|
|
8
15
|
include Dynomite::DbConfig
|
9
16
|
include Common
|
10
17
|
|
11
|
-
attr_accessor
|
12
|
-
|
18
|
+
attr_accessor(*ATTRIBUTES)
|
19
|
+
|
13
20
|
def initialize(method_name, table_name, &block)
|
14
21
|
@method_name = method_name
|
15
22
|
@table_name = table_name
|
16
23
|
@block = block
|
17
24
|
|
18
|
-
# Dsl fills in
|
25
|
+
# Dsl fills in attributes in as methods are called within the block.
|
19
26
|
# Attributes for both create_table and updated_table:
|
27
|
+
@billing_mode = 'PROVISIONED'
|
20
28
|
@attribute_definitions = []
|
21
29
|
@provisioned_throughput = {
|
22
30
|
read_capacity_units: 5,
|
@@ -31,6 +39,14 @@ class Dynomite::Migration
|
|
31
39
|
@lsi_indexes = []
|
32
40
|
end
|
33
41
|
|
42
|
+
# t.billing_mode(:pay_per_request)
|
43
|
+
# t.billing_mode(:provisioned) # default value
|
44
|
+
def billing_mode(mode = nil)
|
45
|
+
return @billing_mode if mode.nil?
|
46
|
+
|
47
|
+
@billing_mode = mode.to_s.upcase
|
48
|
+
end
|
49
|
+
|
34
50
|
# t.gsi(:create) do |i|
|
35
51
|
# i.partition_key "category:string"
|
36
52
|
# i.sort_key "created_at:string" # optional
|
@@ -81,9 +97,10 @@ class Dynomite::Migration
|
|
81
97
|
table_name: namespaced_table_name,
|
82
98
|
key_schema: @key_schema,
|
83
99
|
attribute_definitions: @attribute_definitions,
|
84
|
-
|
100
|
+
billing_mode: @billing_mode
|
85
101
|
}
|
86
102
|
|
103
|
+
params[:provisioned_throughput] = @provisioned_throughput if @billing_mode == 'PROVISIONED'
|
87
104
|
params[:local_secondary_indexes] = lsi_secondary_index_creates unless @lsi_indexes.empty?
|
88
105
|
params[:global_secondary_indexes] = gsi_secondary_index_creates unless @gsi_indexes.empty?
|
89
106
|
params
|
@@ -95,12 +112,15 @@ class Dynomite::Migration
|
|
95
112
|
params = {
|
96
113
|
table_name: namespaced_table_name,
|
97
114
|
attribute_definitions: @attribute_definitions,
|
115
|
+
billing_mode: @billing_mode
|
98
116
|
# update table take values only some values for the "parent" table
|
99
117
|
# no key_schema, update_table does not handle key_schema for the "parent" table
|
100
118
|
}
|
101
119
|
# only set "parent" table provisioned_throughput if user actually invoked
|
102
120
|
# it in the dsl
|
103
|
-
|
121
|
+
if @provisioned_throughput_set_called && @billing_mode == 'PROVISIONED'
|
122
|
+
params[:provisioned_throughput] = @provisioned_throughput
|
123
|
+
end
|
104
124
|
params[:global_secondary_index_updates] = global_secondary_index_updates
|
105
125
|
params
|
106
126
|
end
|
@@ -31,7 +31,7 @@ class Dynomite::Migration
|
|
31
31
|
table_name: table_name,
|
32
32
|
partition_key: @options[:partition_key],
|
33
33
|
sort_key: @options[:sort_key],
|
34
|
-
provisioned_throughput: @options[:provisioned_throughput] || 5
|
34
|
+
provisioned_throughput: @options[:provisioned_throughput] || 5
|
35
35
|
)
|
36
36
|
end
|
37
37
|
|
@@ -5,6 +5,7 @@ class <%= @migration_class_name %> < Dynomite::Migration
|
|
5
5
|
<% if @sort_key # so extra spaces are not added when generated -%>
|
6
6
|
t.sort_key "<%= @sort_key %>" # optional
|
7
7
|
<% end -%>
|
8
|
+
t.billing_mode(:PROVISIONED)
|
8
9
|
t.provisioned_throughput(<%= @provisioned_throughput %>) # sets both read and write, defaults to 5 when not set
|
9
10
|
|
10
11
|
# Instead of using partition_key and sort_key you can set the
|
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.2.
|
4
|
+
version: 1.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
- !ruby/object:Gem::Version
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
152
|
+
rubygems_version: 3.1.2
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: ActiveRecord-ish Dynamodb Model
|