Skip to content

Commit 4144cc8

Browse files
committed
MC-5620: --convert-old-scripts mode does not convert indexes and constraints correctly
1 parent 54efea0 commit 4144cc8

File tree

13 files changed

+761
-76
lines changed

13 files changed

+761
-76
lines changed

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule8/revisions/setup_install_with_converting/InstallSchema.php

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class InstallSchema implements InstallSchemaInterface
2828
*/
2929
const SECOND_TABLE = 'module8_test_second_table';
3030

31+
/**
32+
* The name of the second table of Module8.
33+
*/
34+
const TEMP_TABLE = 'module8_test_install_temp_table';
35+
3136
/**
3237
* @inheritdoc
3338
* @throws \Zend_Db_Exception
@@ -65,6 +70,8 @@ private function createTables(SchemaSetupInterface $installer)
6570
$this->addIndexesToSecondTable($secondTable);
6671
$this->addConstraintsToSecondTable($secondTable);
6772
$installer->getConnection()->createTable($secondTable);
73+
74+
$this->createSimpleTable($installer, self::TEMP_TABLE);
6875
}
6976

7077
/**
@@ -103,8 +110,16 @@ private function addColumnsToMainTable($table)
103110
'nullable' => false
104111
],
105112
'Email Contact ID'
106-
)
107-
->addColumn(
113+
)->addColumn(
114+
'module8_contact_group_id',
115+
Table::TYPE_INTEGER,
116+
10,
117+
[
118+
'unsigned' => true,
119+
'nullable' => false
120+
],
121+
'Contact Group ID'
122+
)->addColumn(
108123
'module8_is_guest',
109124
Table::TYPE_SMALLINT,
110125
null,
@@ -113,8 +128,7 @@ private function addColumnsToMainTable($table)
113128
'nullable' => true
114129
],
115130
'Is Guest'
116-
)
117-
->addColumn(
131+
)->addColumn(
118132
'module8_contact_id',
119133
Table::TYPE_TEXT,
120134
15,
@@ -123,6 +137,14 @@ private function addColumnsToMainTable($table)
123137
'nullable' => true
124138
],
125139
'Contact ID'
140+
)->addColumn(
141+
'module8_content',
142+
Table::TYPE_TEXT,
143+
15,
144+
[
145+
'nullable' => false,
146+
],
147+
'Content'
126148
);
127149
}
128150

@@ -145,10 +167,16 @@ private function addIndexesToMainTable($table)
145167
)->addIndex(
146168
'MODULE8_INSTALL_INDEX_3',
147169
['module8_is_guest']
148-
)
149-
->addIndex(
170+
)->addIndex(
150171
'MODULE8_INSTALL_INDEX_4',
151172
['module8_contact_id']
173+
)->addIndex(
174+
'MODULE8_INSTALL_INDEX_TEMP',
175+
['module8_content']
176+
)->addIndex(
177+
'MODULE8_INSTALL_UNIQUE_INDEX_TEMP',
178+
['module8_contact_group_id'],
179+
['type' => AdapterInterface::INDEX_TYPE_UNIQUE]
152180
);
153181
}
154182

@@ -172,21 +200,18 @@ private function addColumnsToSecondTable($table)
172200
'nullable' => false
173201
],
174202
'Entity ID'
175-
)
176-
->addColumn(
203+
)->addColumn(
177204
'module8_contact_id',
178205
Table::TYPE_INTEGER,
179206
null,
180207
[],
181208
'Contact ID'
182-
)
183-
->addColumn(
209+
)->addColumn(
184210
'module8_address',
185211
Table::TYPE_TEXT,
186212
15,
187213
[
188-
'unsigned' => true,
189-
'nullable' => true
214+
'nullable' => false,
190215
],
191216
'Address'
192217
)->addColumn(
@@ -211,6 +236,15 @@ private function addColumnsToSecondTable($table)
211236
'nullable' => true
212237
],
213238
'Second Address'
239+
)->addColumn(
240+
'module8_temp_column',
241+
Table::TYPE_TEXT,
242+
15,
243+
[
244+
'unsigned' => true,
245+
'nullable' => true
246+
],
247+
'Temp column for remove'
214248
);
215249
}
216250

@@ -254,6 +288,47 @@ private function addConstraintsToSecondTable($table)
254288
'module8_address',
255289
self::MAIN_TABLE,
256290
'module8_contact_id'
291+
)->addForeignKey(
292+
'MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_MODULE8_CONTENT_TEMP',
293+
'module8_address',
294+
self::MAIN_TABLE,
295+
'module8_content'
296+
);
297+
}
298+
299+
/**
300+
* Create a simple table.
301+
*
302+
* @param SchemaSetupInterface $setup
303+
* @param $tableName
304+
* @throws \Zend_Db_Exception
305+
*/
306+
private function createSimpleTable(SchemaSetupInterface $setup, $tableName): void
307+
{
308+
$table = $setup->getConnection()->newTable($tableName);
309+
$table
310+
->addColumn(
311+
'module8_entity_id',
312+
Table::TYPE_INTEGER,
313+
null,
314+
[
315+
'primary' => true,
316+
'identity' => true,
317+
'nullable' => false,
318+
'unsigned' => true,
319+
],
320+
'Entity ID'
321+
)->addColumn(
322+
'module8_counter',
323+
Table::TYPE_INTEGER,
324+
null,
325+
[
326+
'unsigned' => true,
327+
'nullable' => true,
328+
'default' => 100
329+
],
330+
'Counter'
257331
);
332+
$setup->getConnection()->createTable($table);
258333
}
259334
}

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule8/revisions/setup_install_with_converting/UpgradeSchema.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
3737
{
3838
$setup->startSetup();
3939

40-
if (version_compare($context->getVersion(), '1.0.0', '<')) {
40+
if (version_compare($context->getVersion(), '1.0.1', '<')) {
4141
$tableName = $setup->getTable(self::UPDATE_TABLE);
4242
$table = $setup->getConnection()->newTable($tableName);
4343
$table->setComment('Update Test Table for Module8');
@@ -50,6 +50,34 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
5050
$this->createSimpleTable($setup, $setup->getTable(self::TEMP_TABLE));
5151
}
5252

53+
if (version_compare($context->getVersion(), '1.0.2', '<')) {
54+
$connection = $setup->getConnection();
55+
$connection
56+
->dropTable(
57+
InstallSchema::TEMP_TABLE
58+
);
59+
$connection
60+
->dropColumn(
61+
InstallSchema::SECOND_TABLE,
62+
'module8_temp_column'
63+
);
64+
$connection
65+
->dropForeignKey(
66+
InstallSchema::SECOND_TABLE,
67+
'MODULE8_INSTALL_FK_ADDRESS_TEST_MAIN_TABLE_MODULE8_CONTENT_TEMP'
68+
);
69+
$connection
70+
->dropIndex(
71+
InstallSchema::MAIN_TABLE,
72+
'MODULE8_INSTALL_INDEX_TEMP'
73+
);
74+
$connection
75+
->dropIndex(
76+
InstallSchema::MAIN_TABLE,
77+
'MODULE8_INSTALL_UNIQUE_INDEX_TEMP'
78+
);
79+
}
80+
5381
$setup->endSetup();
5482
}
5583

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
10+
<module name="Magento_TestSetupDeclarationModule8" setup_version="1.0.2"/>
11+
</config>

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule9/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
10-
<module name="Magento_TestSetupDeclarationModule9" setup_version="2.0.0" />
10+
<module name="Magento_TestSetupDeclarationModule9" setup_version="1.0.0" />
1111
</config>

dev/tests/setup-integration/testsuite/Magento/Developer/Console/Command/SetupInstallTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ public function testInstallWithConverting()
7171
'UpgradeSchema.php',
7272
'Setup'
7373
);
74-
}
7574

76-
$this->moduleManager->updateRevision(
77-
'Magento_TestSetupDeclarationModule9',
78-
'setup_install_with_converting',
79-
'module.xml',
80-
'etc'
81-
);
75+
$this->moduleManager->updateRevision(
76+
$moduleName,
77+
'setup_install_with_converting',
78+
'module.xml',
79+
'etc'
80+
);
81+
}
8282

8383
$this->cliCommand->install($modules, ['convert-old-scripts' => true]);
8484

0 commit comments

Comments
 (0)