Problem/Motivation

The 3 modules Migrate, Migrate_drupal, Migrate_drupal_ui didn't implement any method to remove these tables or other data related to migration and have no use after complete migration.

After uninstall of migration modules the tables created are not removed. It is not reasonable to not have a mechanism to remove these tables.

Why are these tables left after uninstall of the migration modules
Since this is frequently asked, here is a summary.
The tables remain after the migration because they provide the necessary information to fix problems that may discovered later, even after initial testing of the migration results. It is completely up to you to choose when to remove the migrate tables. But do so with the knowledge that if problems appear later and are traced back to the migration, it will be very difficult, if possible at all, to fix. See #11 and #22

Proposed resolution

Create form to delete migration tables both those with a current migration and those without a migration.
Use the existing destroy method on id_map/Sql.php.
Add a menu item at admin/reports

Listing page - No message tables

Listing page - two tables

Confirm page:

Success message:

New documentation page - https://www.drupal.org/docs/upgrading-drupal/after-the-upgrade

Remaining tasks

Reviews
#44

User interface changes

New form to list and delete migrate tables.

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#149 2713327-149.patch17.68 KBquietone
#149 interdiff-145-149.txt992 bytesquietone
#149 Confirm.png28.03 KBquietone
#145 2713327-145.patch17.69 KBquietone
#145 interdiff-141-145.txt8.04 KBquietone
#141 2713327-141.patch17.7 KBquietone
#141 interdiff-140-141.txt5.45 KBquietone
#140 2713327-140.patch17.73 KBquietone
#140 interdiff-138-140.txt9.16 KBquietone
#138 2713327-138.patch17.55 KBquietone
#138 interdiff-137-138.txt206 bytesquietone
#137 2713327-137.patch17.56 KBquietone
#137 interdiff-134-137.txt897 bytesquietone
#136 Screenshot_2020-12-26 Reports dev1-web.png28.62 KBquietone
#136 Screenshot_2020-12-26 Delete migration tables dev1-web.png45.77 KBquietone
#134 interdiff_131-134.txt1.88 KBressa
#134 2713327-134.patch17.45 KBressa
#131 interdiff_129-131.txt460 bytesressa
#131 2713327-131.patch17.45 KBressa
#129 2713327-129.patch17.45 KBayushmishra206
#128 2713327-128.patch17.45 KBayushmishra206
#128 interdiff_125-128.txt533 bytesayushmishra206
#125 2713327-125.patch17.42 KBquietone
#125 interdiff-121-125.txt1.34 KBquietone
#125 DeletedConfirmation.png54.81 KBquietone
#125 AreYourSure.png34.79 KBquietone
#125 TwoMessageTables.png50.57 KBquietone
#125 NoMessageTables.png40.02 KBquietone
#121 2713327-121.patch17.4 KBquietone
#121 interdiff-117.121.txt8.5 KBquietone
#117 2713327-117.patch14.54 KBquietone
#117 interdiff-115-117.txt5.79 KBquietone
#115 2713327-115.patch14.49 KBquietone
#115 interdiff-113-115.txt3.8 KBquietone
#113 Confirm.png19.2 KBquietone
#113 AreYouSure.png20.5 KBquietone
#113 List of upgrades.png18.34 KBquietone
#113 2713327-113.patch14.5 KBquietone
#113 interdiff-105-113.txt10.57 KBquietone
#106 Screen Shot 2019-04-29 at 2.21.55 PM.png54.17 KBedysmp
#106 Screen Shot 2019-04-29 at 2.21.30 PM.png49.15 KBedysmp
#106 Screen Shot 2019-04-29 at 2.21.21 PM.png48.31 KBedysmp
#106 2713327-106.patch14.45 KBedysmp
#106 interdiff-100-106.txt9.93 KBedysmp
#100 2713327-100.patch11.42 KBedysmp
#100 interdiff-99-100.txt616 bytesedysmp
#99 2713327-99.patch11.42 KBedysmp
#99 interdiff-94-99txt.txt811 bytesedysmp
#96 Selection_011.png21.65 KBjfurnas
#96 Selection_012.png45.49 KBjfurnas
#94 2713327-94.patch11.38 KBedysmp
#94 interdiff-93-94.txt9.38 KBedysmp
#93 2713327-93.patch6.8 KBedysmp
#92 Selection_009.png48.01 KBjfurnas
#85 Selection_006.png61.75 KBjfurnas
#81 2713327-81.patch6.8 KBedysmp
#81 interdiff_79-81.txt4.13 KBedysmp
#79 2713327-79.patch7.6 KBedysmp
#79 interdiff_76-79.txt6.87 KBedysmp
#76 2713327-76.patch8.01 KBedysmp
#76 interdiff_75-76.txt3.47 KBedysmp
#75 2713327-75.patch4.32 KBedysmp
#75 interdiff_73-75.txt2.24 KBedysmp
#73 2713327-73.patch3.87 KBedysmp
#44 2713327-44.patch1.21 KBphenaproxima
#32 remove_migration_tables-2713327-31.patch2.6 KBsophie.sk
#30 remove_migration_tables-2713327-30.patch2.59 KBsophie.sk
#29 remove_migration_tables-2713327-29.patch2.63 KBsophie.sk
#21 migrate.patch2.75 KBandrew answer
#3 drop_migration_tables_during_uninstall.patch2.7 KBmhmd

Issue fork drupal-2713327

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mhmd created an issue. See original summary.

catch’s picture

Title: Remove migration tables during uninstall » Migration tables (ID map etc.) don't get removed
Priority: Critical » Major
Issue tags: +Migrate critical

Migrate is still experimental, so moving to major and tagging 'migrate critical' instead.

The ID map table will be removed in MigrateIdMapInterface::destroy() - however I don't see that called anywhere outside tests so think you're right that at the moment there's no straightforward way to remove the tables.

mhmd’s picture

I have implemented the hook_install && uninstall hooks in migrate.install to drop all tables prefixed with migrate except those where found during module installation (may be other contributed or custom modules defines tables prefixed with migrate) which is not a good decision.

Please review and test.

swentel’s picture

I don't see why this is a bug report, having those tables actually still around is interesting for figuring out what was migrated, what status they have and messages (if any). This allows you to even write custom post migration scripts to fix or do additional things that aren't in a plugin at the moment or aren't straightfoward to handle.

So to me this is a task, not a bug.

- edit - oh wait, on uninstall .. that's different, I need to read everything :)
I'd say this is a normal bug report though :)

cilefen’s picture

Priority: Major » Normal

Agreed–I do not see that having extra tables in a database qualifies as Major.

catch’s picture

Issue tags: -Migrate critical

Which means not migrate critical either. If there was a problem re-installing it'd be different, but because the tables are created when needed that shouldn't be an issue.

ckaotik’s picture

Personally, when I uninstall a module and read

The following modules will be completely uninstalled from your site, and all data from these modules will be lost!

I kind of expect the migration map tables to be part of "all data". Drupal\migrate\Plugin\migrate\id_map\Sql::destroy() implements exactly this functionality (and is currently the only id_map core knows).

I see two main options we could implement:

  1. Implement hook_uninstall and run destroy() on all migrations' id_map plugins, as long as the migrations requirements are met. This ensures that only tables stemming from our migrations are affected.
  2. Provide some other means to run destroy(), e.g. via a button on a (not yet existing) migrate configuration page or a drush command in Contrib
JoshOrndorff’s picture

Just to confirm:
In the meantime, Is it safe for me to manually drop these tables?

