Class: Redmine::Plugin::Migrator

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

Overview

Since:

  • 2.0.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.current_version(plugin = current_plugin) ⇒ Object



545
546
547
# File 'lib/redmine/plugin.rb', line 545

def current_version(plugin = current_plugin)
  get_all_versions(plugin).last || 0
end

.get_all_versions(plugin = current_plugin) ⇒ Object

Since:

  • 4.0.0



533
534
535
536
537
538
539
540
541
542
543
# File 'lib/redmine/plugin.rb', line 533

def get_all_versions(plugin = current_plugin)
  # Delete migrations that don't match .. to_i will work because the number comes first
  @all_versions ||= {}
  @all_versions[plugin.id.to_s] ||= begin
    sm_table = ::ActiveRecord::SchemaMigration.table_name
    migration_versions  = ActiveRecord::Base.connection.select_values("SELECT version FROM #{sm_table}")
    versions_by_plugins = migration_versions.group_by { |version| version.match(/-(.*)$/).try(:[], 1) }
    @all_versions       = versions_by_plugins.transform_values! {|versions| versions.map!(&:to_i).sort! }
    @all_versions[plugin.id.to_s] || []
  end
end

.migrate_plugin(plugin, version) ⇒ Object

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



526
527
528
529
530
531
# File 'lib/redmine/plugin.rb', line 526

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

  MigrationContext.new(plugin.migration_directory).migrate(version)
end

Instance Method Details

#load_migratedObject

Since:

  • 4.0.0



550
551
552
# File 'lib/redmine/plugin.rb', line 550

def load_migrated
  @migrated_versions = Set.new(self.class.get_all_versions(current_plugin))
end

#record_version_state_after_migrating(version) ⇒ Object



554
555
556
# File 'lib/redmine/plugin.rb', line 554

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