Module: DynamodbModel::Migration::Dsl::Common
- Included in:
- DynamodbModel::Migration::Dsl, BaseSecondaryIndex
- Defined in:
- lib/dynamodb_model/migration/common.rb
Instance Method Summary collapse
-
#adjust_schema_and_attributes(identifier, key_type) ⇒ Object
Parameters: identifier: “id:string” or “id” key_type: “hash” or “range”.
-
#partition_key(identifier) ⇒ Object
docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Types/KeySchemaElement.html partition_key is required.
-
#provisioned_throughput(*params) ⇒ Object
t.provisioned_throughput(5) # both t.provisioned_throughput(:read, 5) t.provisioned_throughput(:write, 5) t.provisioned_throughput(:both, 5).
-
#sort_key(identifier) ⇒ Object
sort_key is optional.
Instance Method Details
#adjust_schema_and_attributes(identifier, key_type) ⇒ Object
Parameters:
identifier: "id:string" or "id"
key_type: "hash" or "range"
Adjusts the parameters for create_table to add the partition_key and sort_key
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dynamodb_model/migration/common.rb', line 24 def adjust_schema_and_attributes(identifier, key_type) name, attribute_type = identifier.split(':') attribute_type = "string" if attribute_type.nil? partition_key = { attribute_name: name, key_type: key_type.upcase } @key_schema << partition_key attribute_definition = { attribute_name: name, attribute_type: DynamodbModel::ATTRIBUTE_TYPES[attribute_type] } @attribute_definitions << attribute_definition end |
#partition_key(identifier) ⇒ Object
docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Types/KeySchemaElement.html partition_key is required
7 8 9 10 |
# File 'lib/dynamodb_model/migration/common.rb', line 7 def partition_key(identifier) @partition_key_identifier = identifier # for later use. useful for conventional_index_name adjust_schema_and_attributes(identifier, "hash") end |
#provisioned_throughput(*params) ⇒ Object
t.provisioned_throughput(5) # both t.provisioned_throughput(:read, 5) t.provisioned_throughput(:write, 5) t.provisioned_throughput(:both, 5)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/dynamodb_model/migration/common.rb', line 45 def provisioned_throughput(*params) case params.size when 0 # reader method return @provisioned_throughput # early return when 1 # @provisioned_throughput_set_called useful for update_table # only provide a provisioned_throughput settings if explicitly called for update_table @provisioned_throughput_set_called = true arg = params[0] if arg.is_a?(Hash) # Case: # provisioned_throughput( # read_capacity_units: 10, # write_capacity_units: 10 # ) @provisioned_throughput = arg # set directly return # early return else # assume parameter is an Integer # Case: provisioned_throughput(10) capacity_type = :both capacity_units = arg end when 2 @provisioned_throughput_set_called = true # Case: provisioned_throughput(:read, 5) capacity_type, capacity_units = params end map = { read: :read_capacity_units, write: :write_capacity_units, } if capacity_type == :both @provisioned_throughput[map[:read]] = capacity_units @provisioned_throughput[map[:write]] = capacity_units else @provisioned_throughput[capacity_type] = capacity_units end end |
#sort_key(identifier) ⇒ Object
sort_key is optional
13 14 15 16 |
# File 'lib/dynamodb_model/migration/common.rb', line 13 def sort_key(identifier) @sort_key_identifier = identifier # for later use. useful for conventional_index_name adjust_schema_and_attributes(identifier, "range") end |