Problem/Motivation

#2613878: Use hash for Migration source keys, rather than verbatim values introduced a query in \Drupal\migrate\Plugin\migrate\id_map\Sql::delete() that required the source_ids_hash column to exist:

$message_query = $this->getDatabase()->delete($this->messageTableName());
$message_query->condition(static::SOURCE_IDS_HASH, $this->getSourceIDsHash($source_id_values));
$message_query->execute();

However, an update hook was not added to the module to ensure that any existing message tables include the column. For scenarios where a site is doing incremental updates from a previous version of drupal, doing a re-install & fresh install of migrate isn't really a good option. Even though migrate is experimental, updates have been written in the past and this can be easily fixed with such an approach.

Proposed resolution

Create an update hook to ensure that the columns exist on any table(s) that already exist in the database.

Remaining tasks

  1. Write Patch

User interface changes

N/A

API changes

N/A

Data model changes

Data model already changed, need to update existing database schema.

Comments

davidwbarratt created an issue. See original summary.

davidwbarratt’s picture

Issue summary: View changes
davidwbarratt’s picture

Priority: Critical » Major
Issue tags: +Migrate critical
edysmp’s picture

Assigned: Unassigned » edysmp

Working

edysmp’s picture

Status: Active » Needs review
StatusFileSize
new842 bytes
edysmp’s picture

Assigned: edysmp » Unassigned
davidwbarratt’s picture

Shouldn't it be:

$this->messageTableName()

Instead of:

$this->messageTableName

Other than that, it looks perfect to me.

edysmp’s picture

I think this $this->messageTableName() causes a loop:

messageTableName()
$this->init();
$this->ensureTables();
davidwbarratt’s picture

Ah, that makes sense.

davidwbarratt’s picture

Status: Needs review » Needs work

I get this error when running the tests locally:

..................................F......PHP Fatal error:  Call to undefined function Drupal\Core\Database\Driver\sqlite\t() in docroot/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php on line 303

PHP Stack trace:

PHP   1. {main}() vendor/phpunit/phpunit/phpunit:0

PHP   2. PHPUnit_TextUI_Command::main() vendor/phpunit/phpunit/phpunit:47

PHP   3. PHPUnit_TextUI_Command->run() vendor/phpunit/phpunit/src/TextUI/Command.php:100

PHP   4. PHPUnit_TextUI_TestRunner->doRun() vendor/phpunit/phpunit/src/TextUI/Command.php:149

PHP   5. PHPUnit_Framework_TestSuite->run() vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440

PHP   6. PHPUnit_Framework_TestSuite->run() vendor/phpunit/phpunit/src/Framework/TestSuite.php:747

PHP   7. PHPUnit_Framework_TestSuite->run() vendor/phpunit/phpunit/src/Framework/TestSuite.php:747

PHP   8. PHPUnit_Framework_TestCase->run() vendor/phpunit/phpunit/src/Framework/TestSuite.php:747

PHP   9. PHPUnit_Framework_TestResult->run() vendor/phpunit/phpunit/src/Framework/TestCase.php:724

PHP  10. PHPUnit_Framework_TestCase->runBare() vendor/phpunit/phpunit/src/Framework/TestResult.php:612

PHP  11. PHPUnit_Framework_TestCase->runTest() vendor/phpunit/phpunit/src/Framework/TestCase.php:768

PHP  12. ReflectionMethod->invokeArgs() vendor/phpunit/phpunit/src/Framework/TestCase.php:909

PHP  13. Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest->testGetRowBySource() vendor/phpunit/phpunit/src/Framework/TestCase.php:909

PHP  14. Drupal\migrate\Plugin\migrate\id_map\Sql->getRowBySource() docroot/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php:369

PHP  15. Drupal\Tests\migrate\Unit\TestSqlIdMap->getDatabase() docroot/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php:485

