Description
Preconditions and environment
- Magento 2.4.6-p3
- MariaDB:10.6
Command setup:db:status
is useful for deployment tools to determine whether setup:upgrade
should be run.
Steps to reproduce
Create a module with a new table with JSON column:
db_schema.xml
:
<table name="example_table" engine="innodb" resource="default">
<column xsi:type="int" name="entity_id" identity="true" nullable="false" unsigned="true"/>
<column xsi:type="json" name="content" nullable="false"/>
<constraint referenceId="PRIMARY" xsi:type="primary">
<column name="feed_missing_id"/>
</constraint>
</table>
Run
bin/magento setup:db-declaration:generate-whitelist --module-name Sample_Module
bin/magento setup:upgrade
bin/magento setup:db:status
Expected result
Reported schema is up to date
Actual result
Declarative Schema is not up to date
Run 'setup:upgrade' to update your DB schema and data.
Additional information
You can debug results with breakpoint or var_dump
in
\Magento\Framework\Setup\Declaration\Schema\UpToDateDeclarativeSchema::isUpToDate
Search for old
and new
phrases, e.g. bin/magento setup:db:status | grep old -n10
. Following results indicate that the column type is resolved from the database as longtext
but the new value is json
. JSON is stored as longtext
and the diff will always report that columns differ.
Perhaps this is only an issue in MariaDB because JSON is an alias for LONGTEXT and should work fine on MySQL.
Sample output:
bin/magento setup:db:status | grep old -n10
12467: ["old":"Magento\Framework\Setup\Declaration\Schema\ElementHistory":private]=>
12468- object(Magento\Framework\Setup\Declaration\Schema\Dto\Columns\Text)#14665 (6) {
12469- ["type":"Magento\Framework\Setup\Declaration\Schema\Dto\GenericElement":private]=>
12470- string(8) "longtext"
12471- ["name":"Magento\Framework\Setup\Declaration\Schema\Dto\GenericElement":private]=>
12472- string(7) "content"
12473- ["table":"Magento\Framework\Setup\Declaration\Schema\Dto\Column":private]=>
12474- object(Magento\Framework\Setup\Declaration\Schema\Dto\Table)#14661 (13) {
12475- ["type":"Magento\Framework\Setup\Declaration\Schema\Dto\GenericElement":private]=>
12476- string(5) "table"
12477- ["name":"Magento\Framework\Setup\Declaration\Schema\Dto\GenericElement":private]=>
bin/magento setup:db:status | grep new -n10
1-array(1) {
2- [0]=>
3- object(Magento\Framework\Setup\Declaration\Schema\ElementHistory)#15359 (2) {
4: ["new":"Magento\Framework\Setup\Declaration\Schema\ElementHistory":private]=>
5- object(Magento\Framework\Setup\Declaration\Schema\Dto\Columns\Blob)#8029 (6) {
6- ["type":"Magento\Framework\Setup\Declaration\Schema\Dto\GenericElement":private]=>
7- string(4) "json"
8- ["name":"Magento\Framework\Setup\Declaration\Schema\Dto\GenericElement":private]=>
9- string(7) "content"
10- ["table":"Magento\Framework\Setup\Declaration\Schema\Dto\Column":private]=>
11- object(Magento\Framework\Setup\Declaration\Schema\Dto\Table)#8025 (13) {
12- ["type":"Magento\Framework\Setup\Declaration\Schema\Dto\GenericElement":private]=>
13- string(5) "table"
14- ["name":"Magento\Framework\Setup\Declaration\Schema\Dto\GenericElement":private]=>
Workaround: use longtext
instead of json
.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.