Question

The official docs say this.

Revertable data patch - A patch that can be reverted as a module or patch is uninstalled or deleted.

I know that Revertable patches must implement Magento\Framework\Setup\Patch\PatchRevertableInterface and when a module is un-installed the logic in the revert() method is called.

How can one revert a Patch without uninstalling the module

Was it helpful?

Solution

Apparently the docs are incorrect|confusing. There is another page in the docs that clearly states

Magento does not allow you to revert a particular module data patch

OTHER TIPS

vitoriodachef is indeed correct, unfortunately there is no CLI command available to undo a data patch.

Depending on what kind of data patch you have made the quickest way is to call the revert() function from your patch:

//..patch class

    public function apply(): void
    {
        $this->revert();
        return; // (optional, to only execute revert and not patch)

        //...your patch code
    }

    public function revert(): void
    {
        //...your revert code
    }

If you have already executed your patch before then run the following query so that when you run bin/magento setup:upgrade --keep-generated your patch is executed again

DELETE FROM patch_list 
    WHERE patch_name LIKE '%Vendor\Module%' 
    ORDER BY patch_id DESC 
    LIMIT 1;
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top