Skip to content

Commit 2e2a0a5

Browse files
author
Sergii Kovalenko
committed
Merge branch 'MAGETWO-87928' into MAGETWO-87551
2 parents 7f59f8a + 41b5b97 commit 2e2a0a5

File tree

25 files changed

+1006
-99
lines changed

25 files changed

+1006
-99
lines changed

app/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
<preference for="Magento\Setup\Model\Declaration\Schema\Db\DbSchemaReaderInterface" type="Magento\Setup\Model\Declaration\Schema\Db\MySQL\DbSchemaReader" />
180180
<preference for="Magento\Setup\Model\Declaration\Schema\Db\DbSchemaWriterInterface" type="Magento\Setup\Model\Declaration\Schema\Db\MySQL\DbSchemaWriter" />
181181
<preference for="Magento\Setup\Model\Declaration\Schema\SchemaConfigInterface" type="Magento\Setup\Model\Declaration\Schema\SchemaConfig" />
182+
<preference for="Magento\Setup\Model\Declaration\Schema\DataSavior\DumpAccessorInterface" type="Magento\Setup\Model\Declaration\Schema\FileSystem\Csv" />
182183
<type name="Magento\Framework\Model\ResourceModel\Db\TransactionManager" shared="false" />
183184
<type name="Magento\Framework\Acl\Data\Cache">
184185
<arguments>
@@ -1449,6 +1450,10 @@
14491450
<item name="add_complex_element" xsi:type="object">Magento\Setup\Model\Declaration\Schema\Operations\AddComplexElement</item>
14501451
<item name="modify_table" xsi:type="object">Magento\Setup\Model\Declaration\Schema\Operations\ModifyTable</item>
14511452
</argument>
1453+
<argument name="dataSaviorsCollection" xsi:type="array">
1454+
<item name="table_savior" xsi:type="object">Magento\Setup\Model\Declaration\Schema\DataSavior\TableSavior</item>
1455+
<item name="column_savior" xsi:type="object">Magento\Setup\Model\Declaration\Schema\DataSavior\ColumnSavior</item>
1456+
</argument>
14521457
</arguments>
14531458
</type>
14541459
<type name="Magento\Setup\Model\Declaration\Schema\Sharding">
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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:setup:Model/Declaration/Schema/etc/schema.xsd">
10+
<table name="test_table" resource="default" comment="Test Table">
11+
<column xsi:type="int" name="page_id" nullable="false" />
12+
<column xsi:type="varchar" name="email" nullable="false" />
13+
<column xsi:type="varchar" name="title" />
14+
<constraint xsi:type="primary" name="PRIMARY">
15+
<column name="page_id" />
16+
<column name="email" />
17+
</constraint>
18+
</table>
19+
</schema>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"test_table": {
3+
"column": {
4+
"page_id": true,
5+
"email": true,
6+
"title": true
7+
}
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_TestSetupDeclarationModule4" setup_version="1.0.0" />
10+
</config>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
return [
7+
[
8+
'page_id' => 1,
9+
'email' => '[email protected]',
10+
'title' => 'Title1'
11+
],
12+
[
13+
'page_id' => 2,
14+
'email' => '[email protected]',
15+
'title' => 'Title2'
16+
],
17+
[
18+
'page_id' => 3,
19+
'email' => '[email protected]',
20+
'title' => 'Title3'
21+
],
22+
[
23+
'page_id' => 4,
24+
'email' => '[email protected]',
25+
'title' => 'Title4'
26+
]
27+
];
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
$registrar = new ComponentRegistrar();
10+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestSetupDeclarationModule4') === null) {
11+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestSetupDeclarationModule4', __DIR__);
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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:setup:Model/Declaration/Schema/etc/schema.xsd">
10+
<table name="test_table" resource="default" comment="Test Table">
11+
<column xsi:type="int" name="page_id" nullable="false" />
12+
<column xsi:type="varchar" name="email" nullable="false" />
13+
<constraint xsi:type="primary" name="PRIMARY">
14+
<column name="page_id" />
15+
<column name="email" />
16+
</constraint>
17+
</table>
18+
</schema>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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:setup:Model/Declaration/Schema/etc/schema.xsd">
10+
<table name="test_table" resource="default" comment="Test Table">
11+
<column xsi:type="int" name="page_id" nullable="false" />
12+
<column xsi:type="varchar" name="email" nullable="false" />
13+
<column xsi:type="varchar" name="title" />
14+
<constraint xsi:type="primary" name="PRIMARY">
15+
<column name="page_id" />
16+
<column name="email" />
17+
</constraint>
18+
</table>
19+
</schema>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup;
8+
9+
use Magento\Framework\App\ResourceConnection;
10+
use Magento\Setup\Model\Declaration\Schema\Diff\SchemaDiff;
11+
use Magento\Setup\Model\Declaration\Schema\SchemaConfigInterface;
12+
use Magento\Setup\Model\Declaration\Schema\Sharding;
13+
use Magento\TestFramework\Deploy\CliCommand;
14+
use Magento\TestFramework\Deploy\DescribeTable;
15+
use Magento\TestFramework\Deploy\TestModuleManager;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use Magento\TestFramework\TestCase\SetupTestCase;
18+
19+
/**
20+
* The purpose of this test is verifying safe declarative installation works.
21+
*/
22+
class SafeInstallerTest extends SetupTestCase
23+
{
24+
/**
25+
* @var TestModuleManager
26+
*/
27+
private $moduleManager;
28+
29+
/**
30+
* @var CliCommand
31+
*/
32+
private $cliCommad;
33+
34+
/**
35+
* @var ResourceConnection
36+
*/
37+
private $resourceConnection;
38+
39+
40+
public function setUp()
41+
{
42+
$objectManager = Bootstrap::getObjectManager();
43+
$this->moduleManager = $objectManager->get(TestModuleManager::class);
44+
$this->cliCommad = $objectManager->get(CliCommand::class);
45+
$this->resourceConnection = $objectManager->get(ResourceConnection::class);
46+
}
47+
48+
/**
49+
* @moduleName Magento_TestSetupDeclarationModule4
50+
* @dataProviderFromFile Magento/TestSetupDeclarationModule4/fixture/safe_data_provider.php
51+
*/
52+
public function testInstallation()
53+
{
54+
$testTableData = $this->getData();
55+
$row = reset($testTableData);
56+
$this->cliCommad->install(
57+
['Magento_TestSetupDeclarationModule4']
58+
);
59+
$adapter = $this->resourceConnection->getConnection();
60+
$testTableName = $this->resourceConnection->getTableName('test_table');
61+
$adapter->insertArray(
62+
$this->resourceConnection->getTableName('test_table'),
63+
array_keys($row),
64+
$this->getData()
65+
);
66+
//Move new db_schema.xml
67+
$this->moduleManager->updateRevision(
68+
'Magento_TestSetupDeclarationModule4',
69+
'remove_title_column',
70+
'db_schema.xml',
71+
'etc'
72+
);
73+
$this->cliCommad->upgrade();
74+
//Move new db_schema.xml with restored title field
75+
$this->moduleManager->updateRevision(
76+
'Magento_TestSetupDeclarationModule4',
77+
'restore_title_column',
78+
'db_schema.xml',
79+
'etc'
80+
);
81+
$this->cliCommad->upgrade();
82+
$testTableSelect = $adapter->select()->from($testTableName);
83+
self::assertEquals($testTableData, $adapter->fetchAll($testTableSelect));
84+
}
85+
}

setup/src/Magento/Setup/Console/Command/InstallCommand.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ class InstallCommand extends AbstractSetupCommand
6767
*/
6868
const INPUT_KEY_INTERACTIVE_SETUP_SHORTCUT = 'i';
6969

70+
/**
71+
* Parameter says that in this mode all destructive operations, like column removal will be dumped
72+
*/
73+
const INPUT_KEY_SAFE_INSTALLER_MODE = 'safe-mode';
74+
75+
/**
76+
* Parameter allows to restore data, that was dumped with safe mode before
77+
*/
78+
const INPUT_KEY_DATA_RESTORE = 'data-restore';
79+
7080
/**
7181
* Regex for sales_order_increment_prefix validation.
7282
*/
@@ -175,6 +185,18 @@ protected function configure()
175185
InputOption::VALUE_NONE,
176186
'Interactive Magento instalation'
177187
),
188+
new InputOption(
189+
self::INPUT_KEY_SAFE_INSTALLER_MODE,
190+
null,
191+
InputOption::VALUE_NONE,
192+
'Safe installation of Magento with dumps on destructive operations, like column removal'
193+
),
194+
new InputOption(
195+
self::INPUT_KEY_DATA_RESTORE,
196+
null,
197+
InputOption::VALUE_NONE,
198+
'Restore removed data from dumps'
199+
),
178200
]);
179201
$this->setName('setup:install')
180202
->setDescription('Installs the Magento application')

0 commit comments

Comments
 (0)