From 6b36cd0f701c08b9969e7a27d94ef7f943c34cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Codru=C8=9B=20Constantin=20Gu=C8=99oi?= Date: Wed, 27 Mar 2019 23:07:50 +0000 Subject: [PATCH] Fixes plugin migration with specific version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Codruț Constantin Gușoi --- lib/redmine/plugin.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index 4de7c4386..64bb761b9 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -515,6 +515,19 @@ module Redmine def open Migrator.new(:up, migrations, nil) end + + def migrate(target_version = nil, current_version = nil) + case + when target_version.nil? + up(target_version) + when current_version == 0 && target_version == 0 + [] + when current_version && current_version > target_version + down(target_version) + else + up(target_version) + end + end end class Migrator < ActiveRecord::Migrator @@ -525,9 +538,10 @@ module Redmine # Runs the migrations from a plugin, up (or down) to the version given def migrate_plugin(plugin, version) self.current_plugin = plugin - return if current_version(plugin) == version + current = current_version(plugin) + return if current == version - MigrationContext.new(plugin.migration_directory).migrate(version) + MigrationContext.new(plugin.migration_directory).migrate(version, current) end def get_all_versions(plugin = current_plugin) -- 2.21.0