Module: Mack::Database::Migrations
- Defined in:
- lib/mack-data_mapper/database_migrations.rb
Class Method Summary collapse
- .abort_if_pending_migrations ⇒ Object
-
.migrate ⇒ Object
Migrates the database to the latest version.
-
.rollback(step = 1) ⇒ Object
Rolls back the database by the specified number of steps.
Class Method Details
.abort_if_pending_migrations ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/mack-data_mapper/database_migrations.rb', line 25 def self.abort_if_pending_migrations migration_files.each { |mig| load mig } ::DataMapper::MigrationRunner.migrations.each do |mig| raise Mack::Errors::UnrunMigrations.new(mig.name) if mig.send("needs_up?") end ::DataMapper::MigrationRunner.migrations.clear end |
.migrate ⇒ Object
Migrates the database to the latest version
8 9 10 11 12 13 |
# File 'lib/mack-data_mapper/database_migrations.rb', line 8 def self.migrate # Mack::Database.establish_connection ::DataMapper::MigrationRunner.reset! migration_files.each { |mig| load mig } ::DataMapper::MigrationRunner.migrate_up! end |
.rollback(step = 1) ⇒ Object
Rolls back the database by the specified number of steps. Default is 1
16 17 18 19 20 21 22 23 |
# File 'lib/mack-data_mapper/database_migrations.rb', line 16 def self.rollback(step = 1) ::DataMapper::MigrationRunner.reset! migration_files.each { |mig| load mig } migrations = ::DataMapper::MigrationRunner.migrations.sort.reverse step.times do |i| migrations[migrations.size - (i + 1)].perform_down end end |