Module: DataMapper::Migrations::Model

Defined in:
lib/dm-migrations/auto_migration.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



110
111
112
# File 'lib/dm-migrations/auto_migration.rb', line 110

def self.included(mod)
  mod.descendants.each { |model| model.extend self }
end

Instance Method Details

#auto_migrate!(repository_name = self.repository_name) ⇒ Object

Destructively automigrates the data-store to match the model REPEAT: THIS IS DESTRUCTIVE

Parameters:

  • repository_name (Symbol) (defaults to: self.repository_name)

    the repository to be migrated



125
126
127
128
129
# File 'lib/dm-migrations/auto_migration.rb', line 125

def auto_migrate!(repository_name = self.repository_name)
  assert_valid(true)
  auto_migrate_down!(repository_name)
  auto_migrate_up!(repository_name)
end

#auto_migrate_down!(repository_name = self.repository_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Destructively migrates the data-store down, which basically deletes all the models. REPEAT: THIS IS DESTRUCTIVE

Parameters:

  • repository_name (Symbol) (defaults to: self.repository_name)

    the repository to be migrated



154
155
156
157
158
159
160
161
162
# File 'lib/dm-migrations/auto_migration.rb', line 154

def auto_migrate_down!(repository_name = self.repository_name)
  assert_valid(true)
  base_model = self.base_model
  if base_model == self
    repository(repository_name).destroy_model_storage(self)
  else
    base_model.auto_migrate_down!(repository_name)
  end
end

#auto_migrate_up!(repository_name = self.repository_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Auto migrates the data-store to match the model

Parameters:

  • repository_name (Symbol) (defaults to: self.repository_name)

    the repository to be migrated



169
170
171
172
173
174
175
176
177
# File 'lib/dm-migrations/auto_migration.rb', line 169

def auto_migrate_up!(repository_name = self.repository_name)
  assert_valid(true)
  base_model = self.base_model
  if base_model == self
    repository(repository_name).create_model_storage(self)
  else
    base_model.auto_migrate_up!(repository_name)
  end
end

#auto_upgrade!(repository_name = self.repository_name) ⇒ Object

Safely migrates the data-store to match the model preserving data already in the data-store

Parameters:

  • repository_name (Symbol) (defaults to: self.repository_name)

    the repository to be migrated



137
138
139
140
141
142
143
144
145
# File 'lib/dm-migrations/auto_migration.rb', line 137

def auto_upgrade!(repository_name = self.repository_name)
  assert_valid(true)
  base_model = self.base_model
  if base_model == self
    repository(repository_name).upgrade_model_storage(self)
  else
    base_model.auto_upgrade!(repository_name)
  end
end

#storage_exists?(repository_name = default_repository_name) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/dm-migrations/auto_migration.rb', line 115

def storage_exists?(repository_name = default_repository_name)
  repository(repository_name).storage_exists?(storage_name(repository_name))
end