Skip to content

Declarative schema: Constraint with type="index" breaks setup process on subsequent upgrades #21304

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
k4emic opened this issue Feb 18, 2019 · 11 comments
Labels
Component: Setup Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. Progress: ready for dev Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@k4emic
Copy link

k4emic commented Feb 18, 2019

Preconditions (*)

  1. Magento 2.3

Steps to reproduce (*)

  1. Use <constraint xsi:type="index"... in db_schema.xml
  2. Run setup:upgrade twice

Sample db_schema.xml file

<?xml version="1.0"?>

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">

    <table name="inventory_source_item">
        <column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP"
                comment="Update Time"/>
        <constraint xsi:type="index" referenceId="INVENTORY_SOURCE_ITEM_UPDATED_AT">
            <column name="updated_at"/>
        </constraint>
    </table>
</schema>

Expected result (*)

  1. Setup process completes with no changes detected

Actual result (*)

  1. Command fails with message PDOException: SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'INVENTORY_SOURCE_ITEM_UPDATED_AT'
@magento-engcom-team
Copy link
Contributor

Hi @k4emic. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

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

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

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

@k4emic do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Feb 18, 2019
@k4emic k4emic changed the title Declarative schema: Constraint with type="index" breaks setup process Declarative schema: Constraint with type="index" breaks setup process on subsequent upgrades Feb 18, 2019
@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Feb 18, 2019

Hi @engcom-backlog-nazar. 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.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.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. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • Next steps are available in case you are a member of Community Maintainers.

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

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

@ghost ghost self-assigned this Feb 18, 2019
@k4emic
Copy link
Author

k4emic commented Feb 18, 2019

Some speculation on why this happens:

The \Magento\Framework\Setup\Declaration\Schema\Diff\TableDiff::calculateDiff treats indexes and constraints very differently when the diff is calculated. The example column will be added correctly at first, but subsequent runs of setup:upgrade will identify it (correctly) as an index instead of a constraint, which leads Magento to believe the index should be created.

Changing the XML file to use <index ..> (and dropping the existing index) solves this issue.
I think this is mainly a documentation problem, since defining an index through the use of <constraint> is not really valid for two reasons:

  1. It creates two (very similar) ways of doing the same thing
  2. The less intuitive way doesn't work

I would propose dropping/deprecating support for <constraint type="index" in the XSD, while we are still in the early stages of declarative schema.
While this is in breach with the semantic versioning concept, the feature is already broken and likely misplaced.

@ghost ghost added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Feb 18, 2019
@k4emic
Copy link
Author

k4emic commented Feb 18, 2019

Doing a little more research, it seems like the <constraint> element is too loosely defined in what it should allow.

Something like <constraint xsi:type="table" name="my_table" /> and <constraint /> is totally valid according to the XSD.

<xs:complexType name="table">
        <xs:annotation>
            <xs:documentation>
                Table definition. Here we can found column, constraints and indexes
            </xs:documentation>
        </xs:annotation>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="column" type="abstractColumnType"/>
            <xs:element name="constraint" />
            <xs:element name="index" type="index" />
        </xs:choice>

<constraint> is the only type with no type attribute of the three.
Something like the following could help developers choosing the right element type for their needs:

# vendor/magento/framework/Setup/Declaration/Schema/etc/constraints/constraint.xsd
<xs:complexType name="constraintType">
        <xs:attribute name="type">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="foreign" />
                    <xs:enumeration value="unique" />
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>

@ghost ghost added Component: Setup Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Feb 19, 2019
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Feb 19, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-backlog-nazar
Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-98318 were created

Issue Available: @engcom-backlog-nazar, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@ghost ghost removed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Oct 20, 2020
@sdzhepa sdzhepa added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Nov 6, 2020
@magento-engcom-team magento-engcom-team added Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”. labels Nov 30, 2020
@stale
Copy link

stale bot commented Feb 15, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

@stale stale bot added the stale issue label Feb 15, 2021
@kanevbg
Copy link

kanevbg commented Feb 15, 2021

up

@stale stale bot removed the stale issue label Feb 15, 2021
@stale
Copy link

stale bot commented May 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

@stale stale bot added the stale issue label May 2, 2021
@k4emic
Copy link
Author

k4emic commented May 3, 2021

Bump

@stale stale bot removed the stale issue label May 3, 2021
@PascalBrouwers
Copy link
Contributor

You should not make issues stale that are internal tickets!

@kanevbg
Copy link

kanevbg commented Jul 24, 2023

Come on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Setup Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. Progress: ready for dev Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Severity: S4 Affects aesthetics, professional look and feel, “quality” or “usability”. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

No branches or pull requests

5 participants