magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.46k stars 9.28k forks source link

Can't set collation with declarative schema #38999

Open Eddcapone opened 1 month ago

Eddcapone commented 1 month ago

Summary

There is currently no way to set the collation of a column by using declarative schema.

Examples

Try to set the collation of the column detail from the review_detail table to utf8mb4_unicode_ci via declarative schema.

It will not work.

You are then forced to use a Setup/InstallSchema.php script to change the column like so:

<?php
namespace Company\Review\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

class InstallSchema implements InstallSchemaInterface
{
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

        $connection = $setup->getConnection();
        $tableName = $setup->getTable('review_detail');

        // Modify column collation and charset
        $connection->query("ALTER TABLE `{$tableName}` MODIFY COLUMN `title` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
        $connection->query("ALTER TABLE `{$tableName}` MODIFY COLUMN `detail` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");

        $setup->endSetup();
    }

}

Then execute php bin/magento setup:upgrade to make it install that schema.

Problem: The next time you call php bin/magento setup:upgrade, it will override it again because it will find the instruction in the declarative schema @ vendor/magento/module-review/etc/db_schema.xml, to override it again.

Proposed solution

The solution would be, to be able to set the collation in a declarative schema file, so we could override it from a custom extension.

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 month ago

Hi @Eddcapone. Thank you for your report. To speed up processing of this issue, 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:

m2-assistant[bot] commented 3 weeks ago

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: :point_down:

engcom-November commented 3 weeks ago

Hello @Eddcapone,

Thank you for the report and collaboration!

As there is no way to set collation using declarative schema, this can be considered as feature request.