diff options
author | Go MAEDA <maeda@farend.jp> | 2022-10-30 06:26:02 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2022-10-30 06:26:02 +0000 |
commit | a749a6dd83c26f3b242178821d0eb26a65c29899 (patch) | |
tree | f84c79efabc1237de4b8c53c6a606614fe883538 | |
parent | 783e986048041c34d7194e374002dc469919be3b (diff) | |
download | redmine-a749a6dd83c26f3b242178821d0eb26a65c29899.tar.gz redmine-a749a6dd83c26f3b242178821d0eb26a65c29899.zip |
Database migrations don't run correctly for plugins when specifying the `VERSION` env variable (#31116).
Contributed by crypto gopher.
git-svn-id: https://svn.redmine.org/redmine/trunk@21933 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | lib/redmine/plugin.rb | 4 | ||||
-rw-r--r-- | test/unit/lib/redmine/plugin_test.rb | 13 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index fb42a8fa9..78eee1e7f 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -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 diff --git a/test/unit/lib/redmine/plugin_test.rb b/test/unit/lib/redmine/plugin_test.rb index a5a1b2aa3..24c06240c 100644 --- a/test/unit/lib/redmine/plugin_test.rb +++ b/test/unit/lib/redmine/plugin_test.rb @@ -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 |