https://www.redmine.org/https://www.redmine.org/favicon.ico?16793021292019-03-30T10:28:08ZRedmineRedmine - Defect #31116: Database migrations don't run correctly for plugins when specifying the `VERSION` env variablehttps://www.redmine.org/issues/31116?journal_id=910112019-03-30T10:28:08ZAnonymous
<ul></ul><p>Test run available here: <a class="external" href="https://gitlab.com/sdwolfz/redmine/-/jobs/187237412">https://gitlab.com/sdwolfz/redmine/-/jobs/187237412</a></p>
<p>Although... I am not sure how to add a test that checks for this exact error.</p> Redmine - Defect #31116: Database migrations don't run correctly for plugins when specifying the `VERSION` env variablehttps://www.redmine.org/issues/31116?journal_id=910242019-03-31T05:06:37ZGo MAEDA
<ul><li><strong>Category</strong> set to <i>Plugin API</i></li><li><strong>Target version</strong> set to <i>Candidate for next major release</i></li></ul> Redmine - Defect #31116: Database migrations don't run correctly for plugins when specifying the `VERSION` env variablehttps://www.redmine.org/issues/31116?journal_id=912322019-04-17T15:49:12ZMartijn Vernooij
<ul><li><strong>File</strong> <a href="/attachments/22814">redmine-4.0.2.plugin-upgrade.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/22814/redmine-4.0.2.plugin-upgrade.patch">redmine-4.0.2.plugin-upgrade.patch</a> added</li></ul><p>I noticed the same issue (with 4.0.2 though) and 'fixed' it another way.</p> Redmine - Defect #31116: Database migrations don't run correctly for plugins when specifying the `VERSION` env variablehttps://www.redmine.org/issues/31116?journal_id=1079382022-09-19T00:30:15Zcrypto gopher
<ul><li><strong>File</strong> <a href="/attachments/29690">MigrationContext-current_version.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/29690/MigrationContext-current_version.patch">MigrationContext-current_version.patch</a> added</li></ul><p>The problem stems from fact, that <code>Redmine::Plugin::MigrationContext</code> does not override <code>current_version()</code> method. So whenever <code>ActiveRecord::MigrationContext.migrate()</code> is executed, it calls <code>ActiveRecord::MigrationContext.current_version()</code> which does not differentiate between Redmine's migrations and plugin's migrations - yielding erroneous result.</p>
<p>The most straightforward change is to override <code>ActiveRecord::MigrationContext.migrate()</code> by using <code>Redmine::Plugin::Migrator.current_version()</code> which already provides required functionality:</p>
<pre>
class MigrationContext < ActiveRecord::MigrationContext
...
def current_version
Migrator.current_version
end
end
</pre> Redmine - Defect #31116: Database migrations don't run correctly for plugins when specifying the `VERSION` env variablehttps://www.redmine.org/issues/31116?journal_id=1079712022-09-21T03:29:42ZGo MAEDA
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Confirmed</i></li></ul> Redmine - Defect #31116: Database migrations don't run correctly for plugins when specifying the `VERSION` env variablehttps://www.redmine.org/issues/31116?journal_id=1079752022-09-21T04:52:00ZGo MAEDA
<ul></ul><p>crypto gopher wrote:</p>
<blockquote>
<p>The most straightforward change is to override <code>ActiveRecord::MigrationContext.migrate()</code> by using <code>Redmine::Plugin::Migrator.current_version()</code> which already provides required functionality:</p>
</blockquote>
<p>Thank you for posting the patch.</p>
<p>I wrote a test for your patch as follows. Do you think the following code tests the right way?</p>
<pre><code class="diff syntaxhl"><span class="gh">diff --git a/test/unit/lib/redmine/plugin_test.rb b/test/unit/lib/redmine/plugin_test.rb
index a5a1b2aa3..24c06240c 100644
</span><span class="gd">--- a/test/unit/lib/redmine/plugin_test.rb
</span><span class="gi">+++ b/test/unit/lib/redmine/plugin_test.rb
</span><span class="p">@@ -217,4 +217,17 @@</span> class Redmine::PluginTest < ActiveSupport::TestCase
assert Redmine::Plugin.migrate('foo_plugin')
end
<span class="gi">+
+ 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
</span> end
</pre></code></pre> Redmine - Defect #31116: Database migrations don't run correctly for plugins when specifying the `VERSION` env variablehttps://www.redmine.org/issues/31116?journal_id=1082192022-10-13T04:13:18ZGo MAEDA
<ul><li><strong>Target version</strong> changed from <i>Candidate for next major release</i> to <i>5.1.0</i></li></ul><p>Setting the target version to 5.1.0.</p> Redmine - Defect #31116: Database migrations don't run correctly for plugins when specifying the `VERSION` env variablehttps://www.redmine.org/issues/31116?journal_id=1084112022-10-30T06:26:20ZGo MAEDA
<ul><li><strong>Status</strong> changed from <i>Confirmed</i> to <i>Closed</i></li><li><strong>Assignee</strong> set to <i>Go MAEDA</i></li><li><strong>Resolution</strong> set to <i>Fixed</i></li></ul><p>Committed the patch. Thank you for your contribution.</p>