lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
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

        secondary_indexes = options.slice(
          :local_secondary_indexes,
          :global_secondary_indexes
        )
        ls_indexes = options[:local_secondary_indexes]
        gs_indexes = options[:global_secondary_indexes]

        key_schema = {
          :hash_key_schema => { key => (options[:hash_key_type] || :string) },
          :range_key_schema => options[:range_key]
        }
        attribute_definitions = build_all_attribute_definitions(
          key_schema,
          secondary_indexes
        )
        key_schema = aws_key_schema(
          key_schema[:hash_key_schema],
          key_schema[:range_key_schema]
        )

        client_opts = {
          table_name: table_name,
          provisioned_throughput: {
            read_capacity_units: read_capacity,
            write_capacity_units: write_capacity
          },
          key_schema: key_schema,
          attribute_definitions: attribute_definitions
        }

        if ls_indexes.present?
          client_opts[:local_secondary_indexes] = ls_indexes.map do |index|
            index_to_aws_hash(index)
          end
        end

        if gs_indexes.present?
          client_opts[:global_secondary_indexes] = gs_indexes.map do |index|
            index_to_aws_hash(index)
          end
        end
        client.create_table(client_opts)
      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. 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
# @option options [Array<Dynamoid::Indexes::Index>] local_secondary_indexes
# @option options [Array<Dynamoid::Indexes::Index>] global_secondary_indexes
# @option options [Symbol] hash_key_type The type of the hash 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
        secondary_indexes = options.slice(
          :local_secondary_indexes,
          :global_secondary_indexes
        )
        ls_indexes = options[:local_secondary_indexes]
        gs_indexes = options[:global_secondary_indexes]
        key_schema = {
          :hash_key_schema => { key => (options[:hash_key_type] || :string) },
          :range_key_schema => options[:range_key]
        }
        attribute_definitions = build_all_attribute_definitions(
          key_schema,
          secondary_indexes
        )
        key_schema = aws_key_schema(
          key_schema[:hash_key_schema],
          key_schema[:range_key_schema]
        )
        client_opts = {
          table_name: table_name,
          provisioned_throughput: {
            read_capacity_units: read_capacity,
            write_capacity_units: write_capacity
          },
          key_schema: key_schema,
          attribute_definitions: attribute_definitions
        }
        if ls_indexes.present?
          client_opts[:local_secondary_indexes] = ls_indexes.map do |index|
            index_to_aws_hash(index)
          end
        end
        if gs_indexes.present?
          client_opts[:global_secondary_indexes] = gs_indexes.map do |index|
            index_to_aws_hash(index)
          end
        end
        client.create_table(client_opts)
      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 secondary_indexes = options . slice ( :local_secondary_indexes , :global_secondary_indexes ) ls_indexes = options [ :local_secondary_indexes ] gs_indexes = options [ :global_secondary_indexes ] key_schema = { :hash_key_schema => { key => ( options [ :hash_key_type ] || :string ) } , :range_key_schema => options [ :range_key ] } attribute_definitions = build_all_attribute_definitions ( key_schema , secondary_indexes ) key_schema = aws_key_schema ( key_schema [ :hash_key_schema ] , key_schema [ :range_key_schema ] ) client_opts = { table_name : table_name , provisioned_throughput : { read_capacity_units : read_capacity , write_capacity_units : write_capacity } , key_schema : key_schema , attribute_definitions : attribute_definitions } if ls_indexes . present? client_opts [ :local_secondary_indexes ] = ls_indexes . map do | index | index_to_aws_hash ( index ) end end if gs_indexes . present? client_opts [ :global_secondary_indexes ] = gs_indexes . map do | index | index_to_aws_hash ( index ) end end client . create_table ( client_opts ) 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 .
table_name
key
options
hash_key_type The type of the hash key
hash_key_type The type of the hash key
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