PHP  16. Drupal\migrate\Plugin\migrate\id_map\Sql->getDatabase() docroot/core/modules/migrate/tests/src/Unit/TestSqlIdMap.php:46

PHP  17. Drupal\migrate\Plugin\migrate\id_map\Sql->init() docroot/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php:284

PHP  18. Drupal\migrate\Plugin\migrate\id_map\Sql->ensureTables() docroot/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php:301

PHP  19. Drupal\Core\Database\Driver\sqlite\Schema->addField() docroot/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php:448
davidwbarratt’s picture

Looks like it's because of this:

if (!$this->tableExists($table)) {
  throw new SchemaObjectDoesNotExistException(t("Cannot add field @table.@field: table doesn't exist.", array('@field' => $field, '@table' => $table)));
}

I guess we should first add a check to ensure that the table actually exists?

The last submitted patch, 5: migration_failed_with-2679797-5.patch, failed testing.

davidwbarratt’s picture

Status: Needs work » Needs review
StatusFileSize
new1008 bytes
new1.37 KB
davidwbarratt’s picture

Status: Needs review » Needs work
davidwbarratt’s picture

StatusFileSize
new1.68 KB
new715 bytes
davidwbarratt’s picture

Status: Needs work » Needs review

The last submitted patch, 13: migration_failed_with-2679797-13.patch, failed testing.

benjy’s picture

