ddbcli 0.4.2.beta2 → 0.5.0.beta

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
  SHA1:
3
- metadata.gz: ac2238a761573161178f72d78757870ad02735a5
4
- data.tar.gz: 5046cc50433acfd4ff88d1933c735b91c1143ba4
3
+ metadata.gz: 2c0e2c3493edb0a71f2b4676531af7dac96db8be
4
+ data.tar.gz: 066e62c63e99dbf54126bbfe679488846dbec728
5
5
  SHA512:
6
- metadata.gz: 7e13df954a61dc235af9c701189013ad1ead06d5292e99cbd5ba5b1073d79e879adb7e6efc52111a8bb009481d8a8d96df98c066b3806d2201dfa9823d161953
7
- data.tar.gz: 8f2a722e1df716bb7062c56bf1319877208ca0d28e466109fb6146a1d3754c4a0714cfbb1b29bcff2124551c3edbdbb8fc9a9bcc8e72220fc3c6fc03d43c2d52
6
+ metadata.gz: bea729ff5ae101274f98a0d95d666a4beb88ced9fa41149eb3be44ae5d32848fba539097a60206404bcf3639e52daab8751618ffeddea62e30ee42bf7ceb0fc3
7
+ data.tar.gz: 1bc777cd214d0237918569a2bb4e6ab400b57be6ab74085f81dae3a93bbd8baa9deb880e9a87e6f0c8499fb6116a431223652d11c0a6900e85262dbf5bc6c523
data/README.md CHANGED
@@ -69,16 +69,16 @@ DEBUG: 'i' contains: [{"gender"=>"F"}, {"gender"=>"F"}, {"gender"=>"F"}] ...
69
69
  ##### Query #####
70
70
 
71
71
  SHOW TABLES [LIMIT num] [LIKE '...']
72
- displays a table list
72
+ display a table list
73
73
 
74
74
  SHOW TABLE STATUS [LIKE '...']
75
- displays table statues
75
+ display table statues
76
76
 
77
77
  SHOW REGIONS
78
- displays a region list
78
+ display a region list
79
79
 
80
80
  SHOW CREATE TABLE table_name
81
- displays a CREATE TABLE statement
81
+ display a CREATE TABLE statement
82
82
 
83
83
  CREATE TABLE table_name (
84
84
  key_name {STRING|NUMBER|BINARY} HASH
@@ -90,56 +90,62 @@ CREATE TABLE table_name (
90
90
  , GLOBAL INDEX index2_name (hash_attr2 {STRING|NUMBER|BINARY} [, range_attr2 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} [READ = num WRITE = num]
91
91
  , ...]
92
92
  ) READ = num WRITE = num [STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}]
93
- creates a table
93
+ create a table
94
94
 
95
95
  CREATE TABLE table_name LIKE another_table_name [READ = num WRITE = num] [STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}]
96
- creates a table like another table
96
+ create a table like another table
97
97
 
98
98
  DROP TABLE table_name [, table_name2, ...]
99
- deletes tables
99
+ delete tables
100
100
 
101
101
  ALTER TABLE table_name {READ = num WRITE = num|STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}}
102
- updates the provisioned throughput
102
+ update the provisioned throughput
103
103
 
