Skip to content

magento/magento2#23847: Command "setup:db-declaration:generate-patch" does not add revert() method to patch #23848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

atwixfirster
Copy link
Contributor

@atwixfirster atwixfirster commented Jul 24, 2019

Description (*)

Fixed Issues (if relevant)

  1. Command "setup:db-declaration:generate-patch" does not add revert() method to patch #23847: Command "setup:db-declaration:generate-patch" does not add revert() method to patch

Manual testing scenarios (*)

Example with Magento_Cms:

bin/magento setup:db-declaration:generate-patch --revertable=true Magento_Cms TestPatch

Actual result:
app/code/Magento/Cms/Setup/Patch/Data/TestPatch.php is created with content without revert() method:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Cms\Setup\Patch\Data;

use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements
    DataPatchInterface
{
    /**
     * @var ModuleDataSetupInterface $moduleDataSetup
     */
    private $moduleDataSetup;

    /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     */
    public function __construct(ModuleDataSetupInterface $moduleDataSetup)
    {
        $this->moduleDataSetup = $moduleDataSetup;
    }

    /**
     * Do Upgrade
     *
     * @return void
     */
    public function apply()
    {
    }

    /**
     * {@inheritdoc}
     */
    public function getAliases()
    {
        return [];
    }

    /**
     * {@inheritdoc}
     */
    public static function getDependencies()
    {
        return [

        ];
    }
}

Expected result:
app/code/Magento/Cms/Setup/Patch/Data/TestPatch.php is created with revert() method in the content:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Cms\Setup\Patch\Data;

use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements
    DataPatchInterface, PatchRevertableInterface
{
    /**
     * @var ModuleDataSetupInterface $moduleDataSetup
     */
    private $moduleDataSetup;

    /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     */
    public function __construct(ModuleDataSetupInterface $moduleDataSetup)
    {
        $this->moduleDataSetup = $moduleDataSetup;
    }

    /**
     * Do Upgrade
     *
     * @return void
     */
    public function apply()
    {
    }

    /**
     * @inheritdoc
     */
    public function revert()
    {
    }

    /**
     * {@inheritdoc}
     */
    public function getAliases()
    {
        return [];
    }

    /**
     * {@inheritdoc}
     */
    public static function getDependencies()
    {
        return [

        ];
    }
}

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jul 24, 2019

Hi @atwixfirster. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

Copy link
Contributor

@dmytro-ch dmytro-ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atwixfirster, nice catch!
Could you please check the minor CR notices?
Please also check the automated test failures.

Thank you!

