Method: DataMapper::Persevere::Migrations#create_model_storage

Defined in:
lib/persevere_adapter/migrations.rb

#create_model_storage(model) ⇒ Object

Creates the persevere schema from the model.

Parameters:

  • model (DataMapper::Model)

    The model that corresponds to the storage schema that needs to be created.

[View source]

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/persevere_adapter/migrations.rb', line 27

def create_model_storage(model)
  model = Persevere.enhance(model)
  name       = self.name
  properties = model.properties_with_subclasses(name)
  
  return false if storage_exists?(model.storage_name(name))
  return false if properties.empty?

  # Make sure storage for referenced objects exists
  model.relationships.each_pair do |n, r|
    if ! storage_exists?(r.child_model.storage_name)
      put_schema({'id' => r.child_model.storage_name, 'properties' => {}})
    end
  end
  schema_hash = model.to_json_schema_hash()
  
  return true unless put_schema(schema_hash) == false
  false
end