Skip to content

ISSUE-30304 - Mark index removal as non-destructive so indexes can be removed without being present in whitelist json #30939

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

Open
wants to merge 3 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

zaximus84
Copy link

Description (*)

Previous state: When an index is present in the database but not in declarative schema, it's funneled into \Magento\Framework\Setup\Declaration\Schema\Operations\DropElement for evaluation. DropElement is considered destructive, so it fails \Magento\Framework\Setup\Declaration\Schema\Diff\Diff::canBeRegistered unless the index is present in a db_schema_whitelist.json file. An index must be present in the whitelist json to be automatically removed during declarative schema processing.

After this PR: The index removal is funneled into a new DropIndex class instead. This is considered non-destructive, so it passes \Magento\Framework\Setup\Declaration\Schema\Diff\Diff::canBeRegistered. Indexes present in the database but not declarative schema are automatically removed, regardless of what's in db_schema_whitelist.json.

Fixed Issues (if relevant)

  1. Fixes Indexes are not removed unless added to whitelist #30304

Manual testing scenarios (*)

  1. Directly in MySQL, add an index to a column in a core table.
  2. Run bin/magento setup:upgrade.
  3. Confirm that the index was automatically removed because it doesn't exist in any declarative schema.

Questions or comments

I was uncertain if this needs tests written as there seem to be other schema operation classes that aren't tested. If it does need tests, I will need advice on what test class should be updated, and what the test should check for. I understand the concept of unit tests, but haven't written any before.

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)

… operations processing. Mark it as non-destructive so it's not dependent on whitelist json.
@m2-assistant
Copy link

m2-assistant bot commented Nov 16, 2020

Hi @zaximus84. 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.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

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

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Nov 16, 2020
@sidolov sidolov self-assigned this Nov 16, 2020
Copy link
Contributor

@sidolov sidolov left a comment

Choose a reason for hiding this comment

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

@zaximus84 changes look good to me! Could you please cover the solution with an automated test? Thanks!

/**
* Operation name.
*/
const OPERATION_NAME = 'drop_index';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, make const private

@zaximus84
Copy link
Author

@sidolov
I have a basic familiarity with unit tests, but I've never actually written one. Can you give any advice? A suggestion on what the test needs to test for and what class it should be in would help me get started. Thanks.

@sidolov
Copy link
Contributor

sidolov commented Nov 17, 2020

@zaximus84 you may check our testing documentation: https://devdocs.magento.com/guides/v2.4/test/testing.html
In this case, it would be good to cover changes with an integration test or at least with unit.

@zaximus84
Copy link
Author

@sidolov
It turns out there was already a unit test for the index management, and it began failing after my changes due to the new operation. I have updated it to reference the new operation name. I believe this is a sufficient test, but let me know if additional criteria need to be covered.

Regarding the constant, it can't be private as it's referenced in DiffManager.php, but I explicitly marked it with public visibility.

Copy link
Contributor

@sidolov sidolov left a comment

Choose a reason for hiding this comment

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

@zaximus84 got it! Thanks for your contribution! We will proceed with the delivery of PR as soon as possible!

@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-8480 has been created to process this Pull Request
✳️ @sidolov, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@sidolov sidolov added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Nov 18, 2020
@sidolov
Copy link
Contributor

sidolov commented Nov 18, 2020

@magento run all tests

@engcom-Delta
Copy link
Contributor

✔️ QA passed
Was checked cases:
Case 1:

  • Directly in MySQL, add an index to a column in a core table.
  • Run bin/magento setup:upgrade.

Result:
✔️ The index was automatically removed because it doesn't exist in any declarative schema.

Case 2:

  • Add an index to a column in a core table using declarative schema( e.g. captcha_log table)
<index referenceId="CAPTCHA_LOG_VALUE" indexType="btree">
            <column name="value"/>
        </index>
  • Run bin/magento setup:upgrade.
  • Index was added into table
    image
  • Run bin/magento setup:upgrade again

Result:
✔️ The index is not removed because it exists in declarative schema.
image

@engcom-Delta
Copy link
Contributor

Note: Functional Tests B2B and Integration Tests are failed

@engcom-Foxtrot
Copy link
Contributor

Hello, @zaximus84. Thanks for your contribution. Can you please fix the failed integartion test?

@zaximus84
Copy link
Author

I've spent quite a bit of time investigating the failing integration test, and I think I've hit a dead end determining how to resolve the issue. MODULE8_INSTALL_INDEX_TEMP is the first cause of failure, so I've been focusing on it. It's being added by the install script and removed by the upgrade script, so the final expected state in the schema xml for comparison is disabled="true". However, after the change in this PR, the automatic schema handling removes the index before the upgrade script for \Magento\Developer\Console\Command\SetupUpgradeTest. As a result, the dropIndex call in the upgrade script returns early and never registers the index removal, leaving the index in the final XML without being marked as disabled.

I think someone with more expertise in integration tests will need to pick this up.

@engcom-Foxtrot
Copy link
Contributor

I've spent quite a bit of time investigating the failing integration test, and I think I've hit a dead end determining how to resolve the issue. MODULE8_INSTALL_INDEX_TEMP is the first cause of failure, so I've been focusing on it. It's being added by the install script and removed by the upgrade script, so the final expected state in the schema xml for comparison is disabled="true". However, after the change in this PR, the automatic schema handling removes the index before the upgrade script for \Magento\Developer\Console\Command\SetupUpgradeTest. As a result, the dropIndex call in the upgrade script returns early and never registers the index removal, leaving the index in the final XML without being marked as disabled.

I think someone with more expertise in integration tests will need to pick this up.

@zaximus84 thanks for investigating. I think I could try to resolve this issue.

@gabrieldagama
Copy link
Contributor

@magento run all tests

@gabrieldagama
Copy link
Contributor

gabrieldagama commented Nov 25, 2020

Hi @zaximus84, thanks for contributing!

I believe we need to have some internal discussion on this issue, on my local tests the indexes were removed at the upgrade step of the integration tests, I believe this may be changing the behavior more than we would like.

I will put this on hold and start a discussion internally, will add comments with updates as soon as we decide how to proceed with it.

Thanks.

@ihor-sviziev
Copy link
Contributor

@gabrieldagama, are there any updates after discussions?

@engcom-Hotel
Copy link
Contributor

Hello,

We have tried to reproduce the issue in the latest development branch i.e. 2.4-develop and it seems the issue is still relevant.

We have followed the below steps in order to reproduce the issue:

  1. Added an index in table catalog_log in the updated_at column:

image

2. Ran `bin/magento setup:upgrade` command.
  1. Index has not been removed, it is there only.

Let me connect with its PO for further clarification on this.

Thanks

@engcom-Lima engcom-Lima added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Dec 7, 2022
@engcom-Charlie
Copy link
Contributor

As bot moved it from On Hold to Ready for Testing, moving it back.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Setup Partner: Blue Acorn iCi partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: on hold Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Development

Successfully merging this pull request may close these issues.

Indexes are not removed unless added to whitelist
10 participants