Module: Dynomite::Migration::Dsl::Index

Included in:
Dynomite::Migration::Dsl
Defined in:
lib/dynomite/migration/dsl/index.rb,
lib/dynomite/migration/dsl/index/gsi.rb,
lib/dynomite/migration/dsl/index/lsi.rb,
lib/dynomite/migration/dsl/index/base.rb

Defined Under Namespace

Classes: Base, Gsi, Lsi

Instance Method Summary collapse

Instance Method Details

#add_gsi(attrs = {}) ⇒ Object Also known as: create_gsi



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

def add_gsi(attrs={})
  attrs = normalize_index_attrs(attrs, :partition_key)
  @gsi_indexes << Gsi.new(:create, attrs) # store in @gsi_indexes for the parent Dsl to use
end

#add_lsi(attrs = {}) ⇒ Object Also known as: create_lsi



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

def add_lsi(attrs={})
  # dont need create with lsi indexes, they are created as part of create_table
  partition_key_name = @partition_key_identifier.split(':').first
  attrs = normalize_index_attrs(attrs, :sort_key)
  @lsi_indexes << Lsi.new(partition_key_name, attrs) # store in @lsi_indexes for the parent Dsl to use
end

#global_secondary_index_updatesObject

maps each gsi to the hash structure expected by dynamodb update_table under the global_secondary_index_updates key:

{ create: {...} }
{ update: {...} }
{ delete: {...} }


66
67
68
69
70
# File 'lib/dynomite/migration/dsl/index.rb', line 66

def global_secondary_index_updates
  @gsi_indexes.map do |gsi|
    { gsi.action => gsi.params }
  end
end

#gsi_secondary_index_createsObject

maps each lsi to the hash structure expected by dynamodb update_table under the gsi_secondary_index_creates key:

{ create: {...} }
{ update: {...} }
{ delete: {...} }


54
55
56
57
58
# File 'lib/dynomite/migration/dsl/index.rb', line 54

def gsi_secondary_index_creates
  @gsi_indexes.map do |gsi|
    gsi.params
  end
end

#lsi_secondary_index_createsObject

maps each lsi to the hash structure expected by dynamodb update_table under the lsi_secondary_index_creates key:

{ create: {...} }
{ update: {...} }
{ delete: {...} }


42
43
44
45
46
# File 'lib/dynomite/migration/dsl/index.rb', line 42

def lsi_secondary_index_creates
  @lsi_indexes.map do |lsi|
    lsi.params
  end
end

#normalize_index_attrs(attrs, type = :partition_key) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/dynomite/migration/dsl/index.rb', line 28

def normalize_index_attrs(attrs, type=:partition_key)
  if attrs.is_a?(String) || attrs.is_a?(Symbol)
    {type => attrs.to_s}
  else
    attrs
  end
end

#remove_gsi(attrs = {}) ⇒ Object Also known as: delete_gsi



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

def remove_gsi(attrs={})
  attrs = normalize_index_attrs(attrs, :partition_key)
  @gsi_indexes << Gsi.new(:delete, attrs) # store in @gsi_indexes for the parent Dsl to use
end

#update_gsi(attrs = {}) ⇒ Object



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

def update_gsi(attrs={})
  attrs = normalize_index_attrs(attrs, :partition_key)
  @gsi_indexes << Gsi.new(:update, attrs) # store in @gsi_indexes for the parent Dsl to use
end