2

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

2 Answers 2

6

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

4

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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