Needs work
Project:
Migrate Tools
Version:
6.0.x-dev
Component:
Drush commands
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
5 Sep 2018 at 17:51 UTC
Updated:
26 Sep 2025 at 17:59 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
adamps commentedComment #3
adamps commentedThe patch in #2 worked for me but is a bit rough:
Comment #4
cestmoi commentedI confirm the working of the patch in #2
I still have 12 empty migration tables in the DB though:
They persisted even after next step when I did uninstall of all migration modules using drush.
Otherwise, everything look great, no errors in WS or experienced elsewhere.
Comment #5
adamps commented@cestmoi Thanks for the report.
The drush command is a simple wrapper around already existing clean-up logic and hopefully the existing code works well. If the tables are empty that suggests the drush command did run on those tables. One possibility is that the command deleted all the rows in the table but left the table. However that doesn't seem likely because
Drupal\migrate\Plugin\migrate\id_map\Sql::destroycalls dropTable.So I expect that what happened is that the drush command dropped the tables, and something else put the tables back after. This can happen very easily because
Drupal\migrate\Plugin\migrate\id_map\Sql::initcreates them. So if you run any drush command or visit pages in the GUI the empty tables come back. If you can, it would be useful if you reactivate the migration modules, rerun drush command, then check immediately to see if the tables are still there.Comment #6
cestmoi commented@AdamPS
I confirm it's not the case. I compared with a backup DB and all those tables were already empty.
I checked the creation date of the tables in the DB and they're all old.
I did the check immediately after running the drush command as follows:
drush migrate-destroy --allComment #7
adamps commentedThanks, that's a very clear explanation.
drush migrate-destroy calls drush_migrate_tools_migration_list, which is exactly the same function called by drush migrate-status and drush migrate-import. I don't know if you are able to test again - it would be interesting to know if the 12 migrations above are also missing from those other commands. Perhaps they are missing from the list because a module was uninstalled, a field deleted or some other config changed?
Comment #8
cestmoi commented@AdamPS sorry for the late reply.
I'd uninstalled all migration modules and no more migration commands are available in drush anymore and
drush migrate-statusreturnsCommand "migrate-status" is not definedmessage.Comment #9
heddnI had forgotten about this issue. I've requeued it for tests. And I wonder
I've started doing the parameters into the method a little differently. It seems cleaner and makes the number of params for the method much shorter. Key is to remember to pass it @default $options [] in the annotations.
Also, I'd like to see some tests. This project now has 3 different kernel tests you could extend or clone to add coverage.
Comment #10
adamps commentedThanks @heddn, that all makes sense.
I have run out of time to work on this one right now, but hopefully someone else might find time to take up your suggestions.
Comment #11
heddnThere's all new test coverage now for drush commands. This should be an easy thing to incorporate and do using it.
Comment #12
damienmckennaShould the command be called "migrate-cleanup" instead of "migrate-destroy"? The problem is that the migrate system doesn't clean up after itself like it should, not that there needs to be an extra way of destroying data.
Comment #13
damienmckennaThis is the same as the original patch, just with the everything renamed to reference "Cleanup".
Comment #14
ressaUpdated patch with the command updated from
migrate:destroytomigrate:cleanup.Comment #15
ressaSorry, I forgot the
interdiff.Comment #16
codebymikey commentedAttached a patch for the 5.x branch
Comment #17
heddnmigrate:idmap-destroyis maybe a better name. Of course, naming is hard. But from a discoverability perspective, I think many folks would be looking for destroy or delete. And cleanup isn't very descriptive of that is actually happening.I also considered
migrate:idmap-delete, but that could be taken as deleting a row in the id map. Andmigrate:idmap-table-destroyseemed like too much of a mouthful.Also NW for test coverage.
Comment #18
codebymikey commentedComment #20
codebymikey commentedRerolled for 6.0.x as well as Drush 12.
Still needs to implement tests, as well as account for situations where the source database is no longer accessible.
Comment #21
heddnThis looks really great!!! Thanks for picking this up.
For consistency, we call this
$migration_idin other places.Could we add a test case for this command?
Comment #22
istryker commentedreroll patch
Comment #23
heddnThis is pretty close. Can we fix the phpcs, etc issues and add a test case? That's all that is missing from landing this.
Comment #24
ressaThis will be a great feature. I wonder if the words "delete migration tables" should be included in the description, to make it clearer what the command actually does ... it could be something like this?
Now
* Destroy persistent status for one or more migrations.Better?
* Destroy persistent status for one or more migrations, deleting migration tables.Comment #26
bhanu951 commentedI have fixed the phpcs and phpstan issues.
Tests still need to be added.
@heddn do you want me add full tests similar to the below MR or do you have any suggestions ?
https://git.drupalcode.org/project/drupal/-/commit/d4abe119f885d41104b98...
Comment #27
ressaUntil this gets committed, could a pragmatic workaround be to list all Migrate tables, and then run a Drush command for each?
... update the list to this, and run in batches of 25 lines at a time?