Skip to content
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

Add support for char element to dto factory #22442

Conversation

wardcapp
Copy link
Contributor

@wardcapp wardcapp commented Apr 21, 2019

To avoid the notice "Types char is not declared" (which breaks setup:upgrade) when using the very type anywhere in the MySQL database, mapping for this specific type is added to the DI as well.

Description

Adds the CHAR MySQL column type to the schema type declaration factory (di.xml). Which becomes required as soon as CHAR type has been used anywhere within the connected database - applies to non-Magento tables as well, since they are validated / scanned too upon executing setup:upgrade.

Fixed Issues

  1. Was not able to find a report within the official GitHub repo on this, but still related is following community thread:
    https://community.magento.com/t5/Magento-2-x-Version-Upgrades/Upgrade-Issue-2-2-7-to-2-3-0-Types-char-is-not-declared/td-p/114939

Manual testing scenarios

db_schema.xml
<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="test_table" resource="default" engine="innodb" comment="Data">
        <column xsi:type="bigint" name="id" padding="20" unsigned="true" nullable="false" identity="true" comment="ID"/>
        <column xsi:type="char" name="dataChar" length="5" nullable="false" comment="data"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="id"/>
        </constraint>
    </table>
</schema>
Structure of created table
mysql> show create table test_table\G
*************************** 1. row ***************************
       Table: test_table
Create Table: CREATE TABLE `test_table` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `dataChar` char(5) NOT NULL COMMENT 'data',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Data'
1 row in set (0.00 sec)

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 on Travis CI are green)

To avoid the notice "Types char is not declared" (which breaks setup:upgrade)
when using the very type anywhere in the MySQL database, mapping for this specific type
is added to the DI as well.
@m2-assistant
Copy link

m2-assistant bot commented Apr 21, 2019

Hi @wardcapp. 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-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

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

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Apr 21, 2019

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

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

I believe this is slightly related to #1392. Why do we need to add CHAR mapping if it's not used in Magento?

@wardcapp
Copy link
Contributor Author

wardcapp commented Apr 22, 2019

This PR does slightly relate to #1392, which indeed explains why most of the users aren't applying the CHAR type throughout their MySQL DB over Magento setup scripts. Reasons to why CHAR should still be added to the DTO mapping / why the PR was created:

Could be wrong still / assumptions made could be incorrect, so please feel free to provide feedback.

@orlangur
Copy link
Contributor

Thanks @wardcapp!

@skovalenk @rganin @akaplya is there any reason to disallow CHAR column type?

@Seb33300
Copy link

Seb33300 commented May 1, 2019

I am encountering the issue Types char is not declared when installing Magento on a shared database with other applications. Some of them are using the char field type and this result in this error...

This pull request could solve my issue.
But I don't really understand why db tables not related to Magento can break Magento install...

@@ -1435,6 +1435,7 @@
<item name="mediumtext" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\MediumText</item>
<item name="text" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Text</item>
<item name="varchar" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\StringBinary</item>
<item name="char" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\StringBinary</item>
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not enough to add char in di.xml, you need to fix db_scrma definition too

Copy link
Contributor Author

@wardcapp wardcapp Jul 21, 2019

Choose a reason for hiding this comment

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

First of all, thank you for the follow-up! Not quite sure if I am understanding this correctly - did you mean the DB schema type declarations (within the very same di.xml)? If so, char has already been defined there as well within the current 2.3-develop branch (see app/etc/di.xml:1471).

Apart from that, it is possible to add support for the char type to Magento 2 setup scripts. Which would require adding of a char schema setup declaration (similar to lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/schema.xsd:22) indeed, but does not relate to the intent of this pull request (and could be set up over a separate PR or feature request). But I might still be overlooking another required type of definition?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sidolov please respond :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @wardcapp This is a good idea extending compatible types, but unfortunately, this is not as easy as change one XSD. Here is an example of adding a new data type to a declarative schema. https://github.com/magento/magento2/pull/25479/files
In your case, it even could be more complicated because the CHAR type supports more options that JSON. Also, you can take a look at VARCHAR implementation as an example.

@ghost ghost assigned sidolov Jul 15, 2019
@sidolov sidolov changed the base branch from 2.3-develop to 2.4-develop December 5, 2019 17:21
@lenaorobei lenaorobei self-assigned this Feb 6, 2020
@engcom-Golf engcom-Golf self-assigned this Feb 7, 2020
@engcom-Golf
Copy link
Contributor

i will provide support for db_schema

@lenaorobei
Copy link
Contributor

@wardcapp could you please sign CLA so our team will be able to finish this PR?

@wardcapp
Copy link
Contributor Author

wardcapp commented Feb 7, 2020

Hi @lenaorobei, CLA has been signed and related check should pass now.

@engcom-Golf engcom-Golf force-pushed the magento-2.3/add-char-to-dto-elementfactory branch 3 times, most recently from 7c5471c to 8741cd0 Compare February 11, 2020 12:54
@Nazar65 Nazar65 requested a review from akaplya February 11, 2020 17:39
Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

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

@Nazar65 looks good to me except the small typo 👍

Please fix it and squash your changes into a single commit.

<xs:extension base="abstractColumnType">
<xs:annotation>
<xs:documentation>
Here plain text can be persisted without trailing spaces. Length of this field cant be more than 255 characters
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "cannot" or "can't"

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, thank you 👍

@engcom-Golf engcom-Golf force-pushed the magento-2.3/add-char-to-dto-elementfactory branch from c23a0a5 to 58dde94 Compare February 17, 2020 09:25
@engcom-Golf
Copy link
Contributor

engcom-Golf commented Feb 17, 2020

@orlangur thank you for your review, done ✔️

@lenaorobei lenaorobei added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Covered All changes in Pull Request is covered by auto-tests labels Feb 26, 2020
@engcom-Alfa engcom-Alfa self-assigned this Feb 27, 2020
@engcom-Golf engcom-Golf added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Feb 27, 2020
@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

@engcom-Golf
Copy link
Contributor

@magento run all tests

1 similar comment
@engcom-Golf
Copy link
Contributor

@magento run all tests

@magento-engcom-team
Copy link
Contributor

Hi @lenaorobei, thank you for the review.
ENGCOM-7016 has been created to process this Pull Request

@magento-engcom-team magento-engcom-team merged commit b82791d into magento:2.4-develop Mar 12, 2020
@m2-assistant
Copy link

m2-assistant bot commented Mar 12, 2020

Hi @wardcapp, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.