dynomite 1.2.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -2
- data/CHANGELOG.md +18 -0
- data/Gemfile +1 -5
- data/LICENSE.txt +22 -0
- data/README.md +6 -190
- data/Rakefile +13 -1
- data/dynomite.gemspec +9 -2
- data/exe/dynomite +14 -0
- data/lib/dynomite/associations/association.rb +126 -0
- data/lib/dynomite/associations/belongs_to.rb +35 -0
- data/lib/dynomite/associations/has_and_belongs_to_many.rb +19 -0
- data/lib/dynomite/associations/has_many.rb +19 -0
- data/lib/dynomite/associations/has_one.rb +19 -0
- data/lib/dynomite/associations/many_association.rb +257 -0
- data/lib/dynomite/associations/single_association.rb +157 -0
- data/lib/dynomite/associations.rb +248 -0
- data/lib/dynomite/autoloader.rb +25 -0
- data/lib/dynomite/cli.rb +48 -0
- data/lib/dynomite/client.rb +118 -0
- data/lib/dynomite/command.rb +89 -0
- data/lib/dynomite/completer/script.rb +6 -0
- data/lib/dynomite/completer/script.sh +10 -0
- data/lib/dynomite/completer.rb +159 -0
- data/lib/dynomite/config.rb +39 -0
- data/lib/dynomite/core.rb +18 -19
- data/lib/dynomite/engine.rb +45 -0
- data/lib/dynomite/erb.rb +5 -3
- data/lib/dynomite/error.rb +12 -0
- data/lib/dynomite/help/completion.md +20 -0
- data/lib/dynomite/help/completion_script.md +3 -0
- data/lib/dynomite/help/migrate.md +3 -0
- data/lib/dynomite/help.rb +9 -0
- data/lib/dynomite/install.rb +4 -0
- data/lib/dynomite/item/abstract.rb +15 -0
- data/lib/dynomite/item/components.rb +33 -0
- data/lib/dynomite/item/dsl.rb +101 -0
- data/lib/dynomite/item/id.rb +41 -0
- data/lib/dynomite/item/indexes/finder.rb +58 -0
- data/lib/dynomite/item/indexes/index.rb +21 -0
- data/lib/dynomite/item/indexes/primary_index.rb +18 -0
- data/lib/dynomite/item/indexes.rb +25 -0
- data/lib/dynomite/item/locking.rb +53 -0
- data/lib/dynomite/item/magic_fields.rb +66 -0
- data/lib/dynomite/item/primary_key.rb +85 -0
- data/lib/dynomite/item/query/delegates.rb +28 -0
- data/lib/dynomite/item/query/params/base.rb +42 -0
- data/lib/dynomite/item/query/params/expression_attribute.rb +79 -0
- data/lib/dynomite/item/query/params/filter.rb +41 -0
- data/lib/dynomite/item/query/params/function/attribute_exists.rb +21 -0
- data/lib/dynomite/item/query/params/function/attribute_type.rb +30 -0
- data/lib/dynomite/item/query/params/function/base.rb +33 -0
- data/lib/dynomite/item/query/params/function/begins_with.rb +32 -0
- data/lib/dynomite/item/query/params/function/contains.rb +7 -0
- data/lib/dynomite/item/query/params/function/size_fn.rb +37 -0
- data/lib/dynomite/item/query/params/helpers.rb +94 -0
- data/lib/dynomite/item/query/params/key_condition.rb +34 -0
- data/lib/dynomite/item/query/params.rb +115 -0
- data/lib/dynomite/item/query/partiql/executer.rb +72 -0
- data/lib/dynomite/item/query/partiql.rb +67 -0
- data/lib/dynomite/item/query/relation/chain.rb +125 -0
- data/lib/dynomite/item/query/relation/comparision_expression.rb +21 -0
- data/lib/dynomite/item/query/relation/comparision_map.rb +19 -0
- data/lib/dynomite/item/query/relation/delete.rb +38 -0
- data/lib/dynomite/item/query/relation/ids.rb +21 -0
- data/lib/dynomite/item/query/relation/math.rb +19 -0
- data/lib/dynomite/item/query/relation/where_field.rb +32 -0
- data/lib/dynomite/item/query/relation/where_group.rb +78 -0
- data/lib/dynomite/item/query/relation.rb +127 -0
- data/lib/dynomite/item/query.rb +7 -0
- data/lib/dynomite/item/read/find.rb +196 -0
- data/lib/dynomite/item/read/find_with_event.rb +42 -0
- data/lib/dynomite/item/read.rb +90 -0
- data/lib/dynomite/item/sti.rb +43 -0
- data/lib/dynomite/item/table_namespace.rb +43 -0
- data/lib/dynomite/item/typecaster.rb +106 -0
- data/lib/dynomite/item/waiter_methods.rb +18 -0
- data/lib/dynomite/item/write/base.rb +15 -0
- data/lib/dynomite/item/write/delete_item.rb +14 -0
- data/lib/dynomite/item/write/put_item.rb +99 -0
- data/lib/dynomite/item/write/update_item.rb +73 -0
- data/lib/dynomite/item/write.rb +204 -0
- data/lib/dynomite/item.rb +113 -286
- data/lib/dynomite/migration/dsl/accessor.rb +19 -0
- data/lib/dynomite/migration/dsl/index/base.rb +42 -0
- data/lib/dynomite/migration/dsl/index/gsi.rb +59 -0
- data/lib/dynomite/migration/dsl/index/lsi.rb +27 -0
- data/lib/dynomite/migration/dsl/index.rb +72 -0
- data/lib/dynomite/migration/dsl/primary_key.rb +62 -0
- data/lib/dynomite/migration/dsl/provisioned_throughput.rb +38 -0
- data/lib/dynomite/migration/dsl.rb +89 -142
- data/lib/dynomite/migration/file_info.rb +28 -0
- data/lib/dynomite/migration/generator.rb +30 -16
- data/lib/dynomite/migration/helpers.rb +7 -0
- data/lib/dynomite/migration/internal/migrate/create_schema_migrations.rb +17 -0
- data/lib/dynomite/migration/internal/models/schema_migration.rb +6 -0
- data/lib/dynomite/migration/runner.rb +178 -0
- data/lib/dynomite/migration/templates/create_table.rb +7 -23
- data/lib/dynomite/migration/templates/delete_table.rb +7 -0
- data/lib/dynomite/migration/templates/update_table.rb +3 -18
- data/lib/dynomite/migration.rb +53 -10
- data/lib/dynomite/reserved_words.rb +13 -3
- data/lib/dynomite/seed.rb +12 -0
- data/lib/dynomite/types.rb +22 -0
- data/lib/dynomite/version.rb +1 -1
- data/lib/dynomite/waiter.rb +40 -0
- data/lib/dynomite.rb +11 -17
- data/lib/generators/application_item/application_item_generator.rb +30 -0
- data/lib/generators/application_item/templates/application_item.rb.tt +4 -0
- data/lib/jets/commands/dynamodb_command.rb +29 -0
- data/lib/jets/commands/help/generate.md +33 -0
- data/lib/jets/commands/help/migrate.md +3 -0
- metadata +201 -17
- data/docs/migrations/long-example.rb +0 -127
- data/docs/migrations/short-example.rb +0 -40
- data/lib/dynomite/db_config.rb +0 -121
- data/lib/dynomite/errors.rb +0 -15
- data/lib/dynomite/log.rb +0 -15
- data/lib/dynomite/migration/common.rb +0 -86
- data/lib/dynomite/migration/dsl/base_secondary_index.rb +0 -73
- data/lib/dynomite/migration/dsl/global_secondary_index.rb +0 -4
- data/lib/dynomite/migration/dsl/local_secondary_index.rb +0 -8
- data/lib/dynomite/migration/executor.rb +0 -38
@@ -0,0 +1,29 @@
|
|
1
|
+
require "dynomite"
|
2
|
+
|
3
|
+
module Jets::Command
|
4
|
+
class Dynamodb < Base
|
5
|
+
desc "migrate", "Runs migrations"
|
6
|
+
long_desc Help.text('dynamodb:migrate')
|
7
|
+
def migrate
|
8
|
+
Jets.boot
|
9
|
+
Dynomite::Migration::Runner.new(options).run
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "generate NAME", "Creates a migration for a DynamoDB table"
|
13
|
+
long_desc Help.text('dynamodb:generate')
|
14
|
+
option :action, desc: "create_table, update_table, delete_table. Defaults to convention based on the name of the migration."
|
15
|
+
option :partition_key, default: "id", desc: "table's partition key"
|
16
|
+
option :sort_key, default: nil, desc: "table's sort key"
|
17
|
+
option :table_name, desc: "override the the conventional table name"
|
18
|
+
def generate(name)
|
19
|
+
Dynomite::Migration::Generator.new(name, options).generate
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "seed", "Seed data"
|
23
|
+
long_desc Help.text('dynamodb:seed')
|
24
|
+
def seed
|
25
|
+
Jets.boot
|
26
|
+
Dynomite::Seed.new(options).run
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
## Examples
|
2
|
+
|
3
|
+
jets dynamodb:generate create_products --partition-key category --sort-key product_id:number
|
4
|
+
jets dynamodb:generate create_comments --partition-key post_id:string --sort-key created_at:string
|
5
|
+
jets dynamodb:generate create_posts --partition-key id # default attribute type is string
|
6
|
+
jets dynamodb:generate create_posts --partition-key id:number # attribute type will be number
|
7
|
+
|
8
|
+
## Running migrations
|
9
|
+
|
10
|
+
$ jets dynamodb:migrate
|
11
|
+
|
12
|
+
To add global secondary indexes:
|
13
|
+
|
14
|
+
$ jets dynamodb:generate update_comments --partition-key user_id:string --sort-key created_at:string
|
15
|
+
|
16
|
+
To run:
|
17
|
+
|
18
|
+
$ jets dynamodb:migrate
|
19
|
+
|
20
|
+
## Conventions
|
21
|
+
|
22
|
+
A create_table or update_table migration file is generated based name you provide. If `update` is included in the name then an update_table migration table is generated. If `create` is included in the name then a create_table migration table is generated.
|
23
|
+
|
24
|
+
The table_name is also inferred from the migration name you provide. Examples:
|
25
|
+
|
26
|
+
$ jets dynamodb:generate create_posts # table_name: posts
|
27
|
+
$ jets dynamodb:generate update_comments # table_name: comments
|
28
|
+
|
29
|
+
You can override both of these conventions:
|
30
|
+
|
31
|
+
$ jets dynamodb:generate create_my_posts --table-name posts
|
32
|
+
$ jets dynamodb:generate my_posts --action create_table --table-name posts
|
33
|
+
$ jets dynamodb:generate my_posts --action update_table --table-name posts
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynomite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2023-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: activesupport
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: memoist
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rainbow
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +80,34 @@ dependencies:
|
|
52
80
|
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: zeitwerk
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
55
111
|
- !ruby/object:Gem::Dependency
|
56
112
|
name: bundler
|
57
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +122,48 @@ dependencies:
|
|
66
122
|
- - ">="
|
67
123
|
- !ruby/object:Gem::Version
|
68
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: cli_markdown
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: nokogiri
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
69
167
|
- !ruby/object:Gem::Dependency
|
70
168
|
name: rake
|
71
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,10 +192,11 @@ dependencies:
|
|
94
192
|
- - ">="
|
95
193
|
- !ruby/object:Gem::Version
|
96
194
|
version: '0'
|
97
|
-
description:
|
195
|
+
description:
|
98
196
|
email:
|
99
197
|
- tongueroo@gmail.com
|
100
|
-
executables:
|
198
|
+
executables:
|
199
|
+
- dynomite
|
101
200
|
extensions: []
|
102
201
|
extra_rdoc_files: []
|
103
202
|
files:
|
@@ -105,35 +204,120 @@ files:
|
|
105
204
|
- ".rspec"
|
106
205
|
- CHANGELOG.md
|
107
206
|
- Gemfile
|
207
|
+
- LICENSE.txt
|
108
208
|
- README.md
|
109
209
|
- Rakefile
|
110
210
|
- bin/console
|
111
211
|
- bin/setup
|
112
|
-
- docs/migrations/long-example.rb
|
113
|
-
- docs/migrations/short-example.rb
|
114
212
|
- dynomite.gemspec
|
213
|
+
- exe/dynomite
|
115
214
|
- lib/dynomite.rb
|
215
|
+
- lib/dynomite/associations.rb
|
216
|
+
- lib/dynomite/associations/association.rb
|
217
|
+
- lib/dynomite/associations/belongs_to.rb
|
218
|
+
- lib/dynomite/associations/has_and_belongs_to_many.rb
|
219
|
+
- lib/dynomite/associations/has_many.rb
|
220
|
+
- lib/dynomite/associations/has_one.rb
|
221
|
+
- lib/dynomite/associations/many_association.rb
|
222
|
+
- lib/dynomite/associations/single_association.rb
|
223
|
+
- lib/dynomite/autoloader.rb
|
224
|
+
- lib/dynomite/cli.rb
|
225
|
+
- lib/dynomite/client.rb
|
226
|
+
- lib/dynomite/command.rb
|
227
|
+
- lib/dynomite/completer.rb
|
228
|
+
- lib/dynomite/completer/script.rb
|
229
|
+
- lib/dynomite/completer/script.sh
|
230
|
+
- lib/dynomite/config.rb
|
116
231
|
- lib/dynomite/core.rb
|
117
|
-
- lib/dynomite/
|
232
|
+
- lib/dynomite/engine.rb
|
118
233
|
- lib/dynomite/erb.rb
|
119
|
-
- lib/dynomite/
|
234
|
+
- lib/dynomite/error.rb
|
235
|
+
- lib/dynomite/help.rb
|
236
|
+
- lib/dynomite/help/completion.md
|
237
|
+
- lib/dynomite/help/completion_script.md
|
238
|
+
- lib/dynomite/help/migrate.md
|
239
|
+
- lib/dynomite/install.rb
|
120
240
|
- lib/dynomite/item.rb
|
121
|
-
- lib/dynomite/
|
241
|
+
- lib/dynomite/item/abstract.rb
|
242
|
+
- lib/dynomite/item/components.rb
|
243
|
+
- lib/dynomite/item/dsl.rb
|
244
|
+
- lib/dynomite/item/id.rb
|
245
|
+
- lib/dynomite/item/indexes.rb
|
246
|
+
- lib/dynomite/item/indexes/finder.rb
|
247
|
+
- lib/dynomite/item/indexes/index.rb
|
248
|
+
- lib/dynomite/item/indexes/primary_index.rb
|
249
|
+
- lib/dynomite/item/locking.rb
|
250
|
+
- lib/dynomite/item/magic_fields.rb
|
251
|
+
- lib/dynomite/item/primary_key.rb
|
252
|
+
- lib/dynomite/item/query.rb
|
253
|
+
- lib/dynomite/item/query/delegates.rb
|
254
|
+
- lib/dynomite/item/query/params.rb
|
255
|
+
- lib/dynomite/item/query/params/base.rb
|
256
|
+
- lib/dynomite/item/query/params/expression_attribute.rb
|
257
|
+
- lib/dynomite/item/query/params/filter.rb
|
258
|
+
- lib/dynomite/item/query/params/function/attribute_exists.rb
|
259
|
+
- lib/dynomite/item/query/params/function/attribute_type.rb
|
260
|
+
- lib/dynomite/item/query/params/function/base.rb
|
261
|
+
- lib/dynomite/item/query/params/function/begins_with.rb
|
262
|
+
- lib/dynomite/item/query/params/function/contains.rb
|
263
|
+
- lib/dynomite/item/query/params/function/size_fn.rb
|
264
|
+
- lib/dynomite/item/query/params/helpers.rb
|
265
|
+
- lib/dynomite/item/query/params/key_condition.rb
|
266
|
+
- lib/dynomite/item/query/partiql.rb
|
267
|
+
- lib/dynomite/item/query/partiql/executer.rb
|
268
|
+
- lib/dynomite/item/query/relation.rb
|
269
|
+
- lib/dynomite/item/query/relation/chain.rb
|
270
|
+
- lib/dynomite/item/query/relation/comparision_expression.rb
|
271
|
+
- lib/dynomite/item/query/relation/comparision_map.rb
|
272
|
+
- lib/dynomite/item/query/relation/delete.rb
|
273
|
+
- lib/dynomite/item/query/relation/ids.rb
|
274
|
+
- lib/dynomite/item/query/relation/math.rb
|
275
|
+
- lib/dynomite/item/query/relation/where_field.rb
|
276
|
+
- lib/dynomite/item/query/relation/where_group.rb
|
277
|
+
- lib/dynomite/item/read.rb
|
278
|
+
- lib/dynomite/item/read/find.rb
|
279
|
+
- lib/dynomite/item/read/find_with_event.rb
|
280
|
+
- lib/dynomite/item/sti.rb
|
281
|
+
- lib/dynomite/item/table_namespace.rb
|
282
|
+
- lib/dynomite/item/typecaster.rb
|
283
|
+
- lib/dynomite/item/waiter_methods.rb
|
284
|
+
- lib/dynomite/item/write.rb
|
285
|
+
- lib/dynomite/item/write/base.rb
|
286
|
+
- lib/dynomite/item/write/delete_item.rb
|
287
|
+
- lib/dynomite/item/write/put_item.rb
|
288
|
+
- lib/dynomite/item/write/update_item.rb
|
122
289
|
- lib/dynomite/migration.rb
|
123
|
-
- lib/dynomite/migration/common.rb
|
124
290
|
- lib/dynomite/migration/dsl.rb
|
125
|
-
- lib/dynomite/migration/dsl/
|
126
|
-
- lib/dynomite/migration/dsl/
|
127
|
-
- lib/dynomite/migration/dsl/
|
128
|
-
- lib/dynomite/migration/
|
291
|
+
- lib/dynomite/migration/dsl/accessor.rb
|
292
|
+
- lib/dynomite/migration/dsl/index.rb
|
293
|
+
- lib/dynomite/migration/dsl/index/base.rb
|
294
|
+
- lib/dynomite/migration/dsl/index/gsi.rb
|
295
|
+
- lib/dynomite/migration/dsl/index/lsi.rb
|
296
|
+
- lib/dynomite/migration/dsl/primary_key.rb
|
297
|
+
- lib/dynomite/migration/dsl/provisioned_throughput.rb
|
298
|
+
- lib/dynomite/migration/file_info.rb
|
129
299
|
- lib/dynomite/migration/generator.rb
|
300
|
+
- lib/dynomite/migration/helpers.rb
|
301
|
+
- lib/dynomite/migration/internal/migrate/create_schema_migrations.rb
|
302
|
+
- lib/dynomite/migration/internal/models/schema_migration.rb
|
303
|
+
- lib/dynomite/migration/runner.rb
|
130
304
|
- lib/dynomite/migration/templates/create_table.rb
|
305
|
+
- lib/dynomite/migration/templates/delete_table.rb
|
131
306
|
- lib/dynomite/migration/templates/update_table.rb
|
132
307
|
- lib/dynomite/query.rb
|
133
308
|
- lib/dynomite/reserved_words.rb
|
309
|
+
- lib/dynomite/seed.rb
|
310
|
+
- lib/dynomite/types.rb
|
134
311
|
- lib/dynomite/version.rb
|
312
|
+
- lib/dynomite/waiter.rb
|
313
|
+
- lib/generators/application_item/application_item_generator.rb
|
314
|
+
- lib/generators/application_item/templates/application_item.rb.tt
|
315
|
+
- lib/jets/commands/dynamodb_command.rb
|
316
|
+
- lib/jets/commands/help/generate.md
|
317
|
+
- lib/jets/commands/help/migrate.md
|
135
318
|
homepage: https://github.com/tongueroo/dynomite
|
136
|
-
licenses:
|
319
|
+
licenses:
|
320
|
+
- MIT
|
137
321
|
metadata: {}
|
138
322
|
post_install_message:
|
139
323
|
rdoc_options: []
|
@@ -150,8 +334,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
334
|
- !ruby/object:Gem::Version
|
151
335
|
version: '0'
|
152
336
|
requirements: []
|
153
|
-
rubygems_version: 3.
|
337
|
+
rubygems_version: 3.4.20
|
154
338
|
signing_key:
|
155
339
|
specification_version: 4
|
156
|
-
summary: ActiveRecord-ish
|
340
|
+
summary: ActiveRecord-ish DynamoDB ORM
|
157
341
|
test_files: []
|
@@ -1,127 +0,0 @@
|
|
1
|
-
# Note: table name created will be namespaced based on
|
2
|
-
# Dynomite::Migration.table_namespace. This can be set in
|
3
|
-
# config/dynamodb.yml
|
4
|
-
#
|
5
|
-
# development:
|
6
|
-
# table_namespace: "mynamespace"
|
7
|
-
#
|
8
|
-
# This results in:
|
9
|
-
# create_table "posts"
|
10
|
-
# Produces:
|
11
|
-
# table name: "mynamespace-posts"
|
12
|
-
#
|
13
|
-
# When you're in a in Jets project you can set the namespace based on
|
14
|
-
# Jets.config.table_namespace, which is based on the project name and
|
15
|
-
# a short version of the environment. Example:
|
16
|
-
#
|
17
|
-
# `config/dynamodb.yml`:
|
18
|
-
# development:
|
19
|
-
# table_namespace: <%= Jets.config.table_namespace %>
|
20
|
-
#
|
21
|
-
# If your project_name is demo and environment is production:
|
22
|
-
# create_table "posts" => table name: "demo-prod-posts"
|
23
|
-
#
|
24
|
-
# If your project_name is demo and environment is staging:
|
25
|
-
# create_table "posts" => table name: "demo-stag-posts"
|
26
|
-
#
|
27
|
-
# If your project_name is demo and environment is development:
|
28
|
-
# create_table "posts" => table name: "demo-dev-posts"
|
29
|
-
#
|
30
|
-
# If the table_namespace is set to a blank string or nil, then a namespace
|
31
|
-
# will not be prepended at all.
|
32
|
-
|
33
|
-
class CreateCommentsMigration < Dynomite::Migration
|
34
|
-
def up
|
35
|
-
create_table :comments do |t|
|
36
|
-
t.partition_key "post_id:string" # required
|
37
|
-
t.sort_key "created_at:string" # optional
|
38
|
-
t.provisioned_throughput(5) # sets both read and write, defaults to 5 when not set
|
39
|
-
|
40
|
-
# Instead of using partition_key and sort_key you can set the
|
41
|
-
# key schema directly also
|
42
|
-
# t.key_schema([
|
43
|
-
# {attribute_name: "id", :key_type=>"HASH"},
|
44
|
-
# {attribute_name: "created_at", :key_type=>"RANGE"}
|
45
|
-
# ])
|
46
|
-
# t.attribute_definitions([
|
47
|
-
# {attribute_name: "id", attribute_type: "N"},
|
48
|
-
# {attribute_name: "created_at", attribute_type: "S"}
|
49
|
-
# ])
|
50
|
-
|
51
|
-
# other ways to set provisioned_throughput
|
52
|
-
# t.provisioned_throughput(:read, 10)
|
53
|
-
# t.provisioned_throughput(:write, 10)
|
54
|
-
# t.provisioned_throughput(
|
55
|
-
# read_capacity_units: 5,
|
56
|
-
# write_capacity_units: 5
|
57
|
-
# )
|
58
|
-
|
59
|
-
# set the billing mode to on-demand (NOTE: this overrides provisioned_throughput)
|
60
|
-
# t.billing_mode(:pay_per_request)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class UpdateCommentsMigration < Dynomite::Migration
|
66
|
-
def up
|
67
|
-
update_table :comments do |t|
|
68
|
-
# You can update from provisioned_throughput to on-demand pricing
|
69
|
-
# t.billing_mode(:pay_per_request)
|
70
|
-
|
71
|
-
# t.global_secondary_index do
|
72
|
-
# t.gsi(METHOD, INDEX_NAME) do
|
73
|
-
|
74
|
-
# You normally create an index like so:
|
75
|
-
#
|
76
|
-
# t.gsi(:create) do |i|
|
77
|
-
# i.partition_key = "post_id:string" # partition_key is required
|
78
|
-
# i.sort_key = "updated_at:string" # sort_key is optional
|
79
|
-
# end
|
80
|
-
#
|
81
|
-
# The index name will be inferred from the partition_key and sort_key when
|
82
|
-
# not explicitly set. Examples:
|
83
|
-
#
|
84
|
-
# index_name = "#{partition_key}-#{sort_key}-index"
|
85
|
-
# index_name = "post_id-index" # no sort key
|
86
|
-
# index_name = "post_id-updated_at-index" # has sort key
|
87
|
-
#
|
88
|
-
# The inference allows you to not have to worry about the index
|
89
|
-
# naming scheme. You can still set the index_name explicitly like so:
|
90
|
-
#
|
91
|
-
# t.gsi(:create, "post_id-updated_at-index") do |i|
|
92
|
-
# i.partition_key = "post_id:string" # partition_key is required
|
93
|
-
# i.sort_key = "updated_at:string" # sort_key is optional
|
94
|
-
# end
|
95
|
-
#
|
96
|
-
t.gsi(:create) do |i|
|
97
|
-
i.partition_key "post_id:string"
|
98
|
-
i.sort_key "updated_at:string" # optional
|
99
|
-
|
100
|
-
# translates to
|
101
|
-
# i.key_schema({...})
|
102
|
-
# also makes sure that the schema_keys are added to the attributes_definitions
|
103
|
-
|
104
|
-
# t.projected_attributes(:all) # default if not called
|
105
|
-
# t.projected_attributes(:keys_only) # other ways to call
|
106
|
-
# t.projected_attributes([:id, :body, :tags, :updated_at])
|
107
|
-
# translates to:
|
108
|
-
# Valid Values: ALL | KEYS_ONLY | INCLUDE
|
109
|
-
# t.projection(
|
110
|
-
# projection_type: :all, # defaults to all
|
111
|
-
# )
|
112
|
-
# t.projection(
|
113
|
-
# projection_type: :include, # defaults to all
|
114
|
-
# non_key_attributes: [:id, :body, :tags, :updated_at], # defaults to all
|
115
|
-
# )
|
116
|
-
|
117
|
-
i.provisioned_throughput(10)
|
118
|
-
end
|
119
|
-
|
120
|
-
t.gsi(:update, "category-index") do |i|
|
121
|
-
i.provisioned_throughput(10)
|
122
|
-
end
|
123
|
-
|
124
|
-
t.gsi(:delete, "category-index")
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
class CreateCommentsMigration < Dynomite::Migration
|
2
|
-
def up
|
3
|
-
create_table :comments do |t|
|
4
|
-
t.partition_key "post_id:string" # required
|
5
|
-
t.sort_key "created_at:string" # optional
|
6
|
-
t.provisioned_throughput(1) # sets both read and write, defaults to 5 when not set
|
7
|
-
|
8
|
-
t.lsi do |i|
|
9
|
-
i.partition_key "post_id:string"
|
10
|
-
i.sort_key "updated_at:string" # required for lsi
|
11
|
-
i.provisioned_throughput(2)
|
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
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class UpdateCommentsMigration < Dynomite::Migration
|
24
|
-
def up
|
25
|
-
update_table :comments do |t|
|
26
|
-
t.gsi(:create) do |i|
|
27
|
-
i.partition_key "post_id:string"
|
28
|
-
i.sort_key "flagged_at:string" # optional for gsi
|
29
|
-
i.provisioned_throughput(3)
|
30
|
-
end
|
31
|
-
|
32
|
-
t.gsi(:update, "update-me-index") do |i|
|
33
|
-
i.provisioned_throughput(5)
|
34
|
-
end
|
35
|
-
|
36
|
-
t.gsi(:delete, "delete-me-index")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
data/lib/dynomite/db_config.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
require "aws-sdk-dynamodb"
|
2
|
-
require 'fileutils'
|
3
|
-
require 'erb'
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
module Dynomite::DbConfig
|
7
|
-
def self.included(base)
|
8
|
-
base.extend(ClassMethods)
|
9
|
-
end
|
10
|
-
|
11
|
-
def db
|
12
|
-
self.class.db
|
13
|
-
end
|
14
|
-
|
15
|
-
# NOTE: Class including Dynomite::DbConfig is required to have table_name method defined
|
16
|
-
def namespaced_table_name
|
17
|
-
[self.class.table_namespace, table_name].reject {|s| s.nil? || s.empty?}.join('-')
|
18
|
-
end
|
19
|
-
|
20
|
-
module ClassMethods
|
21
|
-
@@db = nil
|
22
|
-
def db
|
23
|
-
return @@db if @@db
|
24
|
-
|
25
|
-
config = db_config
|
26
|
-
endpoint = ENV['DYNAMODB_ENDPOINT'] || config['endpoint']
|
27
|
-
check_dynamodb_local!(endpoint)
|
28
|
-
|
29
|
-
# Normally, do not set the endpoint to use the current configured region.
|
30
|
-
# Probably want to stay in the same region anyway for db connections.
|
31
|
-
#
|
32
|
-
# List of regional endpoints: https://docs.aws.amazon.com/general/latest/gr/rande.html#ddb_region
|
33
|
-
# Example:
|
34
|
-
# endpoint: https://dynamodb.us-east-1.amazonaws.com
|
35
|
-
options = endpoint ? { endpoint: endpoint } : {}
|
36
|
-
@@db ||= Aws::DynamoDB::Client.new(options)
|
37
|
-
end
|
38
|
-
|
39
|
-
# When endoint has been configured to point at dynamodb local: localhost:8000
|
40
|
-
# check if port 8000 is listening and timeout quickly. Or else it takes a
|
41
|
-
# for DynamoDB local to time out, about 10 seconds...
|
42
|
-
# This wastes less of the users time.
|
43
|
-
def check_dynamodb_local!(endpoint)
|
44
|
-
return unless endpoint && endpoint.include?("8000")
|
45
|
-
|
46
|
-
host, port = endpoint.gsub("http://", "").split(":")
|
47
|
-
ip = get_endpoint_ip(host)
|
48
|
-
unless ip
|
49
|
-
raise "You have configured your app to use DynamoDB local, but it is not running on the host: #{host}."
|
50
|
-
end
|
51
|
-
|
52
|
-
open = port_open?(ip, 8000, 0.2)
|
53
|
-
unless open
|
54
|
-
raise "You have configured your app to use DynamoDB local, but it is not running. Please start DynamoDB local. Example: brew install --cask dynamodb-local && dynamodb-local"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def get_endpoint_ip(host)
|
59
|
-
begin
|
60
|
-
IPSocket.getaddress(host)
|
61
|
-
rescue SocketError
|
62
|
-
false # Can return anything you want here
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Thanks: https://gist.github.com/ashrithr/5305786
|
67
|
-
def port_open?(ip, port, seconds=1)
|
68
|
-
# => checks if a port is open or not
|
69
|
-
Timeout::timeout(seconds) do
|
70
|
-
begin
|
71
|
-
TCPSocket.new(ip, port).close
|
72
|
-
true
|
73
|
-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError
|
74
|
-
false
|
75
|
-
end
|
76
|
-
end
|
77
|
-
rescue Timeout::Error
|
78
|
-
false
|
79
|
-
end
|
80
|
-
|
81
|
-
# useful for specs
|
82
|
-
def db=(db)
|
83
|
-
@@db = db
|
84
|
-
end
|
85
|
-
|
86
|
-
def db_config
|
87
|
-
return @db_config if @db_config
|
88
|
-
|
89
|
-
if defined?(Jets)
|
90
|
-
config_path = "#{Jets.root}/config/dynamodb.yml"
|
91
|
-
env = Jets.env
|
92
|
-
else
|
93
|
-
config_path = ENV['DYNOMITE_CONFIG'] || "./config/dynamodb.yml"
|
94
|
-
env = ENV['DYNOMITE_ENV'] || "development"
|
95
|
-
end
|
96
|
-
|
97
|
-
config = YAML.load(Dynomite::Erb.result(config_path))
|
98
|
-
@db_config ||= config[env] || {}
|
99
|
-
end
|
100
|
-
|
101
|
-
def table_namespace(*args)
|
102
|
-
case args.size
|
103
|
-
when 0
|
104
|
-
get_table_namespace
|
105
|
-
when 1
|
106
|
-
set_table_namespace(args[0])
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def get_table_namespace
|
111
|
-
return @table_namespace if defined?(@table_namespace)
|
112
|
-
|
113
|
-
config = db_config
|
114
|
-
@table_namespace = config['table_namespace']
|
115
|
-
end
|
116
|
-
|
117
|
-
def set_table_namespace(value)
|
118
|
-
@table_namespace = value
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
data/lib/dynomite/errors.rb
DELETED