Problem/Motivation

See #2748609: [meta] Preserving auto-increment IDs on migration is fragile and #2818155: Add comments to d6_file stating the conflicts with d6_user_picture_file. 6.x user pictures didn't have a record in file_managed - they were just on disk with magic naming. In 8.x they become managed files, but this means they need a new fid assigned.

Other file migrations try to preserve existing fids, which means there can be conflicts. This is a specific data-integrity issue that can happen without the involvement of incremental migrations at all.

Proposed resolution

Don't preserve file IDs when migrating from Drupal 6 to Drupal 7, since user pictures not having file IDs means it's not possible to map 1-1 anyway, and fids generally aren't referenced as URLs or similar.

(Old suggestion, not implemented):
1. Make sure the user picture migration runs last of all (pretty sure this already happens)
2. Set the autoincrement ID to a high number before the user picture migration runs, to give some space for other migrations to add existing IDs in the gap left.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch created an issue. See original summary.

catch’s picture

mikeryan’s picture

Set the autoincrement ID to a high number before the user picture migration runs, to give some space for other migrations to add existing IDs in the gap left.

In this instance, perhaps we could more simply set explicit fids as $max_existing_fid + SOME_FAIRLY_LARGE_CONSTANT?

quietone’s picture

Issue tags: +migrate-d6-d8
heddn’s picture

Assigned: Unassigned » heddn
Issue tags: +Needs tests

Discussed in the migrate weekly meeting. The proposed solution:

  • Need a failure test to demonstrate the issue now.
  • Remove the fid from the d6_file template.
  • Update the d6_file/d6_user_picture migration docs to denote the current state.

This should catch 98% of sites that don't really care what the FID is. In the rare condition that FIDs are important, then the site could easily turn on migration of the fids and figure out a solution for user pictures.

Assigning to myself to work on this.

catch’s picture

Priority: Major » Critical

Bumping this to independently critical since it's one of the last known data integrity issues with migrate.

heddn’s picture

Status: Active » Needs review
FileSize
1.52 KB

Still needs tests. But this gets the ball rolling.

Status: Needs review » Needs work

The last submitted patch, 7: 6_8_user_picture-2826047-7.patch, failed testing.

heddn’s picture

Status: Needs work » Needs review
FileSize
7.49 KB

Here's some tests.

Status: Needs review » Needs work

The last submitted patch, 10: 6_8_user_picture-2826047-10.patch, failed testing.

alexpott’s picture

Issue tags: +Triaged D8 critical

Discussed with @catch, @cilefen, @effulgentsia and @xjm. We agreed that this should be a critical issue since regardless of the experimental nature of migrate this is a data integrity issue that can result in data loss.

jofitz’s picture

Status: Needs work » Needs review
FileSize
1.12 KB
1.12 KB

Assuming the migration is working as it should (i.e. each file is migrated twice due to having a different uri the second time the d6_file migration is executed) and assuming I understand what should be happening (!), then I have adjusted MigrateFileTest to pass correctly. I have added comments to try and explain what is happening and why.

heddn’s picture

Assigned: heddn » Unassigned

Unassigning.

heddn’s picture

Status: Needs review » Needs work

re #13 it looks like your patch and interdiff are the same thing. I'm pretty sure you intended something different.

jofitz’s picture

Status: Needs work » Needs review
FileSize
1.12 KB
6.47 KB

Sorry, my git-fu was a little off yesterday. Here is what I meant to upload. :#

alexpott’s picture

  1. +++ b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php
    @@ -90,12 +90,15 @@ public function testFiles() {
    -    $file = File::load(2);
    +    // File 2, when migrated for the second time, is treated as a different file
    +    // (due to having a different uri this time) and is given fid 6.
    +    $file = File::load(6);
         $this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri());
    

    I think we should also test the map here. To should the before 2 maps to 2 and now 2 maps to 6.

  2. +++ b/core/modules/file/tests/src/Kernel/Migrate/d6/MigrateFileTest.php
    @@ -90,12 +90,15 @@ public function testFiles() {
    +    // File 6, created in static::migrateDumpAlter(), shares a path with
    +    // file 4, which means it should be skipped entirely. If it was migrated
    +    // then it would have an fid of 9.
    +    $this->assertNull(File::load(9));
    

    This test looks brittle - perhaps it is best test would be to count the number of files before and after the second migration run. Not sure.

  3. One thought is that if we do #2748609: [meta] Preserving auto-increment IDs on migration is fragile is this change and the complexity brings (of not preserving FIDs) really necessary?
heddn’s picture

If we fix the general problem, then we don't need one for these files. But I think we can get this in quick and dirty, while auto-increment could take longer.

heddn’s picture

Status: Needs review » Needs work

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jofitz’s picture

  1. Test the map (before and) after the second migration execution.
  2. Test the number of files migrated.
  3. I agree with @heddn that we should go for this as a quick and dirty solution.
heddn’s picture

Looks good with these last changes. Unfortunately, I cannot mark RTBC. Hopefully someone else will jump in.

mikeryan’s picture

Assigned: Unassigned » mikeryan
arunkumark’s picture

Status: Needs review » Reviewed & tested by the community

Hi,

The patch #21 seems to be look good. Working as expected.

xjm’s picture

Status: Reviewed & tested by the community » Needs review

@arunkumark, please provide a more specific review than that when RTBCing a patch. "Working as expected" does not actually contain any information. Please document what you reviewed and how you tested it. Otherwise, you will not receive issue credit for your review. Thanks for helping review patches!

mikeryan’s picture

Assigned: mikeryan » Unassigned
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Looks good to me, thanks!

mikeryan’s picture

@alexpott points out my RTBC was even terser than @arunkumark's... I did test this locally and it worked as expected. I also reviewed the code in and of itself and in the context of previous replies here, and I feel the previous points have been addressed.

catch’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Updated the issue summary to add the current resolution and committed/pushed to 8.4.x and cherry-picked to 8.3.x, thanks!

  • catch committed d318148 on 8.4.x
    Issue #2826047 by heddn, Jo Fitzgerald, mikeryan, catch, alexpott: 6-8...

  • catch committed 2d22fcf on 8.3.x
    Issue #2826047 by heddn, Jo Fitzgerald, mikeryan, catch, alexpott: 6-8...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.