Module: Dynamoid::Tasks::Database

Defined in:
lib/dynamoid/tasks/database.rb

Class Method Summary collapse

Class Method Details

.create_tablesObject

Create any new tables for the models. Existing tables are not modified.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dynamoid/tasks/database.rb', line 11

def create_tables
  results = { created: [], existing: [] }
  # We can't quite rely on Dynamoid.included_models alone, we need to select only viable models
  Dynamoid.included_models.reject { |m| m.base_class.try(:name).blank? }.uniq(&:table_name).each do |model|
    if Dynamoid.adapter.list_tables.include? model.table_name
      results[:existing] << model.table_name
    else
      model.create_table(sync: true)
      results[:created] << model.table_name
    end
  end
  results
end

.pingObject

Is the DynamoDB reachable?



26
27
28
29
# File 'lib/dynamoid/tasks/database.rb', line 26

def ping
  Dynamoid.adapter.list_tables
  true
end