I'm trying to migrate a Drupal 6.3.8 website to Drupal 8.1.0, and after running the migration process, I have 178 database tables in my Drupal 8 database that begin with the names "migrate_map" and "migrate_message". I've looked at some of them so far, and some are empty, and some have data in them.

A few questions:

* Should these tables have been cleaned up (deleted) after the migration process finished?
* If not, can I delete the empty tables?

It seems like the migration process finished okay, though there are 27 errors like this in the reports:

Source ID node,teaser,source_code,field_source_tags: Failed to lookup field type array ( 0 => 'content_taxonomy', 1 => 'link', ) in the static map.

There are a couple of errors related to menus as well, like this:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'aa_d6.menu_custom' doesn't exist: SELECT COUNT(*) AS expression FROM (SELECT 1 AS expression FROM @menu_custom m) subquery; Array ( )

I'll be glad to provide any information you need on this. I'm using MAMP 3.5 on a Mac OS X system, and the Drupal 6.38 site has a little over 7,000 nodes and 18,000 URL aliases.

If the image attachment works, it shows some of the table names that are left over.

CommentFileSizeAuthor
drupal_migrate-tables.jpg187.53 KBalvinalexander
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alvinalexander created an issue. See original summary.

xeM8VfDh’s picture

+1

I am also interested in knowing the answer to this. After a successful migration, when one knows that they won't be doing any more migrations, is it okay to drop all migrate_* tables.

mikeryan’s picture

Category: Bug report » Support request
Status: Active » Fixed

The tables absolutely should remain after running a migration process - the migrate_message tables are necessary for diagnosing any problems that may have occurred during migration, and the migrate_map tables are necessary to permit rolling back a migration or running incremental (delta) migrations after the initial bulk migration.

A related question is whether the tables should be removed when uninstalling the migrate module - there's an existing issue for that: #2713327: Provide a way to remove migration tables (ID map etc.).

xeM8VfDh’s picture

@mikeryan, thanks for the feedback. However, lets say that my migration went well, I've done all of my cleanup, no more migrations/rollbacks will be performed, and I am moving forward without any further need for the migration functionalities. In that scenario, would it be okay to deactivate/uninstall the Migrate Upgrade module, then drop all of those tables? Thanks again.

mikeryan’s picture

Yes, the expectation is that you will disable the migration modules once you're done with them. Unless/until #2713327: Provide a way to remove migration tables (ID map etc.) is addressed, you can safely drop the tables.

xeM8VfDh’s picture

Thanks mikeryan for confirming that

Status: Fixed » Closed (fixed)

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

davidwhthomas’s picture

Just noting, after a completed migration, uninstalling the migrate modules doesn't appear to delete the migrate_% tables in the database. They need to be manually deleted after that.

Probably a few ways to do it, but here's a sample .install file update hook to remove them:

/**
 * Drop completed migrate_% db tables
 */
function MY_MODULE_update_8017(&$sandbox) {
  // Get table list
  $result = db_query("SHOW TABLES LIKE :table", [':table' => 'migrate_%']);
  // Init drop counter
  $count = 0;
  // Iterate and drop matched table
  foreach ($result as $row) {
    // Get table name from row data
    $data = array_values((array)$row);
    $table_name = $data[0];
    // Validate table name again
    if (strpos($table_name, 'migrate_') === 0) {
      // Drop the table
      db_drop_table($table_name);
      // Increment drop counter
      $count++;
      // Log dropped table
      \Drupal::logger('my_module')->info('Dropped table: @table', ['@table' => $table_name]);
    }
  }
  // Log total dropped table count
  \Drupal::logger('my_module')->info('Dropped @count tables', ['@count' => $count]);
}
phuang07’s picture

For Drupal 9:

/**
 * Drop completed migrate_% db tables
 */
function MY_MODULE_update_8017(&$sandbox) {
  // Get table list
  $result = \Drupal::database()
    ->query("SHOW TABLES LIKE :table", [':table' => 'migrate_%'])
    ->fetchAll();  // Init drop counter

  $count = 0;
  // Iterate and drop matched table
  foreach ($result as $row) {
    // Get table name from row data
    $data = array_values((array)$row);
    $table_name = $data[0];
    // Validate table name again
    if (strpos($table_name, 'migrate_') === 0) {
      // Drop the table
      \Drupal::database()->schema()->dropTable($table_name);

      // Increment drop counter
      $count++;
      // Log dropped table
      \Drupal::logger('my_module')->info('Dropped table: @table', ['@table' => $table_name]);
    }
  }
  // Log total dropped table count
  \Drupal::logger('my_module')->info('Dropped @count tables', ['@count' => $count]);
}
cewernlund’s picture

Just wanted to bump for relevance and appreciate the Drupal 9 syntax for clearing the tables mentioned in #9