+++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
@@ -439,6 +439,18 @@ protected function ensureTables() {
+      // Add any missing columns to the message table.
+      if ($this->getDatabase()->schema()->tableExists($this->messageTableName)) {
+        if (!$this->getDatabase()->schema()->fieldExists($this->messageTableName, static::SOURCE_IDS_HASH)) {

Could this be in an update hook rather than in the map itself?

heddn’s picture

I remember asking this in irc at one point and someone mentioned that since migrate was an experimental module, an update wasn't necessary. If we think about it, it isn't just the creation of the column we need to worry about. We also need to worry about the change of the PK and the fact that all lookups are now done by a hash. So, all previous messages (and mappings) would need to go into that hook update and do a one-time hash into the hash column, right?

davidwbarratt’s picture

#18,

I think it probably should be, but there is already code in there to take care of missing fields for the map tables, so to me it makes sense that it's all together one way or another.

davidwbarratt’s picture

#19,

If a module in core isn't going to have an upgrade path from one Drupal release to another, it probably shouldn't be in core at all.

Either that, or it should be really really clear that experimental modules do not have an upgrade path from version to version and therefor should never be used. If that is the case, then I don't see how anyone can migrate to Drupal 8 until MIgrate is no longer experimental.

However, I think providing an upgrade path is somewhat trivial (especially in this case), and should be done. To your point, it would make more sense to have an update hook than do what this patch does, but similar code already exists in the method, so we should probably remove both instances.

Perhaps we should make a follow up issue? Or fix it all in this issue? How would we figure out all the tables we need to update?

davidwbarratt’s picture

StatusFileSize
new9.42 KB
new9.81 KB

You're right, there's a bigger issue where you can't run migrate-import --update you get a nasty gram error like this:

$ ../vendor/bin/drush migrate-import d7_node__article --update
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '123534' for key 'PRIMARY'' in                                                              [error]
docroot/core/lib/Drupal/Core/Database/Statement.php:64
Stack trace:
#0 docroot/core/lib/Drupal/Core/Database/Statement.php(64): PDOStatement->execute(Array)
#1 docroot/core/lib/Drupal/Core/Database/Connection.php(615): Drupal\Core\Database\Statement->execute(Array, Array)
#2 docroot/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(86): Drupal\Core\Database\Connection->query('INSERT INTO {mi...', Array, Array)
#3 docroot/core/lib/Drupal/Core/Database/Driver/mysql/Insert.php(37): Drupal\Core\Database\Driver\mysql\Connection->query('INSERT INTO {mi...', Array, Array)
#4 docroot/core/lib/Drupal/Core/Database/Query/Merge.php(376): Drupal\Core\Database\Driver\mysql\Insert->execute()
#5 docroot/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php(594): Drupal\Core\Database\Query\Merge->execute()
#6 docroot/core/modules/migrate/src/MigrateExecutable.php(260): Drupal\migrate\Plugin\migrate\id_map\Sql->saveIdMapping(Object(Drupal\migrate\Row), Array, 3)
#7 [internal function]: Drupal\migrate\MigrateExecutable->import()
#8 vendor/drush/drush/includes/drush.inc(715): call_user_func_array(Array, Array)
#9 vendor/drush/drush/includes/drush.inc(706): drush_call_user_func_array(Array, Array)
#10 docroot/modules/contrib/migrate_tools/migrate_tools.drush.inc(235): drush_op(Array)
#11 [internal function]: drush_migrate_tools_migrate_import('d7_node__articl...')
#12 vendor/drush/drush/includes/command.inc(364): call_user_func_array('drush_migrate_t...', Array)
#13 vendor/drush/drush/includes/command.inc(215): _drush_invoke_hooks(Array, Array)
#14 [internal function]: drush_command('d7_node__articl...')
#15 vendor/drush/drush/includes/command.inc(183): call_user_func_array('drush_command', Array)
#16 vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(65): drush_dispatch(Array)
#17 vendor/drush/drush/includes/preflight.inc(64): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#18 vendor/drush/drush/drush.php(12): drush_main()
#19 {main}

Next exception 'Drupal\Core\Database\IntegrityConstraintViolationException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '123534' for key 'PRIMARY': INSERT INTO
{migrate_map_d7_node__article} (source_ids_hash, sourceid1, source_row_status, rollback_action, hash) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2,
:db_insert_placeholder_3, :db_insert_placeholder_4); Array
(
    [:db_insert_placeholder_0] => 35d6677b65c52a7e457408059b3f2c8431bc1d07c5b58e718d0329d5933d835c
    [:db_insert_placeholder_1] => 123534
    [:db_insert_placeholder_2] => 3
    [:db_insert_placeholder_3] => 0
    [:db_insert_placeholder_4] => 
)
' in docroot/core/lib/Drupal/Core/Database/Connection.php:673
Stack trace:
#0 docroot/core/lib/Drupal/Core/Database/Connection.php(640): Drupal\Core\Database\Connection->handleQueryException(Object(PDOException), 'INSERT INTO {mi...', Array,
Array)
#1 docroot/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(86): Drupal\Core\Database\Connection->query('INSERT INTO {mi...', Array, Array)
#2 docroot/core/lib/Drupal/Core/Database/Driver/mysql/Insert.php(37): Drupal\Core\Database\Driver\mysql\Connection->query('INSERT INTO {mi...', Array, Array)
#3 docroot/core/lib/Drupal/Core/Database/Query/Merge.php(376): Drupal\Core\Database\Driver\mysql\Insert->execute()
#4 docroot/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php(594): Drupal\Core\Database\Query\Merge->execute()
#5 docroot/core/modules/migrate/src/MigrateExecutable.php(260): Drupal\migrate\Plugin\migrate\id_map\Sql->saveIdMapping(Object(Drupal\migrate\Row), Array, 3)
#6 [internal function]: Drupal\migrate\MigrateExecutable->import()
#7 vendor/drush/drush/includes/drush.inc(715): call_user_func_array(Array, Array)
#8 vendor/drush/drush/includes/drush.inc(706): drush_call_user_func_array(Array, Array)
#9 docroot/modules/contrib/migrate_tools/migrate_tools.drush.inc(235): drush_op(Array)
#10 [internal function]: drush_migrate_tools_migrate_import('d7_node__articl...')
#11 vendor/drush/drush/includes/command.inc(364): call_user_func_array('drush_migrate_t...', Array)
#12 vendor/drush/drush/includes/command.inc(215): _drush_invoke_hooks(Array, Array)
#13 [internal function]: drush_command('d7_node__articl...')
#14 vendor/drush/drush/includes/command.inc(183): call_user_func_array('drush_command', Array)
#15 vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(65): drush_dispatch(Array)
#16 vendor/drush/drush/includes/preflight.inc(64): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#17 vendor/drush/drush/drush.php(12): drush_main()
#18 {main}

I've attached a patch that's an update script that updates all of the existing tables, rather than having them in ::ensureTables

heddn’s picture

Title: Migration failed with source plugin exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'source_ids_hash' in 'where clause'. » Migration migrate_update_8009 for source hash
heddn’s picture

Issue summary: View changes
heddn’s picture

Issue tags: +Needs tests

OK, we should write an update test here. And we'll need a test where the db table was created using a version of drupal < 8.0.5. Not sure how to do that. I guess we could create the table and fabricate the data in the test. Is there a standard way to do this?

I'm guessing there is a way to stub out the db table in phpunit.

davidwbarratt’s picture

StatusFileSize
new12.09 KB
new718 bytes

Need to remove the existing source id's from the message table(s).

benjy’s picture

+++ b/core/modules/migrate/migrate.install
@@ -23,5 +23,144 @@ function migrate_update_8001() {
+  $storage = \Drupal::service('entity_type.manager')->getStorage('migration');

What happens if the migrate module isn't even enabled, will this fatal?

davidwbarratt’s picture

Is it possible to run an hook_update without the same module being enabled?

benjy’s picture

ah yeah of course. Patch looks good, just needs a test.

freelock’s picture

@davidwbarratt it was possible in D7 and earlier, if a module was installed but disabled... (though module updates in this state often fail).

Does this patch require the tip of 8.0.x or 8.1.x?

I just tried applying to 8.0.5 and it fails to apply changes to the tests. Ignored those and attempted to run the update and I got:

PHP Fatal error: Class 'Unicode' not found in /var/www/html/asap/d8/core/modules/migrate/migrate.install on line 44

jcnventura’s picture

StatusFileSize
new315 bytes
new12.23 KB

Indeed, there's a missing Unicode class.. This patch adds it.

usrsbn’s picture

Hi,

I applied patch 32. After that i uninstalled and reinstalled migrate, migrate_upgrade and migrate_drupal. When trying to "Rerun" import via UI (/upgrade) I get the following errors:
Warning: mt_rand(): max(-1) is smaller than min(0) in Drupal\Core\Database\Database::parseConnectionInfo() (line 217 of core/lib/Drupal/Core/Database/Database.php).
Notice: Undefined offset: 0 in Drupal\Core\Database\Database::parseConnectionInfo() (line 217 of core/lib/Drupal/Core/Database/Database.php).
Notice: Undefined index: driver in Drupal\Core\Database\Database::openConnection() (line 369 of core/lib/Drupal/Core/Database/Database.php).
Notice: Undefined index: driver in Drupal\migrate_upgrade\Form\MigrateUpgradeForm->validateCredentialForm() (line 986 of modules/migrate_upgrade/src/Form/MigrateUpgradeForm.php).

Resolve the issue below to continue the upgrade. Driver not specified for this database connection: upgrade

I have not specified a database called "upgrade". This is what's in my settings.php:

$databases['drupal6_kupf']['default'] = array (
  'database' => 'drupal6_kupf',
  'username' => 'drupal6_kupf',
  'password' => 'secret',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);
$databases['default']['default'] = array (
  'database' => 'drupal8_kupf',
  'username' => 'kupf8',
  'password' => 'secret',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

Do you have any idea how I can fix this?

heddn’s picture

#33 is unrelated to this issue. Please open as a separate thing.

usrsbn’s picture

Thanks! I posted the issue here.

ckng’s picture

Applied patch #32. Importing new content give me Integrity constraint violation, on 2 migrations tested.

$ drush mi blog
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '78' for key 'PRIMARY'' in          [error]
/var/www/bb/html/core/lib/Drupal/Core/Database/Statement.php:64
Stack trace:
#0 /var/www/bb/html/core/lib/Drupal/Core/Database/Statement.php(64): PDOStatement->execute(Array)
#1 /var/www/bb/html/core/lib/Drupal/Core/Database/Connection.php(615): Drupal\Core\Database\Statement->execute(Array, Array)
#2 /var/www/bb/html/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(86): Drupal\Core\Database\Connection->query('INSERT INTO {mi...',
Array, Array)
#3 /var/www/bb/html/core/lib/Drupal/Core/Database/Driver/mysql/Insert.php(37): Drupal\Core\Database\Driver\mysql\Connection->query('INSERT INTO
{mi...', Array, Array)
#4 /var/www/bb/html/core/lib/Drupal/Core/Database/Query/Merge.php(376): Drupal\Core\Database\Driver\mysql\Insert->execute()
#5 /var/www/bb/html/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php(548): Drupal\Core\Database\Query\Merge->execute()
#6 /var/www/bb/html/core/modules/migrate/src/MigrateExecutable.php(260):
Drupal\migrate\Plugin\migrate\id_map\Sql->saveIdMapping(Object(Drupal\migrate\Row), Array, 3)
#7 [internal function]: Drupal\migrate\MigrateExecutable->import()
#8 phar:///usr/local/bin/drush/includes/drush.inc(715): call_user_func_array(Array, Array)
#9 phar:///usr/local/bin/drush/includes/drush.inc(706): drush_call_user_func_array(Array, Array)
#10 /var/www/bb/html/sites/bb-dev/modules/contrib/migrate_tools/migrate_tools.drush.inc(235): drush_op(Array)
#11 [internal function]: drush_migrate_tools_migrate_import('branches_blog')
#12 phar:///usr/local/bin/drush/includes/command.inc(364): call_user_func_array('drush_migrate_t...', Array)
#13 phar:///usr/local/bin/drush/includes/command.inc(215): _drush_invoke_hooks(Array, Array)
#14 [internal function]: drush_command('branches_blog')
#15 phar:///usr/local/bin/drush/includes/command.inc(183): call_user_func_array('drush_command', Array)
#16 phar:///usr/local/bin/drush/lib/Drush/Boot/BaseBoot.php(65): drush_dispatch(Array)
#17 phar:///usr/local/bin/drush/includes/preflight.inc(64): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#18 phar:///usr/local/bin/drush/includes/startup.inc(289): drush_main()
#19 phar:///usr/local/bin/drush/drush(114): drush_startup(Array)
#20 /usr/local/bin/drush(10): require('phar:///usr/loc...')
#21 {main}

Next exception 'Drupal\Core\Database\IntegrityConstraintViolationException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062
Duplicate entry '78' for key 'PRIMARY': INSERT INTO {migrate_map_blog} (source_ids_hash, sourceid1, source_row_status, rollback_action,
hash) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4);
Array
(
    [:db_insert_placeholder_0] => 34bf071f7083187c532015c732883ef4cd27d0351b55d4a5c6233fefa9a5d0a5
    [:db_insert_placeholder_1] => 78
    [:db_insert_placeholder_2] => 3
    [:db_insert_placeholder_3] => 0
    [:db_insert_placeholder_4] =>
)
' in /var/www/bb/html/core/lib/Drupal/Core/Database/Connection.php:673
Stack trace:
#0 /var/www/bb/html/core/lib/Drupal/Core/Database/Connection.php(640):
Drupal\Core\Database\Connection->handleQueryException(Object(PDOException), 'INSERT INTO {mi...', Array, Array)
#1 /var/www/bb/html/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php(86): Drupal\Core\Database\Connection->query('INSERT INTO {mi...',
Array, Array)
#2 /var/www/bb/html/core/lib/Drupal/Core/Database/Driver/mysql/Insert.php(37): Drupal\Core\Database\Driver\mysql\Connection->query('INSERT INTO
{mi...', Array, Array)
#3 /var/www/bb/html/core/lib/Drupal/Core/Database/Query/Merge.php(376): Drupal\Core\Database\Driver\mysql\Insert->execute()
#4 /var/www/bb/html/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php(548): Drupal\Core\Database\Query\Merge->execute()
#5 /var/www/bb/html/core/modules/migrate/src/MigrateExecutable.php(260):
Drupal\migrate\Plugin\migrate\id_map\Sql->saveIdMapping(Object(Drupal\migrate\Row), Array, 3)
#6 [internal function]: Drupal\migrate\MigrateExecutable->import()
#7 phar:///usr/local/bin/drush/includes/drush.inc(715): call_user_func_array(Array, Array)
#8 phar:///usr/local/bin/drush/includes/drush.inc(706): drush_call_user_func_array(Array, Array)
#9 /var/www/bb/html/sites/bb-dev/modules/contrib/migrate_tools/migrate_tools.drush.inc(235): drush_op(Array)
#10 [internal function]: drush_migrate_tools_migrate_import('branches_blog')
#11 phar:///usr/local/bin/drush/includes/command.inc(364): call_user_func_array('drush_migrate_t...', Array)
#12 phar:///usr/local/bin/drush/includes/command.inc(215): _drush_invoke_hooks(Array, Array)
#13 [internal function]: drush_command('branches_blog')
#14 phar:///usr/local/bin/drush/includes/command.inc(183): call_user_func_array('drush_command', Array)
#15 phar:///usr/local/bin/drush/lib/Drush/Boot/BaseBoot.php(65): drush_dispatch(Array)
#16 phar:///usr/local/bin/drush/includes/preflight.inc(64): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#17 phar:///usr/local/bin/drush/includes/startup.inc(289): drush_main()
#18 phar:///usr/local/bin/drush/drush(114): drush_startup(Array)
#19 /usr/local/bin/drush(10): require('phar:///usr/loc...')
#20 {main}

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

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

ckng’s picture

Re-tested my case in #36 after apply only the db update code in the patch without the unit tests. It works for new migration, but still fail for migrate-import --update

Are there specific step required? Uninstall migrate? Rollback all migrations?

hkirsman’s picture

StatusFileSize
new12.24 KB

Needed patch for 8.1.0

hkirsman’s picture

StatusFileSize
new12.24 KB

Re-uploading correct version

The last submitted patch, 39: migration_failed_with-2679797-39.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 40: migration_failed_with-2679797-40.patch, failed testing.

mikeryan’s picture

  1. +++ b/core/modules/migrate/migrate.install
    @@ -23,5 +25,144 @@ function migrate_update_8001() {
    +      $map_table_name = 'migrate_map_' . Unicode::strtolower($machine_name);
    +      $map_table_name = Unicode::substr($map_table_name, 0, 63 - $prefix_length);
    +      $message_table_name = 'migrate_message_' . Unicode::strtolower($machine_name);
    +      $message_table_name = Unicode::substr($message_table_name, 0, 63 - $prefix_length);
    

    The idmap plugin has this code already, you can just call $map->mapTableName() and $map->messageTableName(). Note that in theory one could swap in their own idmap plugin and use a different scheme for naming tables.

  2. +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
    @@ -30532,21 +30532,6 @@
     ->values(array(
    -  'fid' => '13',
    -  'title' => 'Blog',
    -  'name' => 'profile_blog',
    -  'explanation' => 'Paste the full URL, including http://, of your personal blog.',
    -  'category' => 'Personal information',
    -  'page' => '',
    -  'type' => 'url',
    -  'weight' => '3',
    -  'required' => '0',
    -  'register' => '0',
    -  'visibility' => '3',
    -  'autocomplete' => '0',
    -  'options' => '',
    -))
    -->values(array(
    

    What does this have to do with the issue?

smaz’s picture

I've had this issue after upgrading from Drupal 8.0.3 -> 8.0.6.

I applied the patch in #40 (had to remove core/modules/user/tests/src/Kernel/Migrate/d6/MigrateUserProfileValuesTest.php part as that file doesn't exist in 8.0.6), and it's worked fine for me - thanks all.

hkirsman’s picture

I have no idea of why there's something in the patch and I don't have the technical know-how. Just adjusted the patch for last Drupal :)

Anybody can answer mikeryan?

mikgreen’s picture

StatusFileSize
new11.17 KB

The version from #40, just without MigrateUserProfileValuesTest.php part.

mikgreen’s picture

StatusFileSize
new11.75 KB
new7.21 KB
new9.35 KB

I've had a case where there are source_ids_hash fields, but their empty.
So I changed the code to always regenerate source_ids_hash field values.

Also removed stuff as per #43.

Also a patch for 8.0.x is included.

mikeryan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 47: migration_failed_with-2679797-8.0.x-47.patch, failed testing.

The last submitted patch, 47: migration_failed_with-2679797-47.patch, failed testing.

smaz’s picture

I've had a case where there are source_ids_hash fields, but their empty.
So I changed the code to always regenerate source_ids_hash field values.

I had the same - the patch added the new column, but all values were empty so any migrations that used the migration process plugin failed to lookup the value from the other migrations.

I've applied the 8.0.x patch from #47 & it applies cleanly, adds the new column + generates the source_ids_hash value.

Cheers

Anonymous’s picture

Issue tags: -Migrate critical

At the migrate critical issues triage in New Orleans we decided to remove the critical tag on this issue for the same reasons @heddn suggests in #19. We are keeping the issue open as a major so that work can proceed.

tom m fallon’s picture

Hello

We are having some real trouble upgrading from 8.0.x to 8.1.x

I've added an 8.1.8 core, connected to a 8.0.x database.

I've successfully applied patch #47 migration_failed_with-2679797-47.patch

And received the following error.

/var/core/www$ drush updb -y
The following updates are pending:

migrate module :
  8009 -   Update existing database tables if necessary.

Do you wish to run all pending updates? (y/n): y
PHP Fatal error:  Call to undefined method Drupal\migrate_plus\Entity\Migration::getSourcePlugin() in /var/core/www/core/modules/migrate/migrate.install on line 37
PHP Stack trace:
PHP   1. {main}() /home/vagrant/.config/composer/vendor/drush/drush/drush.php:0
PHP   2. drush_main() /home/vagrant/.config/composer/vendor/drush/drush/drush.php:12
PHP   3. Drush\Boot\BaseBoot->bootstrap_and_dispatch() /home/vagrant/.config/composer/vendor/drush/drush/includes/preflight.inc:66
PHP   4. drush_dispatch() /home/vagrant/.config/composer/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php:67
PHP   5. call_user_func_array:{/home/vagrant/.config/composer/vendor/drush/drush/includes/command.inc:185}() /home/vagrant/.config/composer/vendor/drush/drush/includes/command.inc:185
PHP   6. drush_command() /home/vagrant/.config/composer/vendor/drush/drush/includes/command.inc:185
PHP   7. _drush_invoke_hooks() /home/vagrant/.config/composer/vendor/drush/drush/includes/command.inc:217
PHP   8. call_user_func_array:{/home/vagrant/.config/composer/vendor/drush/drush/includes/command.inc:366}() /home/vagrant/.config/composer/vendor/drush/drush/includes/command.inc:366
PHP   9. drush_core_updatedb_batch_process() /home/vagrant/.config/composer/vendor/drush/drush/includes/command.inc:366
PHP  10. _update_batch_command() /home/vagrant/.config/composer/vendor/drush/drush/commands/core/core.drush.inc:1221
PHP  11. drush_batch_command() /home/vagrant/.config/composer/vendor/drush/drush/commands/core/drupal/update.inc:174
PHP  12. _drush_batch_command() /home/vagrant/.config/composer/vendor/drush/drush/includes/batch.inc:98
Drush command terminated abnormally due to an unrecoverable error.                                                                                         [error]
Error: Call to undefined method Drupal\migrate_plus\Entity\Migration::getSourcePlugin() in /var/core/www/core/modules/migrate/migrate.install, line 37
PHP  13. _drush_batch_worker() /home/vagrant/.config/composer/vendor/drush/drush/commands/core/drupal/batch.inc:111
PHP  14. call_user_func_array:{/home/vagrant/.config/composer/vendor/drush/drush/commands/core/drupal/batch.inc:163}() /home/vagrant/.config/composer/vendor/drush/drush/commands/core/drupal/batch.inc:163
PHP  15. drush_update_do_one() /home/vagrant/.config/composer/vendor/drush/drush/commands/core/drupal/batch.inc:163
PHP  16. migrate_update_8009() /home/vagrant/.config/composer/vendor/drush/drush/commands/core/drupal/update.inc:60
The external command could not be executed due to an application error.                                                                                    [error]
Cache rebuild complete.                                                                                                                                    [ok]
Finished performing updates.

The line that appears to be wrong is
migrate.install

foreach ($migration->getSourcePlugin()->getIds() as $field => $schema) { 

Has anyone else got this issue, and if possible how do I resolve it. I believe this is a critical issue as its preventing users from reliably upgrading to 8.1.x leaving them running out of date software.

Thanks

tom m fallon’s picture

Priority: Major » Critical
tom m fallon’s picture

I've elevated this issue to critical from major.
I've done some further work with this issue, and found the migrate_plus is a particular source of the issue. It appears to be the lack the getSourcePlugin which is loaded within

$storage = \Drupal::service('entity_type.manager')->getStorage('migration');

This issue blocks us from being able to move to Drupal 8.1.x.

I believe the issue is a widespread thing, and to de-escalate the issue a patch which reliably works is provided, and preferably merged into the migrate module. If we are to use a hash it should be that the upgrade path to 8.1.x is possible.

This issue hasn't moved in months, and needs to be addressed if people are to want to upgrade to the later versions of Drupal.

I will be following this issue closely, and any ways to get this turned round into production ready code I'm happy to help.

mikeryan’s picture

Priority: Critical » Major
Issue tags: +Needs reroll

As previously mentioned, experimental modules are not required to provide update paths (although it may be nice to do so in some cases, like this) - moving back to major.

The problem you're seeing is that the last patch was made before #2625696: Make migrations themselves plugins instead of config entities went in (see the change record). That patch removed migration configuration entities from core - since migrate_plus added its own implementation of migration configuration entities on the contrib side, the old update function here is picking those up, but too much has changed since 8.0.x for that to work cleanly. If you didn't have migrate_plus, the update function would have done nothing at all.

So, the update function here would need to use the core migration plugin manager instead of trying to load config entities. That probably won't work until #2560795: Source plugins have a hidden dependency on migrate_drupal is fixed - well, maybe it would work if you have migrate_drupal enabled, but not in the general case.

I'm sorry, but about all I can suggest in the short term is a custom script to update the tables.

As for the patch itself:

  1. Why is it numbered 8009 rather than 8002?
  2. Somehow some irrelevent user profile stuff crept in.

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

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

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

heddn’s picture

Status: Needs work » Closed (won't fix)

Discussed in weekly migrate meeting. Considering this is for functionality added in 8.0.x, and we are now in 8.2.x we are going to mark this "not fix". There were no promises that updates would be provided for experimental modules and no one has stepped forward to provide such an update.