17
17
use Magento \Framework \Setup \Declaration \Schema \Declaration \TableElement \ElementNameResolver ;
18
18
use Magento \Framework \Setup \Declaration \Schema \Diff \Diff ;
19
19
use Magento \Framework \Setup \Declaration \Schema \Dto \Schema ;
20
+ use Magento \Framework \Setup \Declaration \Schema \Dto \Table ;
20
21
use Magento \Framework \Setup \Declaration \Schema \SchemaConfig ;
21
22
use Magento \Framework \Setup \JsonPersistor ;
22
23
@@ -192,6 +193,9 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
192
193
$ elementType = 'index ' ;
193
194
if (!empty ($ tableData [$ elementType ])) {
194
195
foreach ($ tableData [$ elementType ] as $ tableElementData ) {
196
+ if (!isset ($ tableElementData ['column ' ])) {
197
+ continue ;
198
+ }
195
199
$ indexName = $ this ->elementNameResolver ->getFullIndexName (
196
200
$ table ,
197
201
$ tableElementData ['column ' ],
@@ -201,9 +205,30 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
201
205
}
202
206
}
203
207
208
+ $ constraintName = $ this ->getConstraintName ($ schema , $ table , $ tableData );
209
+ if ($ constraintName ) {
210
+ $ declaredStructure += $ constraintName ;
211
+ }
212
+
213
+ return $ declaredStructure ;
214
+ }
215
+
216
+ /**
217
+ * @param Schema $schema
218
+ * @param Table $table
219
+ * @param array $tableData
220
+ * @return array
221
+ */
222
+ private function getConstraintName (Schema $ schema , Table $ table , array $ tableData ): array
223
+ {
224
+ $ declaredStructure = [];
225
+
204
226
$ elementType = 'constraint ' ;
205
227
if (!empty ($ tableData [$ elementType ])) {
206
228
foreach ($ tableData [$ elementType ] as $ tableElementData ) {
229
+ if (!isset ($ tableElementData ['referenceTable ' ])) {
230
+ continue ;
231
+ }
207
232
if ($ tableElementData ['type ' ] === 'foreign ' ) {
208
233
$ referenceTable = $ schema ->getTableByName ($ tableElementData ['referenceTable ' ]);
209
234
$ column = $ table ->getColumnByName ($ tableElementData ['column ' ]);
@@ -216,6 +241,9 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
216
241
$ referenceColumn
217
242
) : null ;
218
243
} else {
244
+ if (!isset ($ tableElementData ['column ' ])) {
245
+ continue ;
246
+ }
219
247
$ constraintName = $ this ->elementNameResolver ->getFullIndexName (
220
248
$ table ,
221
249
$ tableElementData ['column ' ],
0 commit comments