lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
# Create a table on DynamoDB. This usually takes a long time to complete.
#
# @param [String] table_name the name of the table to create
# @param [Symbol] key the table's primary key (defaults to :id)
# @param [Hash] options provide a range key here if the table has a composite key
#
# @since 1.0.0
Create a table on DynamoDB. This usually takes a long time to complete.
Create a table on DynamoDB . This usually takes a long time to complete .
def create_table(table_name, key = :id, options = {})
        Dynamoid.logger.info "Creating #{table_name} table. This could take a while."
        read_capacity = options[:read_capacity] || Dynamoid::Config.read_capacity
        write_capacity = options[:write_capacity] || Dynamoid::Config.write_capacity
        range_key = options[:range_key]
        key_schema = [
          { attribute_name: key.to_s, key_type: HASH_KEY }
        ]
        key_schema << {
          attribute_name: range_key.keys.first.to_s, key_type: RANGE_KEY
        } if(range_key)
        attribute_definitions = [
          { attribute_name: key.to_s, attribute_type: 'S' }
        ]
        attribute_definitions << {
          attribute_name: range_key.keys.first.to_s, attribute_type: api_type(range_key.values.first)
        } if(range_key)
        client.create_table(table_name: table_name,
          provisioned_throughput: {
            read_capacity_units: read_capacity,
            write_capacity_units: write_capacity
          },
          key_schema: key_schema,
          attribute_definitions: attribute_definitions
        )
      rescue Aws::DynamoDB::Errors::ResourceInUseException => e
        Dynamoid.logger.error "Table #{table_name} cannot be created as it already exists"
      end
def create_table ( table_name , key = :id , options = { } ) Dynamoid . logger . info "Creating #{table_name} table. This could take a while." read_capacity = options [ :read_capacity ] || Dynamoid :: Config . read_capacity write_capacity = options [ :write_capacity ] || Dynamoid :: Config . write_capacity range_key = options [ :range_key ] key_schema = [ { attribute_name : key . to_s , key_type : HASH_KEY } ] key_schema << { attribute_name : range_key . keys . first . to_s , key_type : RANGE_KEY } if ( range_key ) attribute_definitions = [ { attribute_name : key . to_s , attribute_type : 'S' } ] attribute_definitions << { attribute_name : range_key . keys . first . to_s , attribute_type : api_type ( range_key . values . first ) } if ( range_key ) client . create_table ( table_name : table_name , provisioned_throughput : { read_capacity_units : read_capacity , write_capacity_units : write_capacity } , key_schema : key_schema , attribute_definitions : attribute_definitions ) rescue Aws :: DynamoDB :: Errors :: ResourceInUseException => e Dynamoid . logger . error "Table #{table_name} cannot be created as it already exists" end
Create a table on DynamoDB.
Create a table on DynamoDB .
#TODO: Provide support for number and binary hash key
table_name
key
options
options provide a range key here if the table has a composite key
options provide a range key here if the table has a composite key
since
None