@@ -105,6 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
{
$moduleName = $input->getArgument(self::MODULE_NAME);
$patchName = $input->getArgument(self::INPUT_KEY_PATCH_NAME);
$includeRevertMethod = ($input->getOption(self::INPUT_KEY_IS_REVERTABLE) == "true");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use strict comparison operator ===.
Please also use single-quotes 'true' to keep the same style within the same class unless three is no specific need to use double-quotes.
I would also recommend avoiding the usage of redundant parenthesis.

As for the implementation itself, I think, it should be possible to use the following condition:

if ($input->getOption(self:: INPUT_KEY_IS_REVERTABLE)) {
...
}

Please check other examples of \Symfony\Component\Console\Input\InputInterface::getOption method usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -15,7 +15,7 @@ use Magento\Framework\Setup\ModuleDataSetupInterface;
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class %class% implements
%patchInterface%
%patchInterface%%patchRevertableInterface%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the %patchRevertableInterface% should be on a new line.
Here's an example of what I mean:

/**
 * Wrapper for GraphQl NonNull
 */
class NonNull extends \GraphQL\Type\Definition\NonNull implements
    WrappedTypeInterface,
    InputTypeInterface,
    OutputTypeInterface
{

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the %patchRevertableInterface% should be on a new line.

Not really, @dmytro-ch :)

%patchRevertableInterface% is the alias of , PatchRevertableInterface.

So, with the --revertable=true flag a result will be:

class TestPatch implements
    DataPatchInterface, PatchRevertableInterface
{

Without it:

class TestPatch implements
    DataPatchInterface
{

So, I would like to leave this part as it is.

Thank you!

Copy link
Contributor

@dmytro-ch dmytro-ch Aug 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that the PatchRevertableInterface should be added on a new line.
Please, check the example above, it shows how the interfaces should be arranged.

According to PSR-2 coding style guide:

Lists of implements MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one interface per line.

Copy link
Contributor Author

@atwixfirster atwixfirster Aug 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that the PatchRevertableInterface should be added on a new line.

done

Command 1:

bin/magento setup:db-declaration:generate-patch --revertable=true Magento_Cms TestPatch

Bash output 1:

Patch app/code/Magento/Cms/Setup/Patch/Data/TestPatch.php has been successfully generated.

Result 1:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Cms\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;

/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements
    DataPatchInterface,
    PatchRevertableInterface
{
    /**
     * @var ModuleDataSetupInterface $moduleDataSetup
     */
    private $moduleDataSetup;

    /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     */
    public function __construct(ModuleDataSetupInterface $moduleDataSetup)
    {
        $this->moduleDataSetup = $moduleDataSetup;
    }

    /**
     * Do Upgrade
     *
     * @return void
     */
    public function apply()
    {
    }

    /**
     * @inheritdoc
     */
    public function revert()
    {
    }

    /**
     * {@inheritdoc}
     */
    public function getAliases()
    {
        return [];
    }

    /**
     * {@inheritdoc}
     */
    public static function getDependencies()
    {
        return [

        ];
    }
}

Command 2:

bin/magento setup:db-declaration:generate-patch --revertable=false Magento_Cms TestPatch

Bash output 2:

Patch app/code/Magento/Cms/Setup/Patch/Data/TestPatch.php has been successfully generated.

Result 2:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Cms\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;

/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements DataPatchInterface
{
    /**
     * @var ModuleDataSetupInterface $moduleDataSetup
     */
    private $moduleDataSetup;

    /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     */
    public function __construct(ModuleDataSetupInterface $moduleDataSetup)
    {
        $this->moduleDataSetup = $moduleDataSetup;
    }

    /**
     * Do Upgrade
     *
     * @return void
     */
    public function apply()
    {
    }

    /**
     * {@inheritdoc}
     */
    public function getAliases()
    {
        return [];
    }

    /**
     * {@inheritdoc}
     */
    public static function getDependencies()
    {
        return [

        ];
    }
}

Command 3:

bin/magento setup:db-declaration:generate-patch --revertable=true --type=schema Magento_Cms TestPatch

Bash output 3:

Patch app/code/Magento/Cms/Setup/Patch/Schema/TestPatch.php has been successfully generated.

Result 3:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Cms\Setup\Patch\Schema;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;

/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements
    SchemaPatchInterface,
    PatchRevertableInterface
{
    /**
     * @var ModuleDataSetupInterface $moduleDataSetup
     */
    private $moduleDataSetup;

    /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     */
    public function __construct(ModuleDataSetupInterface $moduleDataSetup)
    {
        $this->moduleDataSetup = $moduleDataSetup;
    }

    /**
     * Do Upgrade
     *
     * @return void
     */
    public function apply()
    {
    }

    /**
     * @inheritdoc
     */
    public function revert()
    {
    }

    /**
     * {@inheritdoc}
     */
    public function getAliases()
    {
        return [];
    }

    /**
     * {@inheritdoc}
     */
    public static function getDependencies()
    {
        return [

        ];
    }
}

Command 4:

bin/magento setup:db-declaration:generate-patch --revertable=false --type=schema Magento_Cms TestPatch

Bash output 4:

Patch app/code/Magento/Cms/Setup/Patch/Schema/TestPatch.php has been successfully generated.

Result 4:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Cms\Setup\Patch\Schema;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;

/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class TestPatch implements SchemaPatchInterface
{
    /**
     * @var ModuleDataSetupInterface $moduleDataSetup
     */
    private $moduleDataSetup;

    /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     */
    public function __construct(ModuleDataSetupInterface $moduleDataSetup)
    {
        $this->moduleDataSetup = $moduleDataSetup;
    }

    /**
     * Do Upgrade
     *
     * @return void
     */
    public function apply()
    {
    }

    /**
     * {@inheritdoc}
     */
    public function getAliases()
    {
        return [];
    }

    /**
     * {@inheritdoc}
     */
    public static function getDependencies()
    {
        return [

        ];
    }
}

@atwixfirster
Copy link
Contributor Author

Could you please check the minor CR notices?

fixed

@dmytro-ch
Copy link
Contributor

@atwixfirster, thank you for the fixes!
Could you please squash all commits into a single one in order to clean up history?

@atwixfirster atwixfirster force-pushed the 23847-generate-patch-add-revert-method branch from b84e3b7 to 2a62f1c Compare August 13, 2019 20:49
@m2-assistant
Copy link

m2-assistant bot commented Aug 13, 2019

Hi @atwixfirster, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@atwixfirster atwixfirster reopened this Aug 13, 2019
@m2-assistant
Copy link

m2-assistant bot commented Aug 13, 2019

Hi @atwixfirster. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

In case you'd like to rerun tests use the following comments:

  • @magento run all tests - run all tests
  • @magento run { check name } - run a single test job (check name example: Static Tests build)

For more details, please, review the Magento Contributor Guide documentation.

@ghost ghost unassigned dmytro-ch Aug 13, 2019
@atwixfirster atwixfirster self-assigned this Aug 13, 2019
@ghost ghost unassigned atwixfirster Aug 13, 2019
@ghost
Copy link

ghost commented Aug 13, 2019

@atwixfirster unfortunately, only members of the maintainers team are allowed to assign developers to the pull request

@atwixfirster
Copy link
Contributor Author

Could you please squash all commits into a single one in order to clean up history?

done

Thank you, @dmytro-ch 👍

@atwixfirster atwixfirster self-assigned this Aug 13, 2019
@ghost ghost unassigned atwixfirster Aug 13, 2019
@ghost
Copy link

ghost commented Aug 13, 2019

@atwixfirster unfortunately, only members of the maintainers team are allowed to assign developers to the pull request

@dmytro-ch dmytro-ch self-assigned this Aug 14, 2019
@dmytro-ch dmytro-ch added Award: special achievement Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Aug 14, 2019
@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, thank you for the review.
ENGCOM-5619 has been created to process this Pull Request

@engcom-Alfa
Copy link
Contributor

Hi @atwixfirster

During testing we faced the issue

Problem: revert() method generate to patch even if option --revertable=false

Steps to reproduce:
Example with Magento_Cms

bin/magento setup:db-declaration:generate-patch --revertable=false Magento_Cms TestPatch

Actual Result:

class TestPatch implements
DataPatchInterface,
PatchRevertableInterface
{
/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;

/**
 * @param ModuleDataSetupInterface $moduleDataSetup
 */
public function __construct(ModuleDataSetupInterface $moduleDataSetup)
{
    $this->moduleDataSetup = $moduleDataSetup;
}

/**
 * Do Upgrade
 *
 * @return void
 */
public function apply()
{
}

/**
 * @inheritdoc
 */
public function revert()
{
}

/**
 * {@inheritdoc}
 */
public function getAliases()
{
    return [];
}

/**
 * {@inheritdoc}
 */
public static function getDependencies()
{
    return [

    ];
}

@atwixfirster Could you take a look, please?

Thanks!

@atwixfirster
Copy link
Contributor Author

@engcom-Alfa

Problem: revert() method generate to patch even if option --revertable=false

Let me please explain.

If --revertable is present in the bin/magento setup:db-declaration:generate-patch command then revert() method will be added.

So, the key here is --revertable. It may have any value. For example,

--revertable=hello.

Please let me know you you have any additional questions here.

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Before:
before

After:
after

@engcom-Foxtrot engcom-Foxtrot self-assigned this Aug 20, 2019
magento-engcom-team pushed a commit that referenced this pull request Aug 21, 2019
@magento-engcom-team magento-engcom-team merged commit 84527e7 into magento:2.3-develop Aug 21, 2019
@m2-assistant
Copy link

m2-assistant bot commented Aug 21, 2019

Hi @atwixfirster, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.4 milestone Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests Award: special achievement Component: Developer Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Progress: accept Release Line: 2.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants