I need to update the installation part of one extension from old to declarative schema.
Old system looks like:
Setup version – 1.0
Adds table vendor_entity
- entity_id
- name
- desciption
- status
Setup version – 2.0
Adds new table vendor_entity_locale
- entity_locale_id
- entity_id
- name
- desciption
- store_id
with SQL method for moving data from vendor_entity
to vendor_entity_locale
The fields name
and description
removed from vendor_entity
and table looks like:
- entity_id
- status
As you can see the database schema was transforming for hold the store-related values in new specific table.
My Question – how can I achieve the same using the declarative schema?
The problem related to this rule statement: “Magento prioritizes the declarative schema and executes the declarative install schemas before the data and schema patches.”
So if I leave the final state (bin/magento setup:upgrade --convert-old-scripts=1
) in db_schema.xml:
<table name="vendor_entity" resource="default" engine="innodb">
<column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true"/>
<column xsi:type="text" name="name" nullable="false" disabled="true"/>
<column xsi:type="text" name="description" nullable="false" disabled="true"/>
<column xsi:type="smallint" name="status" padding="5" unsigned="true" nullable="false" identity="false" default="0" />
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="entity_id"/>
</constraint>
</table>
the clients who updated the extension from 1.0 version will lose name and description because database structure will be modified firstly (columns name and description will be deleted by schema) and than data won’t be found (for transferring to new table) in any data path script which will be executed after.
Here is the dry-run-installation.log:
ALTER TABLE `vendor_entity` DROP COLUMN `name`, DROP COLUMN `description`
CREATE TABLE `vendor_entity_locale` (
...
)