Skip to content

Commit 8bd8b4d

Browse files
committed
MAGETWO-95595: Index names are ignored by declarative schema
1 parent 43f9417 commit 8bd8b4d

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/foreign_key_interpreter_result.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'constraint' => [
3434
'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF' => [
3535
'type' => 'foreign',
36-
'name' => 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF',
36+
'referenceId' => 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF',
3737
'column' => 'tinyint',
3838
'table' => 'test_table',
3939
'referenceTable' => 'reference_table',

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/valid_xml_revision_1.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
'tinyint_ref' => 'tinyint_ref',
9494
],
9595
'type' => 'primary',
96-
'name' => 'tinyint_primary',
96+
'referenceId' => 'tinyint_primary',
9797
],
9898
],
9999
'name' => 'reference_table',
@@ -125,7 +125,7 @@
125125
'int_auto_increment_with_nullable' => 'int_auto_increment_with_nullable',
126126
],
127127
'type' => 'unique',
128-
'name' => 'AUTO_INCREMENT_TEST_INT_AUTO_INCREMENT_WITH_NULLABLE',
128+
'referenceId' => 'AUTO_INCREMENT_TEST_INT_AUTO_INCREMENT_WITH_NULLABLE',
129129
],
130130
],
131131
'name' => 'auto_increment_test',
@@ -231,11 +231,11 @@
231231
'bigint' => 'bigint',
232232
],
233233
'type' => 'unique',
234-
'name' => 'TEST_TABLE_SMALLINT_BIGINT',
234+
'referenceId' => 'TEST_TABLE_SMALLINT_BIGINT',
235235
],
236236
'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF' => [
237237
'type' => 'foreign',
238-
'name' => 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF',
238+
'referenceId' => 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF',
239239
'column' => 'tinyint',
240240
'table' => 'test_table',
241241
'referenceTable' => 'reference_table',
@@ -249,7 +249,7 @@
249249
'tinyint' => 'tinyint',
250250
'bigint' => 'bigint',
251251
],
252-
'name' => 'TEST_TABLE_TINYINT_BIGINT',
252+
'referenceId' => 'TEST_TABLE_TINYINT_BIGINT',
253253
'indexType' => 'btree',
254254
],
255255
],

dev/tests/setup-integration/testsuite/Magento/Setup/DeclarativeInstallerTest.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,26 @@ public function testInstallation()
7979

8080
//Second time installation should not find anything as we do not change anything
8181
self::assertNull($diff->getAll());
82+
$this->compareStructures();
83+
}
84+
85+
/**
86+
* Compare structure of DB and declared structure.
87+
*/
88+
private function compareStructures()
89+
{
8290
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
83-
self::assertEquals($this->getTrimmedData(), $shardData);
91+
foreach ($this->getTrimmedData() as $tableName => $sql) {
92+
$this->assertArrayHasKey($tableName, $shardData);
93+
/**
94+
* MySQL 8.0 and above does not provide information about the ON DELETE instruction
95+
* if ON DELETE NO ACTION
96+
*/
97+
if (preg_match('#ON DELETE\s+NO ACTION#i', $shardData[$tableName] === 1)) {
98+
preg_replace('#ON DELETE\s+NO ACTION#i', '', $sql);
99+
self::assertEquals($sql, $shardData[$tableName]);
100+
}
101+
}
84102
}
85103

86104
/**
@@ -110,8 +128,7 @@ public function testInstallationWithColumnsModification()
110128
$this->schemaConfig->getDbConfig()
111129
);
112130
self::assertNull($diff->getAll());
113-
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
114-
self::assertEquals($this->getTrimmedData(), $shardData);
131+
$this->compareStructures();
115132
}
116133

117134
/**
@@ -156,8 +173,7 @@ public function testInstallationWithColumnsRemoval()
156173
$this->schemaConfig->getDbConfig()
157174
);
158175
self::assertNull($diff->getAll());
159-
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
160-
self::assertEquals($this->getTrimmedData(), $shardData);
176+
$this->compareStructures();
161177
}
162178

163179
/**

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/Definition/Constraints/ForeignKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function fromDefinition(array $data)
9595
'column' => $match[2],
9696
'referenceTable' => $match[5],
9797
'referenceColumn' => $match[6],
98-
'onDelete' => isset($match[7]) ? $match[8] : ''
98+
'onDelete' => isset($match[7]) ? $match[8] : 'NO ACTION'
9999
];
100100
}
101101
}

0 commit comments

Comments
 (0)