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



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

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



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

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



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

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



499
500
501
# File 'lib/redmine/plugin.rb', line 499

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