magento/magento2

setup:upgrade action: adding trigger (mview.xml) to not exist table

Closed this issue · 10 comments

Preconditions (*)

  1. Magento 2.4.3 - upgrade from 2.2.4 to 2.4.3
  2. php 7.4
  3. "amasty/sorting" - upgrade from "^2.6" to "^2.9" version

Steps to reproduce (*)

  1. run composer update
  2. run bin/magento setup:upgrade

Expected result (*)

  1. upgraded Magento and Amaty module to newest version

Actual result (*)

The directory '/app/generated/metadata/' doesn't exist - skipping cleanup
Updating modules:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'amasty_sorting_reviews_link' doesn't exist, query was: CREATE TRIGGER trg_amasty_sorting_reviews_link_after_insert AFTER INSERT ON amasty_sorting_reviews_link FOR EACH ROW
BEGIN
INSERT IGNORE INTO catalogsearch_fulltext_cl (entity_id) VALUES (NEW.product_id);
END

Description (*)

In vendor/amasty/sorting/etc/mview.xml

    <subscriptions>
        <table name="amasty_sorting_reviews_link" entity_column="product_id" />
    </subscriptions>
</view>

Magento wanted to create trigger trg_amasty_sorting_reviews_link_after_insert but the table amasty_sorting_reviews_link wasn't created yet, as you can see in the error .

Table amasty_sorting_reviews_link is created in the same Amasty module vendor/amasty/sorting/etc/db_schema.xml.

The problem is in the setup/src/Magento/Setup/Console/Command/UpgradeCommand.php file in execute function.

$installer->removeUnusedTriggers();
$installer->installSchema($request);

First, magento removes all triggers and creates new ones in removeUnusedTriggers(), but the amasty_sorting_reviews_link table is created in the following installSchema() function.

Therefore we get an error there as I wrote above.
It might help to change the call position of these functions.


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Hi @chochold. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


⚠️ According to the Magento Contribution requirements, all issues 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 issues happens in the queue order. If you want to speed up the delivery of your contribution, 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

Hi @engcom-November. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

Hi @chochold ,
Amasty is a 3rd party extension and code of this extension is not part of https://github.com/magento/magento2 git repository. We are closing this issue as community is not able to provide fix for it in this repository. All questions, issue reports and fix for them should be addressed to the corresponding extension owners(support) on the Magento Market place page
Thank you.

Hi @engcom-November,

it is no 3rd party module problem. The main problem is in the Magento core setup:upgrade code. Amasty we used as an example.

The problem is in this file
setup/src/Magento/Setup/Console/Command/UpgradeCommand.php

$installer->removeUnusedTriggers();
$installer->installSchema($request);

Because, if you want to create a on xxxxx table

<view id="catalogsearch_fulltext"
 class="\Magento\CatalogSearch\Model\Indexer\Mview\Action"
 group="indexer">
         <subscriptions>
             <table name="xxxxx"
 entity_column="product_id" />
         </subscriptions>
</view>

And xxxxx table is created in the same module where we have mview.xml, setup:upgrade generates error because the table does not exist when triggers are generated.
Table will generate in the next command

$installer->installSchema($request);

We have faced the same issue. We created a new module, created db_schema.xml file which describes new table, also we created mview.xml file, but when we deploy this module to new environment (which don't has this table) we are getting the error.

2022-12-02-13-24-03

2022-12-02-13-29-59

not limited to 3rd party modules

image

module disabled by config.xml then re-enabled
cannot use CLI command to enable module as per CI/CD

@hostep @mamsincl do you guys have any idea to handle this problem, this is bad situation has happened to us/

@engcom-November kindly reopen this issue, this is not 3rd party module, while Magento\Framework\Mview\Config\Reader was running to validate before the table was created by schema. In this case mview should ignore or run after the table creation.

Edit

Ignore this, this seems be fixed on #33092

@tuyennn, you can probably workaround the problem by temporarily setting indexers to 'realtime' mode, deploy your module, and reverting indexers back to 'scheduled' mode.

This issue also reminds me of #33092 which got included in Magento 2.4.7, are you on that version or a lower one?

@hostep good to know it fixed, well a patch is necessary while I'm on 2.4.5-p9