]> source.dussan.org Git - redmine.git/commitdiff
Database migrations don't run correctly for plugins when specifying the `VERSION...
authorGo MAEDA <maeda@farend.jp>
Sun, 30 Oct 2022 06:26:02 +0000 (06:26 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 30 Oct 2022 06:26:02 +0000 (06:26 +0000)
Contributed by crypto gopher.

git-svn-id: https://svn.redmine.org/redmine/trunk@21933 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/plugin.rb
test/unit/lib/redmine/plugin_test.rb

index fb42a8fa98c6f54c66cf94d2daa4a95a3b6c7df9..78eee1e7ff17ae862753e84386b11ea3193e4970 100644 (file)
@@ -485,6 +485,10 @@ module Redmine
       def open
         Migrator.new(:up, migrations, schema_migration)
       end
+
+      def current_version
+        Migrator.current_version
+      end
     end
 
     class Migrator < ActiveRecord::Migrator
index a5a1b2aa3102eda6ba381b7d555534e0b5800cc5..24c06240c3e333fd18e7705008a9b6a452b0cc65 100644 (file)
@@ -217,4 +217,17 @@ class Redmine::PluginTest < ActiveSupport::TestCase
 
     assert Redmine::Plugin.migrate('foo_plugin')
   end
+
+  def test_migration_context_should_override_current_version
+    plugin = @klass.register :foo_plugin do
+      name 'Foo plugin'
+      version '0.0.1'
+    end
+    migration_dir = File.join(@klass.directory, 'db', 'migrate')
+
+    Redmine::Plugin::Migrator.current_plugin = plugin
+    context = Redmine::Plugin::MigrationContext.new(migration_dir, ::ActiveRecord::Base.connection.schema_migration)
+    # current_version should be zero because Foo plugin has no migration
+    assert_equal 0, context.current_version
+  end
 end