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
544 545 546 |
# File 'lib/redmine/plugin.rb', line 544 def current_version(plugin = current_plugin) get_all_versions(plugin).last || 0 end |
.get_all_versions(plugin = current_plugin) ⇒ Object
532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/redmine/plugin.rb', line 532 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::Base.connection.pool.schema_migration.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
525 526 527 528 529 530 |
# File 'lib/redmine/plugin.rb', line 525 def migrate_plugin(plugin, version) self.current_plugin = plugin return if current_version(plugin) == version MigrationContext.new(plugin.migration_directory, ::ActiveRecord::Base.connection.pool.schema_migration).migrate(version) end |
Instance Method Details
#load_migrated ⇒ Object
549 550 551 |
# File 'lib/redmine/plugin.rb', line 549 def load_migrated @migrated_versions = Set.new(self.class.get_all_versions(current_plugin)) end |
#record_version_state_after_migrating(version) ⇒ Object
553 554 555 |
# File 'lib/redmine/plugin.rb', line 553 def (version) super(version.to_s + "-" + current_plugin.id.to_s) end |