chegor’s picture

Version: 8.1.0 » 8.2.4

Confirming that problem still available for 8.2.4
Decision with manual removing tables works for me

joelpittet’s picture

Version: 8.2.4 » 8.4.x-dev
claudiu.cristea’s picture

+1 for #4. Those tables should not be removed. The behavior it's not a bug, it's intentional. The same behavior was in the Migrate module.

rodrigoaguilera’s picture

I feel that if you need to keep the references from the maps you can just keep the migrate module installed.

chegor’s picture

Let's think about next use case:
I enabled modules for migration (incl. "Migrate_drupal_ui").
I migrated content by using UI.
Now have drupal8 and want to live with it.

What is the point of having an interface for migration and not be able to remove everything (by using UI/uninstalling modules) that I do not need after the migration has been completed?

rocketeerbkw’s picture

Here's another use case for removing them:

I have migrations running on cron on Drupal 8.0.x. I upgraded to 8.2.x, and all the migrations are broken. I can fix the migration and custom source plugins easily (simple migrations, not migrate_drupal), but I'm still stuck because there is no upgrade path between migrate module versions, see for example https://www.drupal.org/node/2679797.

I'd like to just rollback all content, uninstall all migrate related modules, upgrade drupal, then re-install migrate and import the new content. That fails because there are still all the old map and message tables with invalid schema.

When I uninstall a module, I want to start from scratch. I believe that was the reasoning for removing the "disabled" status for modules.

rewted’s picture

So the solution is to drop any table with migrate_map_* or migrate_message_* ?

merilainen’s picture

Dropping tables sound reasonable, at least it would offer a way to start from scratch without deleting tables from database manually.

ckaotik’s picture

Dropping the tables is fine and safe as long as you delete both map and message tables. To delete all tables of currently present migrations, you can run something like this before uninstalling the module:

  // Specify migration ids. An empty array means "all migrations".
  $migrations = [];
  $plugin_manager = \Drupal::service('plugin.manager.migration');
  $instances = $plugin_manager->createInstances($migrations);

  foreach ($instances as $id => $instance) {
    $instance->getIdMap()->destroy();
  }
eneko1907’s picture

Per conversation with Mike, the process described in #3 and #17 present challenges.

It would be safer to check and delete the tables in the state, rather than scan the tables prefixed with migrate. Why? it could happen that other contrib or custom module creates tables whose name would begin with migrate -- therefore, the uninstall process suggeted here would result in bad consequences (break other modules)

mhmd’s picture

@eneko1907, I wrote the code to scan the DB before starting the migration process and store all tables starting with migrate in a variable.

When uninstall drop the tables not present in that variable.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andrew answer’s picture

StatusFileSize
new2.75 KB

I found the problem with #3. When you patch 'migrate' module with this patch and try to uninstall module, you get

in_array() expects parameter 2 to be array, null given migrate.install:57

because you haven't prefixed_migrate_tables variable in DB.
I fixed the patch to check this situation. Minor styling added also.

quietone’s picture

Thanks everyone for working on this.

I am concerned that the tables will be removed prematurely. That is, before the site is thoroughly tested or without the user fully understanding the risk. Whatever solution is taken to remove the tables it really should include a warning (in big red scary letters) that those tables are needed to fix problems with the migration. They need to be left until they are 100% sure that the site has been thoroughly tested. And that once removed, it may not be possible to fix a problem.

mhmd’s picture

I totally agree with you @quietone, we shall display the list of tables and let the user take the action either delete or keep the tables.

sopranos’s picture

yes that is what I am talking about......I installed just a core drupal 8 site...used migrate to migrade D6 site, it was just a standard site, nothing fancy.....few blog posts...few pages......nothng major, no extra field, custome stuff.....it has like 70 tables in drupal 6.....but after using coremigrate module.....the number of tables jumped to over 220.....which is a disaster..because blue host limits me with 1000 tables per hostig acccount.....so I want to save on tables.....

somebody needs to fix this...this module is just a disaster.....

quietone’s picture

@sopranos, thanks for reporting your problem with the extra tables. As pointed in #11 and #22 the tables are left after the upgrade so that it is possible to fix any problem. It is up to the user to delete them, knowing that it will make fixing problems with the upgrade difficult. But once you are completely sure the new site is functioning as expected it is perfectly OK to drop the tables by whatever means available to you.

To help fix this, you could try the patch in #21 in a test environment and report the results here.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hudri’s picture

I've got the same issue as @rocketeerbkw in #14.

Uninstall module => reinstall module => migration failed because of invalid old table schema. For me this is a bug, and the tables should be removed on uninstall.

I can't follow the reasoning behind "leaving the tables so user can fix problems with migration"... when the user uninstalls the module, his intentions are obvious. IMHO the current handling is counter-intuitive.

sopranos’s picture

 

sophie.sk’s picture

StatusFileSize
new2.63 KB

Rerolled the patch and tidied it up. I don't like the solution but we need to get rid of the tables (we have over 1,100 on our site right now) so it'll do for the short term.

I'd be interested in trying out the destroy() method.

sophie.sk’s picture

Status: Active » Needs review
StatusFileSize
new2.59 KB

Oh no! Updated file paths :)

Status: Needs review » Needs work

The last submitted patch, 30: remove_migration_tables-2713327-30.patch, failed testing. View results

sophie.sk’s picture

Status: Needs work » Needs review
StatusFileSize
new2.6 KB

Aaaaaaand fixing a PHP problem that I forgot to fix duh

Status: Needs review » Needs work

The last submitted patch, 32: remove_migration_tables-2713327-31.patch, failed testing. View results

heddn’s picture

We discussed in the migrate maintainers meeting. One option very much liked was to delete tables and remove all the mapping tables when migrate API module is un-installed. If a module depends on the mapping tables, then they need to keep the migrate module enabled.

Ideally we'd like to provide an extra confirm explaining to users that when they uninstall the migrate module, the mapping tables will disappear. Are they sure they want to do this? Because if they do disable it, then they have no way to get that data back except from database backup, etc.

On one hand, it would make sense to delete the tables on uninstall. On the other hand, deleting the tables is a new feature and would be un-expected. And could break a lot of folks.

masipila’s picture

When a module is being uninstalled, there is a final confirmation that says like this:
--clips--
The following modules will be completely uninstalled from your site, and all data from these modules will be lost!

  • Migrate

Would you like to continue with uninstalling the above?
--clips--

This text comes from here:
https://api.drupal.org/api/drupal/core%21modules%21system%21src%21Form%2...

We could and should alter this form and add a big fat warning that by uninstalling Migrate, the map tables will be lost forever.

Cheers,
Markus

sophie.sk’s picture

