Skip to content

Commit c6f0c75

Browse files
committed
Merge remote-tracking branch 'origin/MC-21833' into 2.3-develop-pr85
2 parents afe8ed1 + 464a8bd commit c6f0c75

File tree

4 files changed

+165
-9
lines changed

4 files changed

+165
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
10+
<table name="test_table" resource="default">
11+
<!--Columns-->
12+
<column xsi:type="smallint" identity="true" name="smallint" padding="3" nullable="true"/>
13+
<column xsi:type="tinyint" name="tinyint" padding="7" nullable="true" unsigned="false"/>
14+
<column xsi:type="bigint" name="bigint" default="0" padding="13" nullable="true" unsigned="false"/>
15+
<column xsi:type="float" name="float" default="0" scale="4" precision="12"/>
16+
<column xsi:type="decimal" name="double" default="11111111.111111" precision="14" scale="6"/>
17+
<column xsi:type="decimal" name="decimal" default="0" scale="4" precision="15"/>
18+
<column xsi:type="date" name="date"/>
19+
<column xsi:type="timestamp" name="timestamp" default="CURRENT_TIMESTAMP" on_update="true"/>
20+
<column xsi:type="datetime" name="datetime" default="0"/>
21+
<column xsi:type="longtext" name="longtext"/>
22+
<column xsi:type="mediumtext" name="mediumtext"/>
23+
<column xsi:type="varchar" name="varchar" length="254" nullable="true"/>
24+
<column xsi:type="mediumblob" name="mediumblob"/>
25+
<column xsi:type="blob" name="blob"/>
26+
<column xsi:type="boolean" name="boolean"/>
27+
<column xsi:type="varbinary" name="varbinary_rename" default="10101" disabled="true"/>
28+
<!--Constraints-->
29+
<constraint xsi:type="unique" referenceId="TEST_TABLE_SMALLINT_BIGINT">
30+
<column name="smallint"/>
31+
<column name="bigint"/>
32+
</constraint>
33+
<!--Indexes-->
34+
<index referenceId="TEST_TABLE_TINYINT_BIGINT" indexType="btree">
35+
<column name="tinyint"/>
36+
<column name="bigint"/>
37+
</index>
38+
</table>
39+
</schema>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"test_table": {
3+
"column": {
4+
"smallint": true,
5+
"tinyint": true,
6+
"bigint": true,
7+
"float": true,
8+
"double": true,
9+
"decimal": true,
10+
"date": true,
11+
"timestamp": true,
12+
"datetime": true,
13+
"longtext": true,
14+
"mediumtext": true,
15+
"varchar": true,
16+
"mediumblob": true,
17+
"blob": true,
18+
"boolean": true,
19+
"varbinary_rename": true
20+
},
21+
"index": {
22+
"TEST_TABLE_TINYINT_BIGINT": true
23+
},
24+
"constraint": {
25+
"TEST_TABLE_SMALLINT_BIGINT": true
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"test_table": {
3+
"column": {
4+
"smallint": true,
5+
"tinyint": true,
6+
"bigint": true,
7+
"float": true,
8+
"double": true,
9+
"decimal": true,
10+
"date": true,
11+
"timestamp": true,
12+
"datetime": true,
13+
"longtext": true,
14+
"mediumtext": true,
15+
"varchar": true,
16+
"mediumblob": true,
17+
"blob": true,
18+
"boolean": true,
19+
"varbinary_rename": true
20+
},
21+
"index": {
22+
"TEST_TABLE_TINYINT_BIGINT": true
23+
},
24+
"constraint": {
25+
"TEST_TABLE_SMALLINT_BIGINT": true,
26+
"TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF": true
27+
}
28+
}
29+
}

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

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
namespace Magento\Setup;
88

99
use Magento\Framework\App\ResourceConnection;
10-
use Magento\Framework\Setup\Declaration\Schema\Diff\SchemaDiff;
11-
use Magento\Framework\Setup\Declaration\Schema\SchemaConfigInterface;
12-
use Magento\Framework\Setup\Declaration\Schema\Sharding;
10+
use Magento\Framework\Setup\Declaration\Schema\Db\DbSchemaReaderInterface;
1311
use Magento\TestFramework\Deploy\CliCommand;
14-
use Magento\TestFramework\Deploy\DescribeTable;
1512
use Magento\TestFramework\Deploy\TestModuleManager;
1613
use Magento\TestFramework\Helper\Bootstrap;
1714
use Magento\TestFramework\TestCase\SetupTestCase;
@@ -29,19 +26,28 @@ class SafeInstallerTest extends SetupTestCase
2926
/**
3027
* @var CliCommand
3128
*/
32-
private $cliCommad;
29+
private $cliCommand;
3330

3431
/**
3532
* @var ResourceConnection
3633
*/
3734
private $resourceConnection;
3835

36+
/**
37+
* @var DbSchemaReaderInterface
38+
*/
39+
private $dbSchemaReader;
40+
41+
/**
42+
* @inheritdoc
43+
*/
3944
public function setUp()
4045
{
4146
$objectManager = Bootstrap::getObjectManager();
4247
$this->moduleManager = $objectManager->get(TestModuleManager::class);
43-
$this->cliCommad = $objectManager->get(CliCommand::class);
48+
$this->cliCommand = $objectManager->get(CliCommand::class);
4449
$this->resourceConnection = $objectManager->get(ResourceConnection::class);
50+
$this->dbSchemaReader = $objectManager->get(DbSchemaReaderInterface::class);
4551
}
4652

4753
/**
@@ -52,7 +58,7 @@ public function testInstallation()
5258
{
5359
$testTableData = $this->getData();
5460
$row = reset($testTableData);
55-
$this->cliCommad->install(['Magento_TestSetupDeclarationModule4']);
61+
$this->cliCommand->install(['Magento_TestSetupDeclarationModule4']);
5662
$adapter = $this->resourceConnection->getConnection();
5763
$testTableName = $this->resourceConnection->getTableName('test_table');
5864
$adapter->insertArray(
@@ -67,7 +73,7 @@ public function testInstallation()
6773
'db_schema.xml',
6874
'etc'
6975
);
70-
$this->cliCommad->upgrade(
76+
$this->cliCommand->upgrade(
7177
[
7278
'safe-mode' => true,
7379
]
@@ -79,12 +85,66 @@ public function testInstallation()
7985
'db_schema.xml',
8086
'etc'
8187
);
82-
$this->cliCommad->upgrade(
88+
$this->cliCommand->upgrade(
8389
[
8490
'data-restore' => true,
8591
]
8692
);
8793
$testTableSelect = $adapter->select()->from($testTableName);
8894
self::assertEquals($testTableData, $adapter->fetchAll($testTableSelect));
8995
}
96+
97+
/**
98+
* Tests that not whitelisted elements should not be removed from DB to avoid backwards-incompatible change.
99+
*
100+
* @moduleName Magento_TestSetupDeclarationModule6
101+
*/
102+
public function testDestructiveOperationBehaviour()
103+
{
104+
$this->cliCommand->install(['Magento_TestSetupDeclarationModule6']);
105+
$this->assertForeignKeyPresence('test_table', 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF');
106+
107+
$this->moduleManager->updateRevision(
108+
'Magento_TestSetupDeclarationModule6',
109+
'remove_fk_declaration',
110+
'db_schema.xml',
111+
'etc'
112+
);
113+
$this->moduleManager->updateRevision(
114+
'Magento_TestSetupDeclarationModule6',
115+
'remove_fk_declaration',
116+
'db_schema_whitelist.json',
117+
'etc'
118+
);
119+
$this->cliCommand->upgrade();
120+
$this->assertForeignKeyPresence('test_table', 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF');
121+
122+
$this->moduleManager->updateRevision(
123+
'Magento_TestSetupDeclarationModule6',
124+
'restore_fk_declaration_to_wl',
125+
'db_schema_whitelist.json',
126+
'etc'
127+
);
128+
$this->cliCommand->upgrade();
129+
$this->assertForeignKeyPresence('test_table', 'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF', false);
130+
}
131+
132+
/**
133+
* Asserts foreign key presence.
134+
*
135+
* @param string $tableName
136+
* @param string $foreignKeyName
137+
* @param bool $isPresent
138+
* @return void
139+
*/
140+
private function assertForeignKeyPresence(string $tableName, string $foreignKeyName, bool $isPresent = true): void
141+
{
142+
$foreignKeys = $this->dbSchemaReader
143+
->readReferences($this->resourceConnection->getTableName($tableName), 'default');
144+
if ($isPresent) {
145+
$this->assertArrayHasKey($foreignKeyName, $foreignKeys);
146+
} else {
147+
$this->assertArrayNotHasKey($foreignKeyName, $foreignKeys);
148+
}
149+
}
90150
}

0 commit comments

Comments
 (0)