Class: DataMapper::AutoMigrator

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-core/auto_migrations.rb

Class Method Summary collapse

Class Method Details

.auto_migrate(repository_name = nil, *descendants) ⇒ Object

Destructively automigrates the data-store to match the model. First migrates all models down and then up. REPEAT: THIS IS DESTRUCTIVE

Parameters:

  • Symbol

    repository_name the repository to be migrated



11
12
13
14
# File 'lib/dm-core/auto_migrations.rb', line 11

def self.auto_migrate(repository_name = nil, *descendants)
  auto_migrate_down(repository_name, *descendants)
  auto_migrate_up(repository_name, *descendants)
end

.auto_migrate_down(repository_name = nil, *descendants) ⇒ 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 automigrates the data-store down REPEAT: THIS IS DESTRUCTIVE

Parameters:

  • Symbol

    repository_name the repository to be migrated



23
24
25
26
27
28
# File 'lib/dm-core/auto_migrations.rb', line 23

def self.auto_migrate_down(repository_name = nil, *descendants)
  descendants = DataMapper::Resource.descendants.to_a if descendants.empty?
  descendants.reverse.each do |model|
    model.auto_migrate_down!(repository_name)
  end
end

.auto_migrate_up(repository_name = nil, *descendants) ⇒ 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.

Automigrates the data-store up

Parameters:

  • Symbol

    repository_name the repository to be migrated



36
37
38
39
40
41
# File 'lib/dm-core/auto_migrations.rb', line 36

def self.auto_migrate_up(repository_name = nil, *descendants)
  descendants = DataMapper::Resource.descendants.to_a if descendants.empty?
  descendants.each do |model|
    model.auto_migrate_up!(repository_name)
  end
end

.auto_upgrade(repository_name = nil) ⇒ Object

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

Parameters:

  • Symbol

    repository_name the repository to be migrated



49
50
51
52
53
# File 'lib/dm-core/auto_migrations.rb', line 49

def self.auto_upgrade(repository_name = nil)
  DataMapper::Resource.descendants.each do |model|
    model.auto_upgrade!(repository_name)
  end
end