Defect #36766

Database migration from Redmine 0.8.7 or earlier fails

Added by Bernhard Kotzur 5 months ago. Updated 5 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Database
Target version:4.1.7
Resolution:Fixed Affected version:4.1.1

Description

After import mysqldump from the old environment to get all the data and copy the files into the new environment and run
bundle exec rake db:migrate RAILS_ENV=production I got te following error:

== 20090503121505 PopulateMemberRoles: migrating ==============================
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

undefined method `inherit_members?' for #<Project:0x0000000005a426a8>
/opt/rh/rh-ruby25/root/usr/share/gems/gems/activemodel-5.2.4.2/lib/active_model/attribute_methods.rb:430:in `method_missing'
/data/redmine/sf-redmine_redmine-4.1.1/app/models/member_role.rb:72:in `block in add_role_to_subprojects'

Please see details in the attached file.

Environment:
  Redmine version                4.1.1.stable
  Ruby version                   2.5.9-p229 (2021-04-05) [x86_64-linux]
  Rails version                  5.2.4.2
  Environment                    production
  Database adapter               Mysql2
  Mailer queue                   ActiveJob::QueueAdapters::AsyncAdapter
  Mailer delivery                smtp
SCM:
  Subversion                     1.7.14
  Git                            1.8.3.1
  Filesystem
Redmine plugins:
  no plugin installed

MySQL Server version: 5.5.52 MySQL Community Server (GPL)

-------------

Old Environment
Redmine 0.8.7.stable (MySQL)
Server version: 5.0.83-community-log MySQL Community Edition (GPL)

redmine_ERROR.txt Magnifier - redmine_error_trace_file (43.1 KB) Bernhard Kotzur, 2022-03-15 17:30

36766.patch Magnifier (591 Bytes) Go MAEDA, 2022-03-16 15:21


Related issues

Related to Redmine - Defect #19174: db migrate error from old version to 2.6 Needs feedback

Associated revisions

Revision 21461
Added by Go MAEDA 5 months ago

Database migration from Redmine 0.8.7 or earlier fails (#36766).

Patch by Go MAEDA.

Revision 21476
Added by Go MAEDA 5 months ago

Merged r21461 from trunk to 4.2-stable (#36766).

Revision 21477
Added by Go MAEDA 5 months ago

Merged r21461 from trunk to 4.1-stable (#36766).

History

#1 Updated by C S 5 months ago

Hi there,
Unfortunately, I can't help you directly, but my approach to problems like this is to try not to upgrade in such big steps. I would try upgrading to version 1.2 first... https://www.redmine.org/projects/redmine/wiki/RedmineUpgrade/46

#2 Updated by Go MAEDA 5 months ago

  • Related to Defect #19174: db migrate error from old version to 2.6 added

#3 Updated by Go MAEDA 5 months ago

Could you check if changing app/models/member_role.rb as follows fixes the problem?

Index: app/models/member_role.rb
===================================================================
--- app/models/member_role.rb    (リビジョン 21454)
+++ app/models/member_role.rb    (作業コピー)
@@ -69,7 +69,7 @@

   def add_role_to_subprojects
     member.project.children.each do |subproject|
-      if subproject.inherit_members?
+      if subproject.try(:inherit_members?)
         child_member = Member.find_or_new(subproject.id, member.user_id)
         child_member.member_roles << MemberRole.new(:role => role, :inherited_from => id)
         child_member.save!

#4 Updated by Go MAEDA 5 months ago

The reason the error occurs is that when executing migration 20090503121505_populate_member_roles.rb, the callback for the MemberRole model attempts to access columns in the projects table that are created in later migrations.

The problem can be fixed by replacing Member.create! with Member.insert! in the migration to avoid extra callback execution.

#5 Updated by Bernhard Kotzur 5 months ago

Hello Go MAEDA,

first thank you very much for your support!

Changing the app/models/member_role.rb as described above fixes the problem.
I was able to migrate the db without any further errors.

Now I see you provide a 36766.patch for this issue.
What is the best way for further migrations? Apply the 36766.patch or edit the app/models/member_role.rb file or both?

Thanks in advance.

#6 Updated by Go MAEDA 5 months ago

Bernhard Kotzur wrote:

Now I see you provide a 36766.patch for this issue.
What is the best way for further migrations? Apply the 36766.patch or edit the app/models/member_role.rb file or both?

Applying the 36766.patch is better. That is the fundamental measure. Changes for app/models/member_role.rb is just a quick workaround.

#7 Updated by Go MAEDA 5 months ago

  • Subject changed from db migrate error from 0.8.7 version to 4.1.1 to Database migration from Redmine 0.8.7 or earlier fails
  • Target version set to 4.1.7

Setting the target version to 4.1.7.

#8 Updated by Go MAEDA 5 months ago

  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

#9 Updated by Marius BALTEANU 5 months ago

  • Description updated (diff)

#10 Updated by Go MAEDA 5 months ago

  • Status changed from Resolved to Closed

Committed the fix.

Also available in: Atom PDF