Class: Dynomite::Migration::Dsl::Index::Lsi

Inherits:
Base
  • Object
show all
Defined in:
lib/dynomite/migration/dsl/index/lsi.rb

Constant Summary

Constants included from Types

Types::TYPE_MAP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#conventional_index_name, #get_attribute_name, #get_attribute_type, #partition_key_attribute_name, #partition_key_attribute_type, #sort_key_attribute_name, #sort_key_attribute_type

Methods included from Types

#type_map

Constructor Details

#initialize(partition_key_name, attrs) ⇒ Lsi

Returns a new instance of Lsi.



4
5
6
7
8
9
# File 'lib/dynomite/migration/dsl/index/lsi.rb', line 4

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

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



3
4
5
# File 'lib/dynomite/migration/dsl/index/lsi.rb', line 3

def attrs
  @attrs
end

Instance Method Details

#attribute_definitionsObject



20
21
22
23
24
25
# File 'lib/dynomite/migration/dsl/index/lsi.rb', line 20

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

#paramsObject



11
12
13
14
15
16
17
18
# File 'lib/dynomite/migration/dsl/index/lsi.rb', line 11

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