Module: Ronin::DB::Migrations

Defined in:
lib/ronin/db/migrations.rb

Overview

Handles migrating the database.

Constant Summary collapse

DIR =

Path to the db/migrate/ directory in ronin-db-activerecord.

File.expand_path('../../../db/migrate',__dir__)

Class Method Summary collapse

Class Method Details

.contextActiveRecord::MigrationContext

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.

The migration context.

Returns:

  • (ActiveRecord::MigrationContext)


118
119
120
# File 'lib/ronin/db/migrations.rb', line 118

def self.context
  @context ||= ActiveRecord::MigrationContext.new([DIR])
end

.current_versionInteger

The current migration version of the database.

Returns:

  • (Integer)


35
36
37
# File 'lib/ronin/db/migrations.rb', line 35

def self.current_version
  context.current_version
end

.down(target_version = nil, &block) ⇒ Object

Explicitly migrates down the database to the target version.

Parameters:

  • target_version (Integer, nil) (defaults to: nil)

    The desired target version.



80
81
82
# File 'lib/ronin/db/migrations.rb', line 80

def self.down(target_version=nil,&block)
  context.down(target_version,&block)
end

.foreward(steps = 1) ⇒ Object

Applies the next number of migrations.

Parameters:

  • steps (Integer) (defaults to: 1)

    The number of migrations to rollback.



104
105
106
# File 'lib/ronin/db/migrations.rb', line 104

def self.foreward(steps=1)
  context.foreward(steps)
end

.migrate(target_version = nil) ⇒ Object

Migrates the database to the target version.

Parameters:

  • target_version (Integer, nil) (defaults to: nil)

    The desired target version.



56
57
58
# File 'lib/ronin/db/migrations.rb', line 56

def self.migrate(target_version=nil)
  context.migrate(target_version)
end

.needs_migration?Boolean

Determines if the database needs migrating up.

Returns:

  • (Boolean)


44
45
46
# File 'lib/ronin/db/migrations.rb', line 44

def self.needs_migration?
  context.needs_migration?
end

.rollback(steps = 1) ⇒ Object

Rollbacks the last number of migrations.

Parameters:

  • steps (Integer) (defaults to: 1)

    The number of migrations to rollback.



92
93
94
# File 'lib/ronin/db/migrations.rb', line 92

def self.rollback(steps=1)
  context.rollback(steps)
end

.up(target_version = nil, &block) ⇒ Object

Explicitly migrates up the database to the target version.

Parameters:

  • target_version (Integer, nil) (defaults to: nil)

    The desired target version.



68
69
70
# File 'lib/ronin/db/migrations.rb', line 68

def self.up(target_version=nil,&block)
  context.up(target_version,&block)
end