Changing column type from plugin


#1

Hi everyone,

I’m currently attempting to implement a plugin that can help our company by syncing the product catalog with our PIM system. (This will be used in multiple shops)
The problem I’m running into is that the meta_keywords column in the sylius_product_translation table is a varchar(255) type (string in the orm mapping of the Product bundle).
However I need to store more keywords, so modifying the column type to longtext would be nice.
I tried to do that by overriding the attribute in a new mapping in my plugin, but changing the type there is not supported by doctrine (https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#overrides).
In your opinion what would be the best way to go about this problem?

  1. Make a migration and include it and mention in the README that it needs to be copied to the Migrations folder (does update the db schema, but not the mapping)
  2. Change the mapping in the Product bundle and make a Pull Request so that we can all store more meta keywords in product translations
  3. Your suggestion…

Thanks in advance for your time and information.


#2

If you are using ORM annotations as Doctrine default mapping you can override ProductTranslation entity and specify some data to the meta_keywords field.

Example:

class ProductTranslation extends BaseProductTranslation
{

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $meta_keywords;

}

#3

The doctrine documentation states: "The column type CANNOT be changed. If the column type is not equal you get a MappingException"

So I don’t think it is possible to do that.