Sha256: f3155a88510bdd80f3caa217bdd3b125561ad5afc8f38cb6efff7c84637fe08c

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Dynomite::Migration::Dsl::Index
  class Lsi < Base
    attr_reader :attrs
    def initialize(partition_key_name, attrs)
      @partition_key_name = partition_key_name
      @params = attrs.dup
      # Delete the special DSL keys. Keep the rest and pass through to AWS create_table or update_table
      @sort_key = @params.delete(:sort_key) || @params.delete(:range_key) # require for LSI index since it must be a composite key
    end

    def params
      @params[:key_schema] ||= []
      @params[:key_schema] << {attribute_name: @partition_key_name, key_type: "HASH"}
      @params[:key_schema] << {attribute_name: sort_key_attribute_name, key_type: "RANGE"}
      @params[:index_name] ||= conventional_index_name
      @params[:projection] ||= {projection_type: "ALL"}
      @params
    end

    def attribute_definitions
      definitions = []
      definitions << {attribute_name: partition_key_attribute_name, attribute_type: partition_key_attribute_type} unless @partition_key.blank?
      definitions << {attribute_name: sort_key_attribute_name, attribute_type: sort_key_attribute_type} unless @sort_key.blank?
      definitions
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dynomite-2.0.3 lib/dynomite/migration/dsl/index/lsi.rb
dynomite-2.0.2 lib/dynomite/migration/dsl/index/lsi.rb
dynomite-2.0.1 lib/dynomite/migration/dsl/index/lsi.rb
dynomite-2.0.0 lib/dynomite/migration/dsl/index/lsi.rb