When attempting to migrate forum_access rules into a D7 site, the Migrate module generates the following error:

Auditing migrations
Invalid argument supplied for foreach() table.inc:39

The line in question is this one:
https://cgit.drupalcode.org/migrate/tree/plugins/destinations/table.inc#n39

The problem is the forum_access table doesn't have a primary key defined. Beyond the migration issue, I think it's good practice to define a primary key.

The attached patch fixes the issue by adding "primary key" to the schema and including an update to run db_add_primary_key.

Please review, thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ron_s created an issue. See original summary.

salvis’s picture

Status: Needs review » Needs work

Thank you for your report and patch, ron_s!

into a D7 site

Are you migrating D6 to D7? This should be a simple upgrade as far as Forum Access is concerned. Or am I missing something?

There's no downside to adding a tid+rid primary key, I guess, but then we should remove the tid index.

ron_s’s picture

Good point on removing the tid index. See updated patch.

Yes, this is a D6 to D7 upgrade. I agree, I would have thought it would be simple.

I have a straightforward mapping using MigrateDestinationTable, and a MigrateSQLMap using tid and rid as the keys:

    $query = $this->getConnection()
      ->select('forum_access', 'fa')
      ->fields('fa');

    $table_name = 'forum_access';

    $this->map = new MigrateSQLMap(
      $this->machineName,
      array(
        'tid' => array(
          'type' => 'int',
          'length' => 11,
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => '0',
          'description' => 'Term ID.',
          'alias' => 'fa',
        ),
        'rid' => array(
          'type' => 'int',
          'length' => 11,
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => '0',
          'description' => 'Role ID.',
          'alias' => 'fa',
        ),
      ),
      MigrateDestinationTable::getKeySchema($table_name)
    );

    $this->destination = new MigrateDestinationTable($table_name);

Have created migrations for many other tables, and forum_access is the first time I've run into any problem like this.

I also ran into a second migration issue regarding Forum Access that I'm going to post separately.

ron_s’s picture

Cross-referencing the other forum_access issue I had when migrating: https://www.drupal.org/project/forum_access/issues/3003279

salvis’s picture

Yes, this looks good now, and we need the same thing for D8.

Why do you need to use Migrate at all? I just upgraded a D6 site to D7 directly, without Migrate, and it seems to work fine.

ron_s’s picture

Good question, with a very straightforward reason.

These are not upgrades. We're using Drupal 6 sites as data repositories to import into a vastly different D7 solution. They will all be part of a single, consistent codebase.

Some of the sites were built by us, and some were built by others. Very little in the D6 sites match what we have in the new platform, so we are mapping what they do have into the proper fields, content types, etc.

salvis’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
FileSize
4.41 KB

D8 version of the patch.

Status: Needs review » Needs work

The last submitted patch, 7: forum_access-add_primary_key-3002918-3-D8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • salvis committed 79d130a on 8.x-1.x
    Issue #3002918 by salvis, ron_s: Add primary key and index to the {...
salvis’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Needs work » Reviewed & tested by the community

Pushed to D8.

  • salvis committed 6c6d58c on 7.x-1.x
    Issue #3002918 by ron_s: Define primary key for the {forum_access} table...
salvis’s picture

Status: Reviewed & tested by the community » Fixed

Thank you, ron_s!

  • salvis committed b278671 on 8.x-1.x
    Issue #3084233 by salvis: Update 8101 (#3002918) can fail; fix rid width...

Status: Fixed » Closed (fixed)

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