Method: Mara::Table.prepare_table!

Defined in:
lib/mara/table.rb

.prepare_table!(table_params, envs, wait) ⇒ true, false

Prepare the table with extra options.

Parameters:

  • table_params (Hash)

    DynamoDB create table params hash.

  • envs (Array<String>)

    The environments that are allowed to check if this action is allowed.

  • wait (true, false)

    Should this function wait for the table to become fully available before returning.

Returns:

  • (true, false)

Since:

  • 1.0.0



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mara/table.rb', line 68

def prepare_table!(table_params, envs, wait)
  env =  Mara.config.env
  unless Array(envs).include?(env)
    raise ArgumentError, "Can't prepare table outside of #{envs.join('/')}"
  end

  table_name = table_params.fetch(:table_name,  Mara.config.dynamodb.table_name)

  if table_exists?(table_name)
    return true
  end

  table_params = normalize_table_params(table_params, table_name)

  log(" Mara create_table(\"#{table_name}\")")

   Mara::Client.shared.create_table(table_params)
   Mara::Client.shared.wait_until(:table_exists, table_name: table_name) if wait

  true
end