Module: DataMapper::AutoMigrations

Defined in:
lib/dm-core/auto_migrations.rb

Overview

class AutoMigrator

Instance Method Summary collapse

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:

  • Symbol

    repository_name the repository to be migrated



62
63
64
65
# File 'lib/dm-core/auto_migrations.rb', line 62

def auto_migrate!(repository_name = self.repository_name)
  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:

  • Symbol

    repository_name the repository to be migrated



74
75
76
77
78
79
# File 'lib/dm-core/auto_migrations.rb', line 74

def auto_migrate_down!(repository_name = self.repository_name)
  # repository_name ||= default_repository_name
  repository(repository_name) do |r|
    r.adapter.destroy_model_storage(r, self.base_model)
  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:

  • Symbol

    repository_name the repository to be migrated



86
87
88
89
90
# File 'lib/dm-core/auto_migrations.rb', line 86

def auto_migrate_up!(repository_name = self.repository_name)
  repository(repository_name) do |r|
    r.adapter.create_model_storage(r, self.base_model)
  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:

  • Symbol

    repository_name the repository to be migrated



97
98
99
100
101
# File 'lib/dm-core/auto_migrations.rb', line 97

def auto_upgrade!(repository_name = self.repository_name)
  repository(repository_name) do |r|
    r.adapter.upgrade_model_storage(r, self)
  end
end