104
- ALTER TABLE table_name CHANGE INDEX index_name READ = num WRITE = num
105
- updates GSI provisioned throughput
104
+ ALTER TABLE table_name CHANGE GLOBAL INDEX index_name READ = num WRITE = num
105
+ update GSI provisioned throughput
106
+
107
+ ALTER TABLE table_name ADD GLOBAL INDEX index_name (hash_attr1 {STRING|NUMBER|BINARY} [, range_attr1 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} READ = num WRITE = num
108
+ add GSI
109
+
110
+ ALTER TABLE table_name DROP GLOBAL INDEX index_name
111
+ delete GSI
106
112
 
107
113
  GET {*|attr1,attr2,...} FROM table_name WHERE key1 = '...' AND ...
108
- gets items
114
+ get items
109
115
 
110
116
  INSERT INTO table_name (attr1, attr2, ...) VALUES ('val1', 'val2', ...), ('val3', 'val4', ...), ...
111
117
  INSERT INTO table_name SELECT ...
112
118
  INSERT INTO table_name SELECT ALL ...
113
- creates items
119
+ create items
114
120
 
115
121
  UPDATE table_name {SET|ADD} attr1 = 'val1', ... WHERE key1 = '...' AND ...
116
122
  UPDATE ALL table_name {SET|ADD} attr1 = 'val1', ... [WHERE attr1 = '...' AND ...] [LIMIT limit]
117
- updates items
123
+ update items
118
124
  ("UPDATE" can update only one record. Please use "UPDATE ALL", when you update more than one.)
119
125
 
120
126
  UPDATE table_name DEL[ETE] attr1, ... WHERE key1 = '...' AND ...
121
127
  UPDATE ALL table_name DEL[ETE] attr1, ... [WHERE attr1 = '...' AND ...] [LIMIT limit]
122
- updates items (delete attribute)
128
+ update items (delete attribute)
123
129
 
124
130
  DELETE FROM table_name WHERE key1 = '...' AND ..
125
131
  DELETE ALL FROM table_name WHERE [WHERE attr1 = '...' AND ...] [ORDER {ASC|DESC}] [LIMIT limit]
126
- deletes items
132
+ delete items
127
133
  ("DELETE" can delete only one record. Please use "DELETE ALL", when you update more than one.)
128
134
 
129
135
  SELECT {*|attr1,attr2,...|COUNT(*)} FROM table_name [USE INDEX (index_name)] [WHERE key1 = '...' AND ...] [HAVING attr1 = '...' AND ...] [ORDER {ASC|DESC}] [LIMIT limit]
130
136
  SELECT ALL {*|attr1,attr2,...|COUNT(*)} FROM table_name [WHERE attr1 = '...' AND ...] [LIMIT limit]
131
137
  SELECT segment/total_segments {*|attr1,attr2,...|COUNT(*)} FROM table_name [WHERE attr1 = '...' AND ...] [LIMIT limit]
132
- queries using the Query/Scan action
138
+ query using the Query/Scan action
133
139
  see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html
134
140
 
135
141
  DESC[RIBE] table_name
136
- displays information about the table
142
+ display information about the table
137
143
 
138
144
  USE region_or_endpoint
139
- changes an endpoint
145
+ change an endpoint
140
146
 
141
147
  NEXT
142
- displays a continuation of a result
148
+ display a continuation of a result
143
149
  (NEXT statement is published after SELECT statement)
144
150
 
145
151
 
@@ -218,16 +224,16 @@ Append
218
224
 
219
225
  ##### Command #####
220
226
 
221
- .help displays this message
222
- .quit | .exit exits ddbcli
223
- .consistent (true|false)? displays ConsistentRead parameter or changes it
224
- .iteratable (true|false)? displays iteratable option or changes it
227
+ .help display this message
228
+ .quit | .exit exit ddbcli
229
+ .consistent (true|false)? display ConsistentRead parameter or changes it
230
+ .iteratable (true|false)? display iteratable option or changes it
225
231
  all results are displayed if true
226
- .debug (true|false)? displays a debug status or changes it
227
- .retry NUM? displays number of times of a retry or changes it
228
- .retry_interval SECOND? displays a retry interval second or changes it
229
- .timeout SECOND? displays a timeout second or changes it
230
- .version displays a version
232
+ .debug (true|false)? display a debug status or changes it
233
+ .retry NUM? display number of times of a retry or changes it
234
+ .retry_interval SECOND? display a retry interval second or changes it
235
+ .timeout SECOND? display a timeout second or changes it
236
+ .version display a version
231
237
  ```
232
238
 
233
239
  # Test
@@ -5,16 +5,16 @@ def print_help(options = {})
5
5
  ##### Query #####
6
6
 
7
7
  SHOW TABLES [LIMIT num] [LIKE '...']
8
- displays a table list
8
+ display a table list
9
9
 
10
10
  SHOW TABLE STATUS [LIKE '...']
11
- displays table statues
11
+ display table statues
12
12
 
13
13
  SHOW REGIONS
14
- displays a region list
14
+ display a region list
15
15
 
16
16
  SHOW CREATE TABLE table_name
17
- displays a CREATE TABLE statement
17
+ display a CREATE TABLE statement
18
18
 
19
19
  CREATE TABLE table_name (
20
20
  key_name {STRING|NUMBER|BINARY} HASH
@@ -26,57 +26,62 @@ CREATE TABLE table_name (
26
26
  , GLOBAL INDEX index2_name (hash_attr2 {STRING|NUMBER|BINARY} [, range_attr2 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} [READ = num WRITE = num]
27
27
  , ...]
28
28
  ) READ = num WRITE = num [STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}]
29
- creates a table
29
+ create a table
30
30
 
31
31
  CREATE TABLE table_name LIKE another_table_name [READ = num WRITE = num] [STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}]
32
- creates a table like another table
32
+ create a table like another table
33
33
 
34
34
  DROP TABLE table_name [, table_name2, ...]
35
- deletes tables
35
+ delete tables
36
36
 
37
37
  ALTER TABLE table_name {READ = num WRITE = num|STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}}
38
+ update the provisioned throughput
38
39
 
39
- updates the provisioned throughput
40
+ ALTER TABLE table_name CHANGE GLOBAL INDEX index_name READ = num WRITE = num
41
+ update GSI provisioned throughput
40
42
 
41
- ALTER TABLE table_name CHANGE INDEX index_name READ = num WRITE = num
42
- updates GSI provisioned throughput
43
+ ALTER TABLE table_name ADD GLOBAL INDEX index_name (hash_attr1 {STRING|NUMBER|BINARY} [, range_attr1 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} READ = num WRITE = num
44
+ add GSI
45
+
46
+ ALTER TABLE table_name DROP GLOBAL INDEX index_name
47
+ delete GSI
43
48
 
44
49
  GET {*|attr1,attr2,...} FROM table_name WHERE key1 = '...' AND ...
45
- gets items
50
+ get items
46
51
 
47
52
  INSERT INTO table_name (attr1, attr2, ...) VALUES ('val1', 'val2', ...), ('val3', 'val4', ...), ...
48
53
  INSERT INTO table_name SELECT ...
49
54
  INSERT INTO table_name SELECT ALL ...
50
- creates items
55
+ create items
51
56
 
52
57
  UPDATE table_name {SET|ADD} attr1 = 'val1', ... WHERE key1 = '...' AND ...
53
58
  UPDATE ALL table_name {SET|ADD} attr1 = 'val1', ... [WHERE attr1 = '...' AND ...] [LIMIT limit]
54
- updates items
59
+ update items
55
60
  ("UPDATE" can update only one record. Please use "UPDATE ALL", when you update more than one.)
56
61
 
57
62
  UPDATE table_name DEL[ETE] attr1, ... WHERE key1 = '...' AND ...
58
63
  UPDATE ALL table_name DEL[ETE] attr1, ... [WHERE attr1 = '...' AND ...] [LIMIT limit]
59
- updates items (delete attribute)
64
+ update items (delete attribute)
60
65
 
61
66
  DELETE FROM table_name WHERE key1 = '...' AND ..
62
67
  DELETE ALL FROM table_name WHERE [WHERE attr1 = '...' AND ...] [ORDER {ASC|DESC}] [LIMIT limit]
63
- deletes items
68
+ delete items
64
69
  ("DELETE" can delete only one record. Please use "DELETE ALL", when you update more than one.)
65
70
 
66
71
  SELECT {*|attr1,attr2,...|COUNT(*)} FROM table_name [USE INDEX (index_name)] [WHERE key1 = '...' AND ...] [HAVING attr1 = '...' AND ...] [ORDER {ASC|DESC}] [LIMIT limit]
67
72
  SELECT ALL {*|attr1,attr2,...|COUNT(*)} FROM table_name [WHERE attr1 = '...' AND ...] [LIMIT limit]
68
73
  SELECT segment/total_segments {*|attr1,attr2,...|COUNT(*)} FROM table_name [WHERE attr1 = '...' AND ...] [LIMIT limit]
69
- queries using the Query/Scan action
74
+ query using the Query/Scan action
70
75
  see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html
71
76
 
72
77
  DESC[RIBE] table_name
73
- displays information about the table
78
+ display information about the table
74
79
 
75
80
  USE region_or_endpoint
76
- changes an endpoint
81
+ change an endpoint
77
82
 
78
83
  NEXT
79
- displays a continuation of a result
84
+ display a continuation of a result
80
85
  (NEXT statement is published after SELECT statement)
81
86
 
82
87
 
@@ -155,16 +160,16 @@ Append
155
160
 
156
161
  ##### Command #####
157
162
 
158
- .help displays this message
159
- .quit | .exit exits ddbcli
160
- .consistent (true|false)? displays ConsistentRead parameter or changes it
161
- .iteratable (true|false)? displays iteratable option or changes it
163
+ .help display this message
164
+ .quit | .exit exit ddbcli
165
+ .consistent (true|false)? display ConsistentRead parameter or changes it
166
+ .iteratable (true|false)? display iteratable option or changes it
162
167
  all results are displayed if true
163
- .debug (true|false)? displays a debug status or changes it
164
- .retry NUM? displays number of times of a retry or changes it
165
- .retry_interval SECOND? displays a retry interval second or changes it
166
- .timeout SECOND? displays a timeout second or changes it
167
- .version displays a version
168
+ .debug (true|false)? display a debug status or changes it
169
+ .retry NUM? display number of times of a retry or changes it
170
+ .retry_interval SECOND? display a retry interval second or changes it
171
+ .timeout SECOND? display a timeout second or changes it
172
+ .version display a version
168
173
 
169
174
  EOS
170
175
 
@@ -61,6 +61,8 @@ module DynamoDB
61
61
  do_show_create_table(parsed)
62
62
  when :ALTER_TABLE
63
63
  do_alter_table(parsed)
64
+ when :ALTER_TABLE_INDEX
65
+ do_alter_table_index(parsed)
64
66
  when :USE
65
67
  do_use(parsed)
66
68
  when :CREATE
@@ -287,6 +289,7 @@ module DynamoDB
287
289
 
288
290
  (table_info['GlobalSecondaryIndexes'] || []).each do |i|
289
291
  index_name = i['IndexName']
292
+ next unless i['KeySchema']
290
293
  key_names = i['KeySchema'].map {|j| j['AttributeName'] }
291
294
  proj_type = i['Projection']['ProjectionType']
292
295
  proj_attrs = i['Projection']['NonKeyAttributes']
@@ -359,33 +362,58 @@ module DynamoDB
359
362
  def do_alter_table(parsed)
360
363
  req_hash = {'TableName' => parsed.table}
361
364
 
362
- if parsed.index_name
363
- req_hash['GlobalSecondaryIndexUpdates'] = [{
364
- 'Update' => {
365
- 'IndexName' => parsed.index_name,
366
- 'ProvisionedThroughput' => throughput,
367
- },
368
- }]
369
- else
370
- if parsed.capacity
371
- req_hash['ProvisionedThroughput'] = {
372
- 'ReadCapacityUnits' => parsed.capacity[:read],
373
- 'WriteCapacityUnits' => parsed.capacity[:write],
365
+ if parsed.capacity
366
+ req_hash['ProvisionedThroughput'] = {
367
+ 'ReadCapacityUnits' => parsed.capacity[:read],
368
+ 'WriteCapacityUnits' => parsed.capacity[:write],
369
+ }
370
+ end
371
+
372
+ unless parsed.stream.nil?
373
+ if parsed.stream
374
+ view_type = (parsed.stream == true) ? 'KEYS_ONLY' : parsed.stream.to_s.upcase
375
+
376
+ req_hash['StreamSpecification'] = {
377
+ 'StreamEnabled' => true,
378
+ 'StreamViewType' => view_type,
374
379
  }
380
+ else
381
+ req_hash['StreamSpecification'] = {'StreamEnabled' => false}
375
382
  end
383
+ end
376
384
 
377
- unless parsed.stream.nil?
378
- if parsed.stream
379
- view_type = (parsed.stream == true) ? 'KEYS_ONLY' : parsed.stream.to_s.upcase
385
+ @client.query('UpdateTable', req_hash)
386
+ nil
387
+ end
380
388
 
381
- req_hash['StreamSpecification'] = {
382
- 'StreamEnabled' => true,
383
- 'StreamViewType' => view_type,
384
- }
385
- else
386
- req_hash['StreamSpecification'] = {'StreamEnabled' => false}
387
- end
388
- end
389
+ def do_alter_table_index(parsed)
390
+ req_hash = {'TableName' => parsed.table}
391
+ index_definition = parsed.index_definition
392
+ gsi_updates = req_hash['GlobalSecondaryIndexUpdates'] = []
393
+
394
+ case parsed.action
395
+ when 'Update'
396
+ gsi_updates << {
397
+ 'Update' => {
398
+ 'IndexName' => index_definition[:name],
399
+ 'ProvisionedThroughput' => {
400
+ 'ReadCapacityUnits' => index_definition[:capacity][:read],
401
+ 'WriteCapacityUnits' => index_definition[:capacity][:write],
402
+ },
403
+ },
404
+ }
405
+ when 'Create'
406
+ attr_defs = req_hash['AttributeDefinitions'] = []
407
+
408
+ gsi_updates << {
409
+ 'Create' => define_index(index_definition, attr_defs, :global => true),
410
+ }
411
+ when 'Delete'
412
+ gsi_updates << {
413
+ 'Delete' => {
414
+ 'IndexName' => index_definition[:name],
415
+ },
416
+ }
389
417
  end
390
418
 
391
419
  @client.query('UpdateTable', req_hash)
@@ -458,105 +486,103 @@ module DynamoDB
458
486
  local_indices = (parsed.indices || []).select {|i| not i[:global] }
459
487
  global_indices = (parsed.indices || []).select {|i| i[:global] }
460
488
 
461
- define_attribute = lambda do |attr_name, attr_type|
462
- attr_defs = req_hash['AttributeDefinitions']
463
- same_attr = attr_defs.find {|i| i['AttributeName'] == attr_name }
489
+ # local secondary index
490
+ unless local_indices.empty?
491
+ req_hash['LocalSecondaryIndexes'] = []
464
492
 
465
- if same_attr
466
- if same_attr['AttributeType'] != attr_type
467
- raise DynamoDB::Error, "different types have been defined: #{attr_name}"
468
- end
469
- else
470
- attr_defs << {
471
- 'AttributeName' => attr_name,
472
- 'AttributeType' => attr_type,
473
- }
493
+ local_indices.each do |idx_def|
494
+ local_secondary_index = define_index(idx_def, req_hash['AttributeDefinitions'], :global => false, :hash_name => parsed.hash[:name])
495
+ req_hash['LocalSecondaryIndexes'] << local_secondary_index
474
496
  end
475
497
  end
476
498
 
477
- define_index = lambda do |idx_def, def_idx_opts|
478
- global_idx = def_idx_opts[:global]
479
-
499
+ # global secondary index
500
+ unless global_indices.empty?
501
+ req_hash['GlobalSecondaryIndexes'] = []
480
502
 
481
- if global_idx
482
- idx_def[:keys].each do |key_type, name_type|
483
- define_attribute.call(name_type[:key], name_type[:type])
484
- end
485
- else
486
- define_attribute.call(idx_def[:key], idx_def[:type])
503
+ global_indices.each do |idx_def|
504
+ global_secondary_index = define_index(idx_def, req_hash['AttributeDefinitions'], :global => true, :capacity => parsed.capacity)
505
+ req_hash['GlobalSecondaryIndexes'] << global_secondary_index
487
506
  end
507
+ end
488
508
 
489
- secondary_index = {
490
- 'IndexName' => idx_def[:name],
491
- 'Projection' => {
492
- 'ProjectionType' => idx_def[:projection][:type],
493
- }
494
- }
495
-
496
- if global_idx
497
- secondary_index['KeySchema'] = []
498
-
499
- [:hash, :range].each do |key_type|
500
- name_type = idx_def[:keys][key_type]
509
+ @client.query('CreateTable', req_hash)
510
+ nil
511
+ end
501
512
 
502
- if name_type
503
- secondary_index['KeySchema'] << {
504
- 'AttributeName' => name_type[:key],
505
- 'KeyType' => key_type.to_s.upcase,
506
- }
507
- end
508
- end
509
- else
510
- secondary_index['KeySchema'] = [
511
- {
512
- 'AttributeName' => parsed.hash[:name],
513
- 'KeyType' => 'HASH',
514
- },
515
- {
516
- 'AttributeName' => idx_def[:key],
517
- 'KeyType' => 'RANGE',
518
- },
519
- ]
520
- end
513
+ def define_attribute(attr_name, attr_type, attr_defs)
514
+ same_attr = attr_defs.find {|i| i['AttributeName'] == attr_name }
521
515
 
522
- if idx_def[:projection][:attrs]
523
- secondary_index['Projection']['NonKeyAttributes'] = idx_def[:projection][:attrs]
516
+ if same_attr
517
+ if same_attr['AttributeType'] != attr_type
518
+ raise DynamoDB::Error, "different types have been defined: #{attr_name}"
524
519
  end
520
+ else
521
+ attr_defs << {
522
+ 'AttributeName' => attr_name,
523
+ 'AttributeType' => attr_type,
524
+ }
525
+ end
526
+ end
525
527
 
526
- if global_idx
527
- capacity = idx_def[:capacity] || parsed.capacity
528
+ def define_index(idx_def, attr_defs, def_idx_opts)
529
+ global_idx = def_idx_opts[:global]
528
530
 
529
- secondary_index['ProvisionedThroughput'] = {
530
- 'ReadCapacityUnits' => capacity[:read],
531
- 'WriteCapacityUnits' => capacity[:write],
532
- }
531
+ if global_idx
532
+ idx_def[:keys].each do |key_type, name_type|
533
+ define_attribute(name_type[:key], name_type[:type], attr_defs)
533
534
  end
535
+ else
536
+ define_attribute(idx_def[:key], idx_def[:type], attr_defs)
537
+ end
534
538
 
535
- secondary_index
536
- end # define_index
539
+ secondary_index = {
540
+ 'IndexName' => idx_def[:name],
541
+ 'Projection' => {
542
+ 'ProjectionType' => idx_def[:projection][:type],
543
+ }
544
+ }
537
545
 
538
- # local secondary index
539
- unless local_indices.empty?
540
- req_hash['LocalSecondaryIndexes'] = []
546
+ if global_idx
547
+ secondary_index['KeySchema'] = []
541
548
 
542
- local_indices.each do |idx_def|
543
- local_secondary_index = define_index.call(idx_def, :global => false)
544
- req_hash['LocalSecondaryIndexes'] << local_secondary_index
549
+ [:hash, :range].each do |key_type|
550
+ name_type = idx_def[:keys][key_type]
551
+
552
+ if name_type
553
+ secondary_index['KeySchema'] << {
554
+ 'AttributeName' => name_type[:key],
555
+ 'KeyType' => key_type.to_s.upcase,
556
+ }
557
+ end
545
558
  end
559
+ else
560
+ secondary_index['KeySchema'] = [
561
+ {
562
+ 'AttributeName' => def_idx_opts.fetch(:hash_name),
563
+ 'KeyType' => 'HASH',
564
+ },
565
+ {
566
+ 'AttributeName' => idx_def[:key],
567
+ 'KeyType' => 'RANGE',
568
+ },
569
+ ]
546
570
  end
547
571
 
548
- # global secondary index
549
- unless global_indices.empty?
550
- req_hash['GlobalSecondaryIndexes'] = []
572
+ if idx_def[:projection][:attrs]
573
+ secondary_index['Projection']['NonKeyAttributes'] = idx_def[:projection][:attrs]
574
+ end
551
575
 
552
- global_indices.each do |idx_def|
553
- global_secondary_index = define_index.call(idx_def, :global => true)
554
- req_hash['GlobalSecondaryIndexes'] << global_secondary_index
555
- end
576
+ if global_idx
577
+ capacity = idx_def[:capacity] || def_idx_opts.fetch(:capacity)
578
+
579
+ secondary_index['ProvisionedThroughput'] = {
580
+ 'ReadCapacityUnits' => capacity[:read],
581
+ 'WriteCapacityUnits' => capacity[:write],
582
+ }
556
583
  end
557
584
 
558
- @client.query('CreateTable', req_hash)
559
- nil
585
+ secondary_index
560
586
  end
561
587
 
562
588
  def do_create_like(parsed)