Defect #31116

Database migrations don't run correctly for plugins when specifying the `VERSION` env variable

Added by Codruț Gușoi about 1 month ago. Updated about 1 month ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Plugin API
Target version:Candidate for next major release
Resolution: Affected version:4.0.2

Description

tl;dr: When comparing versions, the current_version is set to the core's latest migration instead of the plugin's latest.

Steps to reproduce:

1. Install any plugin with migrations, for example:

cd redmine/plugins
git clone https://github.com/ixti/redmine_tags.git

bundle install
rake redmine:plugins:migrate NAME=redmine_tags

2. Undo the last migration of that plugin:

rake redmine:plugins:migrate NAME=redmine_tags VERSION=20151209153801

3. Migrate to the latest version again, but specifying the version this time:

rake redmine:plugins:migrate NAME=redmine_tags VERSION=20180122193833

Expected behaviour: the 20180122193833 migration is executed.
Actual behaviour: the 20180122193833 is not executed.

This is because redmine core's latest migration is 20180923091603 which is greather that the plugin's 20180122193833.

The attached fix defines a `migrate` method for the `Redmine::Plugin::MigrationContext` class that makes sure to pass along the current plugin's latest migration. Using the default migrate method defined in activerecord executes a `current_version` that looks for the most current migration in the list of all migrations (core and plugins).

Note: I have not run any tests with this patch.

0001-Fixes-plugin-migration-with-specific-version.patch Magnifier (1.75 KB) Codruț Gușoi, 2019-03-28 23:51

redmine-4.0.2.plugin-upgrade.patch Magnifier (1.47 KB) Martijn Vernooij, 2019-04-17 17:47

History

#1 Updated by Codruț Gușoi about 1 month ago

Test run available here: https://gitlab.com/sdwolfz/redmine/-/jobs/187237412

Although... I am not sure how to add a test that checks for this exact error.

#2 Updated by Go MAEDA about 1 month ago

  • Category set to Plugin API
  • Target version set to Candidate for next major release

#3 Updated by Martijn Vernooij about 1 month ago

I noticed the same issue (with 4.0.2 though) and 'fixed' it another way.

Also available in: Atom PDF