Class: Redmine::Plugin::Migrator

Inherits:
ActiveRecord::Migrator
  • Object
show all
Defined in:
lib/redmine/plugin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.current_version(plugin = current_plugin) ⇒ Object


477
478
479
480
481
482
# File 'lib/redmine/plugin.rb', line 477

def current_version(plugin=current_plugin)
  # Delete migrations that don't match .. to_i will work because the number comes first
  ::ActiveRecord::Base.connection.select_values(
    "SELECT version FROM #{schema_migrations_table_name}"
  ).delete_if{ |v| v.match(/-#{plugin.id}/) == nil }.map(&:to_i).max || 0
end

.migrate_plugin(plugin, version) ⇒ Object

Runs the migrations from a plugin, up (or down) to the version given


471
472
473
474
475
# File 'lib/redmine/plugin.rb', line 471

def migrate_plugin(plugin, version)
  self.current_plugin = plugin
  return if current_version(plugin) == version
  migrate(plugin.migration_directory, version)
end

Instance Method Details

#migratedObject


485
486
487
488
489
490
# File 'lib/redmine/plugin.rb', line 485

def migrated
  sm_table = self.class.schema_migrations_table_name
  ::ActiveRecord::Base.connection.select_values(
    "SELECT version FROM #{sm_table}"
  ).delete_if{ |v| v.match(/-#{current_plugin.id}/) == nil }.map(&:to_i).sort
end

#record_version_state_after_migrating(version) ⇒ Object


492
493
494
# File 'lib/redmine/plugin.rb', line 492

def record_version_state_after_migrating(version)
  super(version.to_s + "-" + current_plugin.id.to_s)
end