Class: Dynomite::Migration::Dsl::Index::Base

Inherits:
Object
  • Object
show all
Includes:
Types
Defined in:
lib/dynomite/migration/dsl/index/base.rb

Direct Known Subclasses

Gsi, Lsi

Constant Summary

Constants included from Types

Types::TYPE_MAP

Instance Method Summary collapse

Methods included from Types

#type_map

Instance Method Details

#conventional_index_nameObject



33
34
35
36
37
38
39
40
# File 'lib/dynomite/migration/dsl/index/base.rb', line 33

def conventional_index_name
  # DynamoDB requires index names to be at least 3 characters long, otherwise:
  #   Error: Unable to : 1 validation error detected: Value 'id' at 'globalSecondaryIndexes.1.member.indexName' failed to satisfy constraint: Member must have length greater than or equal to 3
  # The id valid is too short sadly.
  # Adding -index to the end of the index name is a safe way to ensure that.
  # Annoying that the index_name("id-index") is going to be a little longer.
  [partition_key_attribute_name, sort_key_attribute_name, 'index'].compact.join('-')
end

#get_attribute_name(field = :partition_key) ⇒ Object



13
14
15
16
# File 'lib/dynomite/migration/dsl/index/base.rb', line 13

def get_attribute_name(field=:partition_key)
  value = instance_variable_get("@#{field}") # IE: @partition_key
  value.to_s.split(':').first if value
end

#get_attribute_type(field = :partition_key) ⇒ Object



26
27
28
29
30
31
# File 'lib/dynomite/migration/dsl/index/base.rb', line 26

def get_attribute_type(field=:partition_key)
  value = instance_variable_get("@#{field}") # IE: @partition_key
  name, type = value.to_s.split(':')
  type ||= "string"
  type_map(type)
end

#partition_key_attribute_nameObject



5
6
7
# File 'lib/dynomite/migration/dsl/index/base.rb', line 5

def partition_key_attribute_name
  get_attribute_name(:partition_key)
end

#partition_key_attribute_typeObject



18
19
20
# File 'lib/dynomite/migration/dsl/index/base.rb', line 18

def partition_key_attribute_type
  get_attribute_type(:partition_key)
end

#sort_key_attribute_nameObject



9
10
11
# File 'lib/dynomite/migration/dsl/index/base.rb', line 9

def sort_key_attribute_name
  get_attribute_name(:sort_key)
end

#sort_key_attribute_typeObject



22
23
24
# File 'lib/dynomite/migration/dsl/index/base.rb', line 22

def sort_key_attribute_type
  get_attribute_type(:sort_key)
end