2

I'm trying to remove an rss reference of a migration. Once I put the yaml code into the Migrate module in the drupal admin interface, it creates a reference to that yaml code, but there is no one in the UI that I can see the reference. The Migrate Tools module gives me access to drush commands, but none of which could remove a reference.

Does anyone know how to delete a reference to an import? I can see references through the command line using $ drush ms

I searched but could only find using this, but it doesn't work.

$ drush php

>>> Drupal::configFactory()->getEditable('migrate_plus.migration.my_rss_importer')->delete();

Here is the list of imports from the CLI I am trying to remove. Just for reference "migrate_plus" mentioned in the code above is another module that compliments the migrate module.

Group: Default (default)      Status  Total  Imported  Unprocessed  Last imported
 berkeley_news_rss_importer_1  Idle    20     20        0            2017-12-09 23:08:36
 berkeley_news_rss_importer_2  Idle    20     20        0            2017-12-09 23:12:34
 berkeley_news_rss_importer_3  Idle    20     20        0            2017-12-09 23:14:03
 berkeley_news_rss_importer_4  Idle    20     20        0            2017-12-09 23:20:04
 berkeley_news_rss_importer_5  Idle    20     20        0            2017-12-09 23:33:17
 berkeley_news_rss_importer_6  Idle    20     20        0            2017-12-09 23:42:26
 berkeley_news_rss_importer_7  Idle    20     0         0            2017-12-10 00:11:17
 berkeley_news_rss_importer_8  Idle    20     20        0            2017-12-11 09:46:45
 berkeley_news_rss_importer_9  Idle    20     0         20
1

So you want to get rid of the migrations so that they don't appear in the drush ms output? Do this:

Removing imported content

Upon reading your question the second time, I thought you might even be asking "How to remove the content which is imported already?". If that is your question, then try drush migrate-rollback or drush mr for short. See documentation with drush mr --help.

Deleting the migrations

  • If you are using configuration management, then delete the relevant config YML files from the config sync directory and do drush cim. There should be files named migrate_plus.migration.MIGRATION_ID. It will ask for confirmation and if you say y, the relevant migrations will be deleted.
  • If you are not using configuration management, do drush config-list. Now, for every migration you want to delete, search for the name of the migration in the output of the config list and do a config-delete for it. Example: drush cdel migrate_plus.migration.MIGRATION_ID Consider using config management in the long run.

Deleting migration mappings

  • The migrate module might have created some mapping tables in the database to track your migrations. To delete these tables (I assume you know what you're doing), delete the mapping and messages tables for the migration. Example: DROP TABLE IF EXISTS migrate_map_MIGRATION_ID, migrate_messages_MIGRATION_ID. After you do this, you will never be able to do rollback.

Hope it helps.

  • How can I delete migrations with fixed name part like : cdel migrate_plus.migration.upgrade_upgrade_* ? I don't find the joker . – webmaster pf May 24 at 9:50
  • The only thing I can think of is that if you've exported your config into a specific directory, then run an ls config/migrate_plus.migration.* - that should give you a list of migrations. Then you can remove the "yml" extensions and get the migration config names. Once you have those, you can run the above commands. There are other ways too. For example, in mysql, run SHOW TABLES LIKE "migrate_%" to see a list of migration related tables. Be careful though. Cheers. – Jigarius May 24 at 14:31
  • thanks for this tips. Actually I update my custom migration with importing the config files like cim --partial --source=modules/custom/site_mg/migrate_nodes_mg/config/install , and no new migration files are duplicate. So I think I will continue as is. – webmaster pf May 28 at 15:22
0

Migrate plus migrations are entities: the following code is adapted from MigrationGroup::delete(), where it finds each migration in a group and deletes them:

$migration_to_delete = 'my_rss_importer'; 
$migration = \Drupal::entityTypeManager()
  ->getStorage('migration')
  ->load($migration_to_delete);
$migration->delete();

Note that this calls Cache::invalidateTags(['migration_plugins']), so after a cache clear, it will remove your cached plugins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.