Class: Redmine::Plugin::Migrator
- Inherits:
-
ActiveRecord::Migrator
- Object
- ActiveRecord::Migrator
- Redmine::Plugin::Migrator
- Defined in:
- lib/redmine/plugin.rb
Class Method Summary collapse
- .current_version(plugin = current_plugin) ⇒ Object
- .get_all_versions(plugin = current_plugin) ⇒ Object
-
.migrate_plugin(plugin, version) ⇒ Object
Runs the migrations from a plugin, up (or down) to the version given.
Instance Method Summary collapse
Class Method Details
.current_version(plugin = current_plugin) ⇒ Object
515 516 517 |
# File 'lib/redmine/plugin.rb', line 515 def current_version(plugin = current_plugin) get_all_versions(plugin).last || 0 end |
.get_all_versions(plugin = current_plugin) ⇒ Object
503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/redmine/plugin.rb', line 503 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
496 497 498 499 500 501 |
# File 'lib/redmine/plugin.rb', line 496 def migrate_plugin(plugin, version) self.current_plugin = plugin return if current_version(plugin) == version MigrationContext.new(plugin.migration_directory, ::ActiveRecord::Base.connection.schema_migration).migrate(version) end |
Instance Method Details
#load_migrated ⇒ Object
520 521 522 |
# File 'lib/redmine/plugin.rb', line 520 def load_migrated @migrated_versions = Set.new(self.class.get_all_versions(current_plugin)) end |
#record_version_state_after_migrating(version) ⇒ Object
524 525 526 |
# File 'lib/redmine/plugin.rb', line 524 def (version) super(version.to_s + "-" + current_plugin.id.to_s) end |