Is it not fair to say that if a module relies on the migration map tables, they should add a dependency on the migrate module(s) (therefore the migrate module(s) can't be uninstalled without first uninstalling the module that depends on it)?

The message "all data will be lost" implies that the default behaviour of removing all tables this module has created will be removed. The fact it doesn't remove the data seems like an anti-pattern.

phenaproxima’s picture

@Sophie.SK makes an excellent point. We could just make Migrate remove the tables on module uninstallation, and update our handbook documentation to explain what will happen when Migrate is uninstalled, so that it's at least documented and not a gotcha! for people who need the map tables to stick around.

heddn’s picture

I'm a little unsure of deleting on uninstall. However, if we do it, we should early in the life of 8.6 and see what feedback we get on it. And not do in 8.5. Too much chance of breaking folks.

phenaproxima’s picture

Are the mapping and messaging tables considered part of Migrate's API? I don't think they are, but I would rather get a framework manager's opinion on that (or at least a consensus from my fellow maintainers). If they are part of our API, I don't think we can unilaterally delete them on uninstall until D9 (although we could easily provide a helper function to do the job), since that'd break backwards compatibility.

masipila’s picture

Issue tags: +Needs documentation

@phenaproxima, what makes you think the map and message tables would not be part of Migrate API? In my opinion they very much are.

To summarize how I see this is as follows:
1. We have to have a way for a site builder to get rid of the tables when she/he considers the migrations to be completed and these tables are not needed anymore.

2. Regardless of the approach we choose, we need to document it in the handbook. Adding the 'Needs Documentation' tag for that.

3. For the actual deletion, we have two options as I see this:

3A: We delete the tables upon Migrate module uninstall.

  • If we choose to do this, we need to alter the uninstall form so that those users doing the uninstall with a browser will get the last warning that the map tables will be forever gone.
  • The (only) downside of this approach in my eyes is that modules can be also uninstalled with drush / drupal console.
  • At least 'drush pmu' will not show any final confirmation, it just does the uninstall.

3B: We provide a way how the user can nuke the tables using contributed Migrate Tools

  • This could be executed either with Drush...
  • ...or by using the browser UI Migrate Tools provided
  • This approach is safer in that sense that wiping out those tables requires an explicit execution of that specific 'nuke em all' command so it can't be a surprise for anyone.

I'm leaning towards 3B at the moment.

Cheers,
Markus

phenaproxima’s picture

If the tables are part of our API, I suggest adding an API method that can clean the tables up, which at least gives us a documentable way for developers to delete the map tables. I envision something like this:

\Drupal::service('plugin.manager.migration')->createInstance('my_migration')->getIdMap()->clean();

From there, we can file follow-up issues and patches to expose that function in install hooks, UIs, Drush commands, and so forth. But we should start there.

masipila’s picture

+1

heddn’s picture

I must be enough onboard with the suggestion in #41 that I want to start debating naming. So +1. We can build the API here and decide who uses it later. This really feels like one of those things that is just a PHP snippet that someone develops and those that care just run the snippet to remove all tables.

BTW, I prefer delete() over clean().

phenaproxima’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.21 KB

An initial attempt, without tests.

BTW, I prefer delete() over clean().

I disagree, because delete() is ambiguous. Are we deleting a specific mapping? Several mappings? The relevant tables or mapping storage? The word "delete" doesn't indicate anything specific. Since this new method is really a way to tell the ID map to clean up after itself, clean() makes that much more obvious. Self-documenting FTW!

heddn’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
    @@ -158,7 +158,12 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
    +      'keep_tables' => TRUE,
    

    How would this get overriden in practice? I don't see how the config is injectable. Maybe an example in the doxygen? NW for this point.

  2. +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
    @@ -999,4 +1004,12 @@ function (array $id) {
    +    if (empty($this->configuration['keep_tables'])) {
    

    If we call this clean, shouldn't the key also be called clean?

    I'm still not sure I like clean. Could we call it dropTables() and drop_tables => FALSE?

phenaproxima’s picture

How would this get overridden in practice? I don't see how the config is injectable.

Once migration plugins implement ConfigurablePluginInterface, it'll be easier to inject the configuration. In the meantime, I think we can pass ID map configuration in the migration definition, much the same way that we can configure the source and destination.

If we call this clean, shouldn't the key also be called clean?

No. "Clean" is a generic concept that could apply to any sort of ID map plugin. In Sql's case, cleaning involves dropping tables, so that configuration key is specific to Sql because it illustrates what it actually does.

I'm still not sure I like clean. Could we call it dropTables() and drop_tables => FALSE?

I don't want to name the method dropTables(), since that's Sql-specific and this method should ultimately go on MigrateIdMapInterface. But renaming the config key should be okay.

heddn’s picture

OK, clean (or cleanup) it is then. Needs work for tests and rekeying the config option.

benjy’s picture

--- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
+++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php

@@ -999,4 +1004,12 @@ function (array $id) {
+  public function clean() {

I'm not sure why the patch in #44 is adding a new method, #7 points out there is already a method to clean-up, can't we not call it if we don't want to run it?

For those interested, I ran this in a custom update hook before uninstalling migrate to clean-up.

  /** @var \Drupal\migrate\Plugin\MigrationPluginManager $pluginManager */
  $pluginManager = \Drupal::service('plugin.manager.migration');

  /** @var \Drupal\migrate\Plugin\Migration $migration */
  foreach ($pluginManager->createInstances(NULL) as $migration) {
    $migration->getIdMap()->destroy();
  }
yang_yi_cn’s picture

Priority: Normal » Major

How exactly can we delete the tables now, either in CMS, or using drush?

I think this is a major problem because when I writing a new migration and modifying the migrate yml files, it looks like the migrate_map_* tables are created when the config is imported first time, but there's no way to update the mapping table schema ever since. So when I change the number of fields, ids from 2 to 1. The ID map schema still expecting sourceid1, sourceid2 instead of just sourceid1 and it causes SQL errors.

quietone’s picture

@yang_yi_cn, you can use drush to delete the map table and it will be created when the migration is run again.

adamps’s picture

Priority: Major » Normal

#36 @Sophie.SK makes an excellent point:

The message "all data will be lost" implies that the default behaviour of removing all tables this module has created will be removed. The fact it doesn't remove the data seems like an anti-pattern.

My understanding is that the current patch does not delete the tables. So the user sees a message "all data will be lost", yet that does not happen, which is different from almost any other module. Potentially there are 100+ tables in the database that the user doesn't want - maybe even data they had deliberately not migrated for legal Data Protection reasons.

I propose that there should be a clear warning displayed to the user that data has been kept with a clear explanation of how to remove it.

adamps’s picture

My situation was that I had already uninstalled many migrate modules and removed the contrib module code from my server, and then I discovered the tables were still present. From a quick scan, I didn't see a comment above that explained what to do in that case.

Here's what I did - run the code from drush php and be careful, run at your own risk - check the output of the first command carefully before running the second.

$database_tables = db_query("SHOW TABLES LIKE 'migrate\_%'")->fetchCol();
foreach ($database_tables as $table) db_drop_table($table);
adamps’s picture

I'm now coming to the conclusion that keeping any data after a module is removed is a bad idea.

Remember that in D7 it was possible to disable a module without uninstalling it. However it didn't really work, as far as I can remember:

  • Migration hooks didn't run for the disabled module so the data was some poorly defined older version that might no longer be valid.
  • If you delete the module code before uninstalling then you are stuck - especially if it was custom code or a deleted insecure module.

Hence I believe D8 dropped the idea of disable and you can only uninstall, in which case D8 modules are expected to remove all their data. If migrate doesn't follow the rule, it opens up the above problems again, but even more confusing because it runs contrary to the D8 expected pattern. For example I found that the code from #48 fails to run if a single migration exists where the code from the uninstalled module is no longer present, and also see the problem in #49.

That all makes me think that migrate should conform to the D8 expected behavior. This suggests that when any migrate module is uninstalled, the corresponding migrations are deleted, because otherwise they become stale data that may not be valid later. However as per #35 we should

add a big fat warning that the map [& message] tables will be lost forever.

Will this be a surprise to people given it's the same as all other D8 modules? It seems natural to me to uninstall the migrate modules exactly when you are content the migration was successful and want to tidy up. If you aren't yet sure, would there be any disadvantage to keep the migrate modules enabled?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.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

Let's add this as an API addition only for now. Then the UI button to delete things can be a follow-up issue. Let's add an interface that adds the cleanup method. Then when the UI or drush needs to find migrations that clean-up after themselves, they can just check if the id_map implements the cleanup interface, list the migrations and give a button or confirmation to delete the map tables.

heddn’s picture

Category: Bug report » Feature request

Re-classifying

adamps’s picture

Title: Migration tables (ID map etc.) don't get removed » Provide a way to remove migration tables (ID map etc.)
Status: Needs work » Active
Issue tags: -Needs tests

It seems to me that @benjy is right in #48. We already have an API that does exactly the job: MigrateIdMapInterface::destroy. I'm not just speculating as I have a working implementation of a drush command using this.

Therefore can move on to the next steps?

Then when the UI or drush needs to find migrations that clean-up after themselves

I'm afraid that I don't follow. I found that calling destroy works on every migration with needing them to have special code to clean-up after themselves.

cestmoi’s picture

I need your advice please.

I'm done with all migrations and don't think I'm going to need to refer to the tables anymore and if did then I do have DB backups just in case. It would be lighter and tidier to move to production with over 100+ DB tables less.

I applied @AdamPS patch and not sure if best to uninstall the modules first or second or if it matters at all.

Drupal 8.6.1
Drush 9.4.0

Thanks

adamps’s picture

@cestmoi

not sure if best to uninstall the modules first or second or if it matters at all.

You should destroy the migrations first and uninstall the modules second. (If you no longer have the modules, then are stuck with the hack in #52.)

If it works for you, the please set the other issue to RTBC.

cestmoi’s picture

@AdamPS

If it works for you, the please set the other issue to RTBC.

Done successfully but didn't update the other issue for the reason mentioned there (12 tables still not-destroyed).

Thanks for the patch :)

heddn’s picture

Issue summary: View changes
Status: Active » Needs work
Issue tags: -Needs documentation

Discussed in migrate maintainers meeting with @mikelutz, @phenaproxima, @quietone, @heddn today. The question came up about do we really need an interface. In 9.0 we'll probably have enough changes in the migrate map plugin system that these might not exist in their current form. And we aren't aware of any non-SQL based id maps. So, to keep things easier, it was proposed to add to the existing sql id map concrete class (w/o any interface). Then we can just do an instance_of check when we iterate over id maps and only call the sql based ones.

The method to add on the sql map is dropTables(). Add it there, and add tests that when it is called we do in fact destroy the mapping and message tables.

In a follow-up (let's open one), we will then add into migrate_drupal_ui an admin page w/ checkboxes and the ability to drop on a per migration basis the backing tables for migrations. I'll let that issue flesh out the UI and if we really want to use checkboxes and how it looks, but this should give an implementer an idea of architecturally what we are looking for.

adamps’s picture

@heddn thanks for taking time to move this one forward.

However I still don't understand why we need a new dropTables() method. We already have an API that does exactly the job: MigrateIdMapInterface::destroy.

  /**
   * {@inheritdoc}
   */
  public function destroy() {
    $this->getDatabase()->schema()->dropTable($this->mapTableName());
    $this->getDatabase()->schema()->dropTable($this->messageTableName());
  }

Excuse me for repeating myself, but I don't yet see that anyone has explained why I'm wrong.

stompersly’s picture

If you just want to manually delete the tables this will generate the SQL statements to do it, after running this SQL select print text with full view at the bottom of phpMyAdmin to show the full names and then copy and run the generated statements.

SELECT CONCAT('DROP TABLE ',  `TABLE_NAME`, ';') 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_NAME LIKE 'migrate_message_%' OR TABLE_NAME LIKE 'migrate_map_%';
rewted’s picture

Is this still a required step, if so what are the pros and cons of taking this action?

sopranos’s picture

I used drop tables in migration tables and it worked out fine....no problems now for over 1 year

quietone’s picture

Issue summary: View changes

Added a brief statement to the IS explaining why the tables are not removed on uninstall.

heddn’s picture

Reviewed in weekly migration maintainers call. Here's some thoughts.

Generate a Form (and route) in Drupal console in the migrate module. This form lists all migrations with a checkbox in front of it. It's submit handler instantiates all the selected migrations, then calls the id map on them and finally, calls destroy. Then print out what migrations were successfully removed. Profit.

heddn’s picture

Also, patches accepted in migrate_tools downstream that do similarly.

adamps’s picture

Also, patches accepted in migrate_tools downstream that do similarly.

There is an initial version of a patch to add a drush command here #2997576: Provide a drush wrapper to destroy/delete migration tables.

rewted’s picture

@heddn So will the patch be pushed the current sable and remove the old migration data once uninstalled, or still a manual process?

heddn’s picture

I envision the automated uninstall to be a follow-up. Let's add a manual process, then discuss how we want to make that automated.

edysmp’s picture

Assigned: Unassigned » edysmp

Working on #67

edysmp’s picture

Assigned: edysmp » Unassigned
StatusFileSize
new3.87 KB

Addressing #67

heddn’s picture

Issue tags: +Needs tests

Can we add a Functional test of this too?

+++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
@@ -0,0 +1,123 @@
+    $migration_plugins = array_filter($migration_plugins, function ($migration) {
+        return $migration->getIdMap()->importedCount();
+    });

I think we want to remove all migrations that have migrate mapping and message tables. Not just if they are empty or not.

edysmp’s picture

StatusFileSize
new2.24 KB
new4.32 KB

Thanks for review @heddn.
I am attaching a patch to destroy migrations that have migrate map or message tables.
This still needs tests.

edysmp’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.47 KB
new8.01 KB

adding tests.

heddn’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
    --- /dev/null
    +++ b/core/modules/migrate/tests/modules/remove_migration_tables/migrations/remove_migration_tables.yml
    
    +++ b/core/modules/migrate/tests/modules/remove_migration_tables/migrations/remove_migration_tables.yml
    @@ -0,0 +1,15 @@
    diff --git a/core/modules/migrate/tests/modules/remove_migration_tables/remove_migration_tables.info.yml b/core/modules/migrate/tests/modules/remove_migration_tables/remove_migration_tables.info.yml
    

    Rather than creating a new test module, could we use migrate_external_translated_test or migrate_high_water_test or migration_directory_test?

  2. +++ b/core/modules/migrate/tests/src/Functional/RemoveMigrationTablesTest.php
    @@ -0,0 +1,67 @@
    +    $type = $this->container->get('entity_type.manager')->getStorage('node_type')
    +      ->create([
    +        'type' => 'article',
    +        'name' => 'Article',
    +      ]);
    +    $type->save();
    

    It is more typical for this to be:

        // Create the node bundles required for testing.
        $type = NodeType::create([
          'type' => 'article',
          'name' => 'Article',
        ]);
        $type->save();
    
  3. +++ b/core/modules/migrate/tests/src/Functional/RemoveMigrationTablesTest.php
    @@ -0,0 +1,67 @@
    +    $this->container->get('router.builder')->rebuild();
    

    This shouldn't be necessary.

  4. +++ b/core/modules/migrate/tests/src/Functional/RemoveMigrationTablesTest.php
    @@ -0,0 +1,67 @@
    +    $account = $this->drupalCreateUser(['access administration pages']);
    

    Create the user in setup above. Like

        // Create some users.
        $this->adminUser = $this->drupalCreateUser(['access administration pages']);
    
  5. +++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
    @@ -0,0 +1,141 @@
    +  public function buildForm(array $form, FormStateInterface $form_state) {
    

    This form could use some preliminary text stating what the form will do. That with it you can remove migration mapping and message tables. This is a process that is not reversible and if you delete the table it cannot be restored. The tables can be useful after migrations have run for troubleshooting. Remove them only with caution.

  6. +++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
    @@ -0,0 +1,141 @@
    +    // $migration = \Drupal::service('plugin.manager.migration')->createInstance('d6_user');
    +
    +    // $executable = new MigrateExecutable($migration);
    +    // $executable->import();
    

    Let's remove this commented out code.

  7. +++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
    @@ -0,0 +1,141 @@
    +    // Collect migrations that have migrate map or message tables on the database.
    

    Longer than 80 chars.

  8. +++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
    @@ -0,0 +1,141 @@
    +      '#empty' => $this->t('No migrations available.'),
    

    This might read, "No migration tables exist."

  9. +++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
    @@ -0,0 +1,141 @@
    +      if (!empty($value)) {
    

    Could we just do if ($value) {?

  10. +++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
    @@ -0,0 +1,141 @@
    +        '#markup' => $this->t('The following migrations have been detroyed.'),
    
    +++ b/core/modules/migrate/tests/src/Functional/RemoveMigrationTablesTest.php
    @@ -0,0 +1,67 @@
    +    $this->assertSession()->pageTextContains('The following migrations have been detroyed.');
    

    Misspelling of 'destroyed'.

edysmp’s picture

Assigned: Unassigned » edysmp

Working on #77

edysmp’s picture

Assigned: edysmp » Unassigned
Status: Needs work » Needs review
StatusFileSize
new6.87 KB
new7.6 KB

addressing #77

heddn’s picture

Issue tags: +Needs screenshots, +Novice

Closer. Looking very nice. Can we get a screenshot of the the page added to the IS? Tagging Novice for the screenshot.

  1. +++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
    index 0000000000..b30cbb470b
    --- /dev/null
    
    --- /dev/null
    +++ b/core/modules/migrate/tests/modules/migrate_external_translated_test/migrations/remove_migration_tables.yml
    
    +++ b/core/modules/migrate/tests/modules/migrate_external_translated_test/migrations/remove_migration_tables.yml
    +++ b/core/modules/migrate/tests/modules/migrate_external_translated_test/migrations/remove_migration_tables.yml
    @@ -0,0 +1,15 @@
    
    @@ -0,0 +1,15 @@
    +id: remove_migration_tables
    +label: Remove Migration Tables
    +source:
    

    I don't think we need a new yml file. Just use one of the existing ones in these test modules.

  2. +++ b/core/modules/migrate/tests/src/Functional/RemoveMigrationTablesTest.php
    @@ -0,0 +1,66 @@
    +    $this->adminUser = $this->drupalCreateUser(['access administration pages']);
    

    This should be done in setup. And we're missing the definition of protected $adminUser at the class level.

  3. +++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
    @@ -0,0 +1,141 @@
    +      '#markup' => '<p>' . t('With this form you can remove migration mapping and message tables. This is a process that is not reversible and if you delete the table it cannot be restored. The tables can be useful after migrations have run for troubleshooting. Remove them only with caution.') . '</p>',
    

    "if you delete the table it cannot be restored"...

    Let's make that a plural, 'tables'.

edysmp’s picture

StatusFileSize
new4.13 KB
new6.8 KB

addressing points of #80. This still needs a screenshot.

quietone’s picture

@edysmp, thanks for moving this along.

I've only just skimmed the patch and what strikes me is 'remove' when elsewhere in Drupal 'delete' is used. I think, that once we have a screenshot we need to tag this (which tag?) for the UI folks to check the wording.

edysmp’s picture

Status: Needs review » Needs work
Issue tags: +Suggested wording

Thanks @quietone for the review, maybe this tag it's could work?

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jfurnas’s picture

StatusFileSize
new61.75 KB

I have attached a screenshot of the /admin/migrate/destroy page

jfurnas’s picture

Status: Needs work » Needs review
heddn’s picture

jfurnas’s picture

@heddn does the screenshot I provided work?

heddn’s picture

Issue summary: View changes

re #88, it is perfect. Which is why we can now proceed to usability review.

quietone’s picture

Nice work, really pleased to see the progress.

The page title should be in sentence case

+++ b/core/modules/migrate/migrate.routing.yml
@@ -0,0 +1,8 @@
+    _title: 'Remove Migration Tables'

Page title should be sentence case. "Remove migration tables". See https://www.drupal.org/node/604342

What is displayed if there are no migrations tables? Can there be a screenshot of that case?

+++ b/core/modules/migrate/src/Form/RemoveMigrationTables.php
@@ -0,0 +1,141 @@
+      '#markup' => '<p>' . t('With this form you can remove migration mapping and message tables. This is a process that is not reversible and if you delete the tables it cannot be restored. The tables can be useful after migrations have run for troubleshooting. Remove them only with caution.') . '</p>',

If this is going to have 'caution' message then I think it should also have a confirmation form. Give folks a chance to back out. Apologies if it there I am missing it.

Leaving at NR to not block a usability review.

rewted’s picture

Regarding #85, wording in the screenshot may not be understood. "The tables can be useful after migrations have run for troubleshooting."

1. In the case of an unsuccessful migration, would the average user know how to use these tables for troubleshooting?
2. If a migration appears successful, should migration tables be deleted?

Lets face it, most individuals will simply browse the site to confirm content has been migrated. Perhaps outline when the migration tables should or should not be deleted? :)

jfurnas’s picture

StatusFileSize
new48.01 KB

I have attached a new screenshot. I am not a UX or Content reviewer by any means, but I feel that the section inside the help text that says 'if you delete the tables it cannot be restored.' should read 'if you delete the tables they cannot be restored.'

edysmp’s picture

StatusFileSize
new6.8 KB

Thanks to all for reviewing this.
I am fixing some wording issues:
#82
#90.1
#92

edysmp’s picture

StatusFileSize
new9.38 KB
new11.38 KB

Adding a Confirm form.

jfurnas’s picture

In testing #94 to get the screenshots, I noticed two things:

#1) The 'Delete Migration Tables' button is no longer available, and has been replaced by a link.

#2) The confirmation page displays li elements not selected on the previous form as '0'. So for example if you only selected one of the elements to delete out of 5, the remaining 4 elements on the confirm page show up as

  • 0
  • . I have attached a couple of screenshots for clarity.

    EDITED for correctness. I prematurely assumed the danger--button was broken. After looking further, I think that's the default behavior for buttons that are danger. In looking at other places in the UI, I had a hard time finding any other places this button was used, so I wonder if for consistency we should just leave it as the button--primary that appears on the confirmation page.

    jfurnas’s picture

    StatusFileSize
    new45.49 KB
    new21.65 KB

    Will remove the files from display once this issue is resolved, and replace them with two accurate screenshots.

    edysmp’s picture

    Thanks @jfurnas for a quick review. I will check it.

    jfurnas’s picture

    I revised my review in my previous comment. Please re-review it for more accurate information :)

    edysmp’s picture

    StatusFileSize
    new811 bytes
    new11.42 KB

    Only show seleted migrations.

    edysmp’s picture

    StatusFileSize
    new616 bytes
    new11.42 KB

    Turn back primary button.

    heddn’s picture

    Leaving at NR for UX feedback, but here's some things I'd like to see addressed from a non visual perspective.

    1. +++ b/core/modules/migrate/migrate.routing.yml
      @@ -0,0 +1,16 @@
      +  requirements:
      +    _access: 'TRUE'
      ...
      +  requirements:
      +    _access: 'TRUE'
      

      The access here should be tied to some type of more elevated permission. Anonymous shouldn't be able to delete migrations.

    2. +++ b/core/modules/migrate/tests/src/Functional/DeleteMigrationTablesTest.php
      @@ -0,0 +1,61 @@
      +    $this->submitForm($edit, 'Delete migration tables');
      +    $this->assertSession()->pageTextContains('Are you sure you want to delete migration tables?');
      +
      +    $this->submitForm([], 'Delete');
      

      Let's include an assertion for the names of migrations we expect to see and ones do no not expect to see on this confirm page.

    heddn’s picture

    Issue summary: View changes
    Status: Needs review » Needs work
    Issue tags: -Needs screenshots, -Needs usability review

    Feedback from today's UX meeting:

    • Wordsmith the text at the top of the page. Both on the first and confirm pages. They could probably repeat the same text.
      • Make it explicit on the top of confirm page what will be deleted. Perhaps:
      • Database tables related to the following migrations will be deleted. This is a process that is not reversible. If you delete the tables they cannot be restored. These tables can be useful after migrations have run for troubleshooting. Delete them only with caution.
    • Need to test w/ and w/o labels. If no label, then we shouldn't put the migration ID in parenthasis.
    • Wording for the submit button on the first page should change to: 'Delete tables'
    quietone’s picture

    Oooh, wordsmithing. This is interesting, and I just noticed it, that this is using 'migration' in the UI, where as previous work on the UI specifically avoided 'migration' in favor of 'upgrade'. Maybe the text should also change to 'upgrade tables'? I'm leaning that way right now.
    And let's change 'process' to 'action'

    Just trying out another text to see what it looks like.
    "Database tables for the following upgrades will be deleted. This action is not reversible. These tables are useful for troubleshooting and if deleted, they cannot be restored. Delete with caution."

    heddn’s picture

    re #103: previous UI rendering is part of migrate drupal ui, which is all about upgrading. These are changes added to migrate base module. So I feel that the terms, 'migrate' or 'migration' are appropriate. Since we are dealing with migrations in the migrate module. Not necessarily upgrade migrations.

    quietone’s picture

    @heddn, yes. good point. Migration is appropriate.

    edysmp’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new9.93 KB
    new14.45 KB
    new48.31 KB
    new49.15 KB
    new54.17 KB

    fixing #101 and #102.

    heddn’s picture

    Issue summary: View changes
    benjifisher’s picture

    Status: Needs review » Needs work

    Are the screenshots in the issue description up to date? (It looks as though they were updated earlier today.)

    The issue description does not mention the navigation to get to the "Delete migration tables" page.

    We discussed this again at the Drupal usability meeting - 2019-05-07 (recording on YouTube) and came up with some additional recommendations. Please either implement these as part of this issue or create follow-ups.

    Requirements

    1. Add a documentation page with more information. At least summarize the reasons discussed here for why one might want to keep the tables.
    2. Give instructions for making a backup (dump) of the tables to be removed.

    Nice to have

    1. In the table, say how big the tables are. (Probably the number of rows is the easiest measure.)
    2. Is there any good way in Drupal core to group the migrations instead of just listing them alphabetically?
    3. Make it easy to create a backup of the tables to be removed. Perhaps a download button on the "Delete migration tables" page. Perhaps show a SQL command for generating a backup of the selected tables either on that page or on the confirmation page.
    bunthorne’s picture

    Would it be feasible to create a report on deletion of the content of the tables rather than suggesting a backup?
    (Sorry if I'm in way over my head with this comment.)

    Version: 8.8.x-dev » 8.9.x-dev

    Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

    tjtj’s picture

    If we have uninstalled the migration modules, how do we use this patch to remove the tables?

    Version: 8.9.x-dev » 9.1.x-dev

    Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

    quietone’s picture

    Issue summary: View changes
    Status: Needs work » Needs review
    StatusFileSize
    new10.57 KB
    new14.5 KB
    new18.34 KB
    new20.5 KB
    new19.2 KB

    Revisited this and changed all references to 'migration' in the UI to upgrade and some other tweaks. See the screenshots in the IS.

    #018 Requirements 1 - Added a doc page, URL in the IS

    mikelutz’s picture

    Status: Needs review » Needs work
    1. +++ b/core/modules/migrate/src/Form/DeleteMigrationTables.php
      @@ -0,0 +1,144 @@
      +      return ($this->database->schema()
      +          ->tableExists($idMap->mapTableName()) || $this->database->schema()
      +          ->tableExists($idMap->messageTableName()));
      

      Indentation is wrong here.

    2. +++ b/core/modules/migrate/tests/modules/delete_migration_tables/delete_migration_tables.info.yml
      @@ -0,0 +1,6 @@
      +core: 8.x
      

      This isn't right for D9, It's breaking tests, I think we settled on not needing it anymore for test modules, but check.

    quietone’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new3.8 KB
    new14.49 KB

    This should address all the points in #114. The test needed some tweaking and I removed the unnecessary quotes from yml files.

    heddn’s picture

    Status: Needs review » Needs work
    +++ b/core/modules/migrate/src/Form/DeleteMigrationTables.php
    @@ -0,0 +1,143 @@
    +      'migration' => $this->t('Upgrade'),
    ...
    +      '#markup' => '<p>' . $this->t('Database tables related to the following upgrades will be deleted. This is a process that is not reversible. If you delete the tables they cannot be restored. These tables can be useful after upgrade for troubleshooting. Delete them only with caution.') . '</p>',
    ...
    +      '#empty' => $this->t('No upgrade tables available.'),
    
    +++ b/core/modules/migrate/src/Form/DeleteMigrationTablesConfirm.php
    @@ -0,0 +1,151 @@
    +    return $this->t('Are you sure you want to delete upgrade tables?');
    ...
    +        '#markup' => '<p>' . $this->t('Database tables related to the following upgrades will be deleted. This is a process that is not reversible. If you delete the tables they cannot be restored. These tables can be useful after upgrade for troubleshooting. Delete them only with caution.') . '</p>',
    ...
    +        '#markup' => $this->t('The following upgrade tables will be deleted.'),
    ...
    +          '#markup' => $this->t('The following upgrade tables have been deleted.'),
    

    Here (and maybe elsewhere). I'm not as keen on the name 'Upgrade" for deleting the migration map and message tables. We have the folks who use migrate for upgrades, but we also have many folks using it for migrations. And all the additions here are in the base API of migrate module. So I guess I'd vote for some name more akin to migrate.

    quietone’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new5.79 KB
    new14.54 KB

    OK, that make sense. Changes made.

    Does this need a menu entry?

    xurizaemon’s picture

    Exposing the tables to remove looks good.

    It seemed odd to me that it's at admin/migrate/destroy without a parent menu item, yep - should I see other items at admin/migrate?

    The text says "Database tables related to the following upgrades will be deleted." - I see your comment 103 above but I do feel like "migrate" is the right term here. I'm not yet familiar with the decision to rename "migrate" to "upgrade" (oh, this is UI stuff that I've missed, ok).

    I have a database which has a bunch of these old tables remaining but the migrations don't get picked up, because the Migration config items are already removed.

    With the patch currently, if there are no discovered migrations to clean up, we see an E_NOTICE in DeleteMigrationTablesConfirm::buildForm() where $migrations is not an iterable array.

    If we have uninstalled the migration modules, how do we use this patch to remove the tables?

    @tjtj, it doesn't look like this patch supports that usage. However if you're in that situation (as I am) you could do something like this.

    quietone’s picture

    Good point, I reckon we should include migrate tables that exist but the migration itself is no longer available.

    But how to display that? The current form uses the migration label and migration machine name as table headers. Neither of those exists for tables with no migration. And we can't assume that the part of the name after migrate_map_ or migrate_message_ is the migration name because the table names may be truncated.

    Ideas?

    xurizaemon’s picture

    We could add a second table (set of inputs) for "not associated with migrations" and handle those similarly. It would require separate presentation I think as the temp storage passes them by migration currently, and the second set would need to be passed by table name. Form validation would prevent someone tampering and deleting tables they shouldn't have access to.

    quietone’s picture

    Issue summary: View changes
    StatusFileSize
    new8.5 KB
    new17.4 KB

    Here is an attempt at adding the migration tables that exist in the db but do not have a migration. There are two values in the tempstore, 'migrations' and 'tables'. Just takes a bit of fiddling to get the list of tables without a migration. The Confirm form displays both, if they exist, and the final confirmation does as well. And I've added a menu item in admin/reports as suggested by xurizaemon.

    This will need some screenshots at some point.

    Status: Needs review » Needs work

    The last submitted patch, 121: 2713327-121.patch, failed testing. View results

    benjifisher’s picture

    Issue summary: View changes
    Issue tags: +Needs usability review, +Needs screenshots

    We discussed this issue at #3171562: [meeting] Migrate Meeting 2020-09-24 and agreed that the new table needs a re-review for usability, so I am adding the issue tag for that. In order to facilitate the review, we will need to update the issue summary (at least new screenshots as mentioned in #121).

    Version: 9.1.x-dev » 9.2.x-dev

    Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

    quietone’s picture

    Issue summary: View changes
    Status: Needs work » Needs review
    Issue tags: -Needs screenshots
    StatusFileSize
    new40.02 KB
    new50.57 KB
    new34.79 KB
    new54.81 KB
    new1.34 KB
    new17.42 KB

    Added updated screenshots to the IS, fixed the tests and changed the form description from 'Destroy ..' to 'Delete ...'.

    I think that the path should be '/admin/migrate/delete' instead of '/admin/migrate/destroy' but I haven't made those changes. Anyone agree with the suggestion?

    quietone’s picture

    Status: Needs review » Needs work
    Issue tags: +Novice
    +++ b/core/modules/migrate/src/Form/DeleteMigrationTables.php
    @@ -0,0 +1,163 @@
    + * Class DeleteMigrationTables.
    

    Change 'Class DeleteMigrationTables' to 'Provides a from for deleting migration table'

    And add @internal. See, say BookAdminForm.php, for an example.

    This change is suitable for a novice, adding tag. Remember to remove the tag when this work is done.

    ayushmishra206’s picture

    Assigned: Unassigned » ayushmishra206
    ayushmishra206’s picture

    Assigned: ayushmishra206 » Unassigned
    Status: Needs work » Needs review
    Issue tags: -Novice
    StatusFileSize
    new533 bytes
    new17.45 KB

    Made the changes suggested in #126.

    ayushmishra206’s picture

    StatusFileSize
    new17.45 KB

    Last patch had whitespace error.

    quietone’s picture

    @ayushmishra206, thanks for fixing this so quickly. Since you've uploaded #129 so soon after #128, it is a good idea to cancel the test for the patch in #128. Just click on 'PHP 7.3 & MySQL 5.7 Running' and there will be a cancel button.

    ressa’s picture

    StatusFileSize
    new17.45 KB
    new460 bytes

    Fixed typo ("from for" > "form for").

    EDIT: I don't see the cancel button @quietone, neither in the two tests started by @ayushmishra206, nor under my own test in this comment. Perhaps it's a question of permissions?
    EDIT2: I do see the "Cancel test" button in my own test now, so you can actually cancel a test if you started it, which makes sense.

    heddn’s picture

    Status: Needs review » Needs work
    +++ b/core/modules/migrate/migrate.routing.yml
    @@ -0,0 +1,16 @@
    +  path: '/admin/migrate/destroy'
    ...
    +  path: '/admin/migrate/confirm-destroy'
    

    Re #125: Delete is more in line with what we typically call these routes and action inside of Drupal.

    ressa’s picture

    Assigned: Unassigned » ressa
    ressa’s picture

    Assigned: ressa » Unassigned
    Status: Needs work » Needs review
    StatusFileSize
    new17.45 KB
    new1.88 KB

    I agree @quietone and @heddn: delete is more in line with naming conventions, this patch updates the path names.

    ressa’s picture

    I have updated the corresponding issue about Drush integration #2997576: Provide a drush wrapper to destroy/delete migration tables but am not sure if it will get picked up, since the Migrate Tools issue queue seems to have been shut down.

    Maybe the recent improvements in GitLab Integration with drupal.org makes it worth reconsidering opening the Migrate Tools issue queue at drupal.org?

    quietone’s picture

    Status: Needs review » Needs work
    StatusFileSize
    new45.77 KB
    new28.62 KB

    This needs work to not show an error when there are no migration tables.

    There is also an confusing mix of name when the patch from #3063856: Add ability to view migrate_message table data is applied as well. In one patch they are called Upgrade Messages and in the other Migrate Tables. We need to be consistent.

    quietone’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new897 bytes
    new17.56 KB

    Catch pdoexceptions when creating the migrations. That way, if the source db is not available the form will not fatal. And since the migrations are not created any migrate tables will be list in the 'Migration tables without migration' section.

    quietone’s picture

    StatusFileSize
    new206 bytes
    new17.55 KB

    Forgot to run commit-code-check.

    benjifisher’s picture

    Status: Needs review » Needs work

    In core, we avoid referring to "migration" in UI text, since the core UI only supports upgrades from earlier versions of Drupal. We should update the text to refer to "upgrade".

    This is especially important if #3063856 is committed in its current form. That issue and this one add links to the Administration > Reports menu, currently "Migrate tables" (this issue) and "Upgrade messages" (the other issue). Those links should use consistent terms. See the screenshot in #3063856-57: Add ability to view migrate_message table data.

    quietone’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new9.16 KB
    new17.73 KB

    Change UI text from migration to upgrade. And also change the delete form to show the migration label instead of the id.

    quietone’s picture

    StatusFileSize
    new5.45 KB
    new17.7 KB

    Renaming variables to be more like what is typically in migration files.

    quietone’s picture

    There is, at least, the following to do.

    With the patch from #3063856: Add ability to view migrate_message table data applied the page admin/reports now has 'Upgrade log' and 'Upgrade tables'. The link for 'Upgrade log' is 'admin/reports/upgrade' and for 'Update tables' it is 'admin/upgrade/delete', which is odd. The latter is added in this issue and should change, but to what?

    When there isn't a migration for existing migrate tables the following is displayed, 'Upgrade tables without migration'. That still uses migration and needs to be fixed. Haven't though of what to replace it with.

    All the UI text needs to handle singular and plural. And all the text needs review.

    New screenshots for the IS.

    heddn’s picture

    If we put this functionality into migrate.module, we shouldn't use upgrade in the UI elements. migrate.module provides an API. It doesn't provide an implementation for D2D upgrades. That's rather migrate_drupal_ui.module. So we should continue to call this "migrate" or "migration", given the implementation going into migrate.module.

    And for the record, I think this should go into the API module. People use the migrate module for lots of different things. We broke the features into parts that make logical sense. A module for an API, another for an upgrade implementation. Having a UI to clean-up migrations seems reasonable to put into the API module.

    benjifisher’s picture

    We discussed this issue at #3201985: Drupal Usability Meeting 2021-03-12. Thanks for updating the screenshots in the issue summary!

    It is a hard problem that the Migrate API serves different audiences. We try to avoid using the term "migrate" in the site upgrade process, so using it here could be confusing to upgraders. This is probably the audience that is most likely to want to delete the tables, and to do it from the UI. On the other hand, someone using the Migrate API for a different purpose, such as upgrading/moving/migrating (whatever they choose to call it) from another system, will be confused by "upgrade".

    The consensus at the meeting is that we should use the term "migrate" here, not "upgrade". I apologize for the back and forth on this point. On the plus side, this recommendation is consistent with #143.

    There are also two more specific suggestions that came out of the meeting:

    1. On the confirmation page, show the table name as well as the related migration.
    2. Do some more wordsmithing. For example, replace "This is a process that is not reversible" with "This action cannot be undone", which is used pretty consistently in Drupal.

    I will make a more specific suggestion for (2) when I have a little more time.

    quietone’s picture

    StatusFileSize
    new8.04 KB
    new17.69 KB

    This patch renames 'upgrade' to 'migration' for the forms. Also, changes the text for #144.2.

    #144.1. Can there be more clarification of how to display the migration name and the two map table names? For example for the D7 color migration the data is "Color", "migrate_map_d7_color", and "migrate_message_d7_color". The easiest is to implode them but that isn't very readable and will be even worse when multiple tables are deleted.

    This will need new screenshot too.

    Version: 9.2.x-dev » 9.3.x-dev

    Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

    quietone’s picture

    Issue tags: +Migrate UI
    mikelutz’s picture

    Status: Needs review » Needs work

    NW for 144.2, but looks like we need some additional comments from @benjifisher to clarify next steps.

    quietone’s picture

    Issue summary: View changes
    StatusFileSize
    new28.03 KB
    new992 bytes
    new17.68 KB

    144.2. Changed to 'this action cannot be undone.' Not running tests because this needs more work and it is a text only change.

    Updated the relevant screenshot.

    Version: 9.3.x-dev » 9.4.x-dev

    Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

    Version: 9.4.x-dev » 9.5.x-dev

    Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

    bob.hinrichs’s picture

    This patch will fix the following error, if anyone is trying this out: https://www.drupal.org/project/smtp/issues/3190531

    Drupal\Component\Plugin\Exception\PluginException: The plugin (d7_system_mail) did not specify an instance class. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (line 79 of core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php).
    Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('d7_system_mail', Array) (Line: 111)
    Drupal\migrate\Plugin\MigrationPluginManager->createInstances(Array) (Line: 79)
    Drupal\migrate\Form\DeleteMigrationTables->buildForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 531)
    Drupal\Core\Form\FormBuilder->retrieveForm('delete_migration_tables', Object) (Line: 278)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)

    solideogloria’s picture

    I ran into this issue for a different reason. I haven't finished migrations yet, but I found that when you revert your migrations then rename a couple migrations like so:

    migrate_plus.migration.b.yml => migrate_plus.migration.c.yml
    migrate_plus.migration.a.yml => migrate_plus.migration.b.yml

    What you are left with is that the migration map table for "b" in this example can have the wrong table structure/columns. I had to delete the tables and start over. While it's a good thing that the tables aren't removed on module uninstall (it's helpful to reinstall a module to pick up changes to custom migrations), it was certainly confusing why my migrations weren't working.

    Version: 9.5.x-dev » 10.1.x-dev

    Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

    Version: 10.1.x-dev » 11.x-dev

    Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

    quietone’s picture

    Issue summary: View changes
    Status: Needs work » Needs review

    The patch still applies.

    I am setting to Needs Review and noting that @benjifisher commented in #44 that he was going to add some more suggestions. Still, others can add reviews if they wish.

    solideogloria’s picture

    For those who do migrations via Drush, adding a Drush command to remove a migration table might be helpful. Otherwise, it is always possible to execute a DROP TABLE command in SQL via Drush.

    bhanu951’s picture

    For anyone who want to drop all migrate tables in one go, here is a command to do it

    drush sqlq --extra='-ss' "show tables like 'migrate_%'" | sed -r '/^\s*$/d' | while read TABLE ; do echo "drush sqlq 'DROP TABLE $TABLE;'" ; done
    

    credits to @xurizaemon on slack

    This command is dangerous and use it only if you know what you are doing. IT WILL DROP ALL MIGRATE TABLES.

    mikelutz’s picture

    Status: Needs review » Needs work

    Moving this back to NW, as it definitely needs some work. I'm also not sold on putting this in the migrate module. I feel like for core, We should add an option in migrate drupal UI to remove tables when done. We might also add a drush command to the core migrate drush commands to remove the tables. As far as a UX like this to remove all migration tables, I think it should live in migrate_tools. I'm hesitant to add any UX to the api module directly, I'm a fan of keeping that purely api. Outside of the migrate_drupal_ui, the migrate api requires migrations to be run through drush, migrate_tools UX, or custom code, and I feel like those are the places where table removal should happen. The api module should only provide an api method of removing the tables, which it does through MigrateIdMapInterface::destroy()

    wim leers’s picture

    Priority: Normal » Major
    Issue tags: +DX (Developer Experience)

    Ran into this again while migrating my own site. At minimum this needs clear documentation.

    The migrate_tools issue that #159 refers to (#2997576: Provide a drush wrapper to destroy/delete migration tables) has not progressed either, which is why I propose a pragmatic docs-only solution for core.

    The Drupal 7 EOL is in a few days, so many more people are bound to run into this very soon 😅

    ressa’s picture

    Until a Drush command or UI is ready, a documentation page with a solution on how to clean up migrate tables after upgrading from Drupal 7 to Drupal 10 would be great.

    I have updated After the upgrade, linking to this issue and #2997576: Provide a drush wrapper to destroy/delete migration tables, adding a Cleaning up, delete migration tables section.

    This page could also include a solution on how to take care of old, lingering blocks in configuration, as seen in #2694895: Single item import fails with validation errors from other config, so I have added a section Clean up orphaned blocks from a deleted theme.

    Ideally, both "Cleaning up, delete migration tables" and "Clean up orphaned blocks from a deleted theme" should contain solutions, and not just link to these issues, and anyone should feel free to add them to that doc page.

    bhanu951’s picture

    Re-Rolled patch from #149 against 11.x to bump the issue.

    bhanu951’s picture

    Status: Needs work » Needs review
    smustgrave’s picture

    Status: Needs review » Needs work

    Left comments on MR.

    mikelutz changed the visibility of the branch 2713327-provide-a-way to hidden.

    mikelutz’s picture

    Title: Provide a way to remove migration tables (ID map etc.) » Document ways to remove migration tables (ID map etc.)
    Category: Feature request » Task
    Priority: Major » Normal
    Issue tags: -Needs usability review, -Migrate UI

    Closing MR and hiding files as we decided on a documentation only solution for core. Work on a UI should be done in drush or migrate_tools.

    Version: 11.x-dev » main

    Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

    Read more in the announcement.