Skip to content

Commit e17662c

Browse files
committed
MAGETWO-95595: Index names are ignored by declarative schema
1 parent bca0e5e commit e17662c

File tree

5 files changed

+238
-122
lines changed

5 files changed

+238
-122
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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="reference_table" resource="default">
11+
<column xsi:type="tinyint" name="tinyint_ref" padding="7" nullable="false" identity="true" unsigned="false"/>
12+
<column xsi:type="tinyint" name="tinyint_without_padding" default="0" nullable="false" unsigned="false"/>
13+
<column xsi:type="bigint" name="bigint_without_padding" default="0" nullable="false" unsigned="false"/>
14+
<column xsi:type="smallint" name="smallint_without_padding" default="0" nullable="false" unsigned="false"/>
15+
<column xsi:type="int" name="integer_without_padding" default="0" nullable="false" unsigned="false"/>
16+
<column xsi:type="smallint" name="smallint_with_big_padding" padding="254" default="0" nullable="false"
17+
unsigned="false"/>
18+
<column xsi:type="smallint" name="smallint_without_default" padding="2" nullable="true" unsigned="false"/>
19+
<column xsi:type="int" name="int_without_unsigned" padding="2" nullable="true"/>
20+
<column xsi:type="int" name="int_unsigned" padding="2" nullable="true" unsigned="true"/>
21+
<column xsi:type="bigint" name="bigint_default_nullable" padding="2" nullable="true" default="1"
22+
unsigned="true"/>
23+
<column xsi:type="bigint" name="bigint_not_default_not_nullable" padding="2" nullable="false" unsigned="true"/>
24+
<constraint xsi:type="primary" referenceId="tinyint_primary">
25+
<column name="tinyint_ref"/>
26+
</constraint>
27+
</table>
28+
<table name="test_table" resource="default">
29+
<!--Columns-->
30+
<column xsi:type="smallint" identity="true" name="smallint" padding="3" nullable="true"/>
31+
<column xsi:type="tinyint" name="tinyint" padding="7" nullable="true" unsigned="false"/>
32+
<column xsi:type="bigint" name="bigint" default="0" padding="13" nullable="true" unsigned="false"/>
33+
<column xsi:type="float" name="float" default="0" scale="4" precision="12"/>
34+
<column xsi:type="decimal" name="double" default="11111111.111111" precision="14" scale="6"/>
35+
<column xsi:type="decimal" name="decimal" default="0" scale="4" precision="15"/>
36+
<column xsi:type="date" name="date"/>
37+
<column xsi:type="timestamp" name="timestamp" default="CURRENT_TIMESTAMP" on_update="true"/>
38+
<column xsi:type="datetime" name="datetime" default="0"/>
39+
<column xsi:type="longtext" name="longtext"/>
40+
<column xsi:type="mediumtext" name="mediumtext"/>
41+
<column xsi:type="varchar" name="varchar" length="254" nullable="true"/>
42+
<column xsi:type="mediumblob" name="mediumblob"/>
43+
<column xsi:type="blob" name="blob"/>
44+
<column xsi:type="boolean" name="boolean"/>
45+
<column xsi:type="varbinary" name="varbinary_rename" default="10101" disabled="true"/>
46+
<!--Constraints-->
47+
<constraint xsi:type="unique" referenceId="TEST_TABLE_UNIQUE">
48+
<column name="smallint"/>
49+
<column name="bigint"/>
50+
</constraint>
51+
<constraint xsi:type="foreign" referenceId="TEST_TABLE_TINYINT_REFERENCE"
52+
column="tinyint" table="test_table"
53+
referenceTable="reference_table" referenceColumn="tinyint_ref" onDelete="NO ACTION"/>
54+
<!--Indexes-->
55+
<index referenceId="TEST_TABLE_INDEX" indexType="btree">
56+
<column name="tinyint"/>
57+
<column name="bigint"/>
58+
</index>
59+
</table>
60+
</schema>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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="reference_test" resource="default">
11+
<column xsi:type="smallint" identity="true" name="entity_id" padding="3" nullable="true"/>
12+
<column xsi:type="smallint" identity="true" name="product_id" padding="3" nullable="true"/>
13+
<index referenceId="ENTITY_ID_INDEX" indexType="btree">
14+
<column name="entity_id"/>
15+
</index>
16+
<constraint xsi:type="unique" referenceId="UNIQUE_PAIR">
17+
<column name="entity_id"/>
18+
<column name="product_id"/>
19+
</constraint>
20+
<constraint xsi:type="foreign" referenceId="TEST_TABLE_TINYINT_REFERENCE"
21+
column="entity_id" table="reference_test"
22+
referenceTable="test_table" referenceColumn="smallint" onDelete="NO ACTION"/>
23+
</table>
24+
<table name="auto_increment_test" resource="default">
25+
<column xsi:type="int" name="int_counter" padding="12" unsigned="true"
26+
nullable="true"/>
27+
</table>
28+
</schema>

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

Lines changed: 50 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\TestFramework\TestCase\SetupTestCase;
1212
use Magento\Framework\Console\Cli;
1313
use Magento\TestFramework\Deploy\CliCommand;
14+
use Magento\TestFramework\Deploy\TestModuleManager;
1415

1516
/**
1617
* The purpose of this test is to verify the declaration:generate:whitelist command.
@@ -42,6 +43,11 @@ class TablesWhitelistGenerateCommandTest extends SetupTestCase
4243
*/
4344
private $cliCommand;
4445

46+
/**
47+
* @var TestModuleManager
48+
*/
49+
private $moduleManager;
50+
4551
/**
4652
* {@inheritdoc}
4753
*/
@@ -56,21 +62,43 @@ public function setUp()
5662
);
5763
$this->cliCommand = $this->objectManager->get(CliCommand::class);
5864
$this->tester = new CommandTester($this->command);
65+
$this->moduleManager = $this->objectManager->get(TestModuleManager::class);
5966
}
6067

6168
/**
62-
* Execute generate command for whitelist on module Magento_TestSetupDeclarationModule1.
63-
*
64-
* @param array $expectedWhitelistContent
69+
* Execute generate command for whitelist.
6570
*
6671
* @moduleName Magento_TestSetupDeclarationModule1
67-
* @dataProvider contentsDataProvider
72+
* @moduleName Magento_TestSetupDeclarationModule8
6873
* @throws \Exception
6974
*/
70-
public function testExecute(array $expectedWhitelistContent)
75+
public function testExecute()
76+
{
77+
$modules = [
78+
'Magento_TestSetupDeclarationModule1',
79+
'Magento_TestSetupDeclarationModule8',
80+
];
81+
82+
$this->cliCommand->install($modules);
83+
foreach ($modules as $moduleName) {
84+
$this->moduleManager->updateRevision(
85+
$moduleName,
86+
'whitelist_upgrade',
87+
'db_schema.xml',
88+
'etc'
89+
);
90+
}
91+
92+
foreach ($modules as $moduleName) {
93+
$this->checkWhitelistFile($moduleName);
94+
}
95+
}
96+
97+
/**
98+
* @param string $moduleName
99+
*/
100+
private function checkWhitelistFile(string $moduleName)
71101
{
72-
$moduleName = 'Magento_TestSetupDeclarationModule1';
73-
$this->cliCommand->install([$moduleName]);
74102
$modulePath = $this->componentRegistrar->getPath('module', $moduleName);
75103
$whiteListFileName = $modulePath
76104
. DIRECTORY_SEPARATOR
@@ -80,125 +108,25 @@ public function testExecute(array $expectedWhitelistContent)
80108

81109
//run bin/magento declaration:generate:whitelist Magento_TestSetupDeclarationModule1 command.
82110
$this->tester->execute(['--module-name' => $moduleName], ['interactive' => false]);
83-
84111
$this->assertSame(Cli::RETURN_SUCCESS, $this->tester->getStatusCode());
85112

86113
$this->assertFileExists($whiteListFileName);
87114
$this->assertContains('', $this->tester->getDisplay());
88115

89-
$whitelistContent = json_decode(file_get_contents($whiteListFileName), true);
90-
$this->assertEquals($expectedWhitelistContent, $whitelistContent);
91-
}
92-
93-
/**
94-
* Data provider for whitelist contents.
95-
*
96-
* @return array
97-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
98-
*/
99-
public function contentsDataProvider(): array
100-
{
101-
return [
102-
[
103-
'content' => [
104-
'reference_table' =>
105-
[
106-
'column' =>
107-
[
108-
'tinyint_ref' => true,
109-
'tinyint_without_padding' => true,
110-
'bigint_without_padding' => true,
111-
'integer_without_padding' => true,
112-
'smallint_with_big_padding' => true,
113-
'smallint_without_default' => true,
114-
'int_without_unsigned' => true,
115-
'int_unsigned' => true,
116-
'bigint_default_nullable' => true,
117-
'bigint_not_default_not_nullable' => true,
118-
'smallint_without_padding' => true,
119-
],
120-
'constraint' =>
121-
[
122-
'tinyint_primary' => true,
123-
'PRIMARY' => true,
124-
],
125-
],
126-
'auto_increment_test' =>
127-
[
128-
'column' =>
129-
[
130-
'int_auto_increment_with_nullable' => true,
131-
'int_disabled_auto_increment' => true,
132-
],
133-
'constraint' =>
134-
[
135-
'AUTO_INCREMENT_TEST_INT_AUTO_INCREMENT_WITH_NULLABLE' => true,
136-
],
137-
],
138-
'test_table' =>
139-
[
140-
'column' =>
141-
[
142-
'smallint' => true,
143-
'tinyint' => true,
144-
'bigint' => true,
145-
'float' => true,
146-
'double' => true,
147-
'decimal' => true,
148-
'date' => true,
149-
'timestamp' => true,
150-
'datetime' => true,
151-
'longtext' => true,
152-
'mediumtext' => true,
153-
'varchar' => true,
154-
'mediumblob' => true,
155-
'blob' => true,
156-
'boolean' => true,
157-
'varbinary_rename' => true,
158-
],
159-
'index' =>
160-
[
161-
'TEST_TABLE_TINYINT_BIGINT' => true,
162-
],
163-
'constraint' =>
164-
[
165-
'TEST_TABLE_SMALLINT_BIGINT' => true,
166-
'TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF' => true,
167-
],
168-
],
169-
'store' =>
170-
[
171-
'column' =>
172-
[
173-
'store_owner_id' => true,
174-
'store_owner' => true,
175-
],
176-
'constraint' =>
177-
[
178-
'STORE_STORE_OWNER_ID_STORE_OWNER_OWNER_ID' => true,
179-
],
180-
],
181-
'store_owner' =>
182-
[
183-
'column' =>
184-
[
185-
'owner_id' => true,
186-
'label' => true,
187-
],
188-
'constraint' =>
189-
[
190-
'' => true,
191-
],
192-
],
193-
'some_table' =>
194-
[
195-
'column' =>
196-
[
197-
'some_column' => true,
198-
],
199-
],
200-
],
201-
],
202-
];
116+
$whitelistFileContent = file_get_contents($whiteListFileName);
117+
$expectedWhitelistContent = file_get_contents(
118+
dirname(__DIR__, 2)
119+
. DIRECTORY_SEPARATOR
120+
. implode(
121+
DIRECTORY_SEPARATOR,
122+
[
123+
'_files',
124+
'WhitelistGenerate',
125+
str_replace('Magento_', '', $moduleName),
126+
'db_schema_whitelist.json'
127+
]
128+
)
129+
);
130+
$this->assertEquals($expectedWhitelistContent, $whitelistFileContent);
203131
}
204132
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"reference_table": {
3+
"column": {
4+
"tinyint_ref": true,
5+
"tinyint_without_padding": true,
6+
"bigint_without_padding": true,
7+
"integer_without_padding": true,
8+
"smallint_with_big_padding": true,
9+
"smallint_without_default": true,
10+
"int_without_unsigned": true,
11+
"int_unsigned": true,
12+
"bigint_default_nullable": true,
13+
"bigint_not_default_not_nullable": true,
14+
"smallint_without_padding": true
15+
},
16+
"constraint": {
17+
"tinyint_primary": true,
18+
"PRIMARY": true
19+
}
20+
},
21+
"auto_increment_test": {
22+
"column": {
23+
"int_auto_increment_with_nullable": true,
24+
"int_disabled_auto_increment": true
25+
},
26+
"constraint": {
27+
"AUTO_INCREMENT_TEST_INT_AUTO_INCREMENT_WITH_NULLABLE": true
28+
}
29+
},
30+
"test_table": {
31+
"column": {
32+
"smallint": true,
33+
"tinyint": true,
34+
"bigint": true,
35+
"float": true,
36+
"double": true,
37+
"decimal": true,
38+
"date": true,
39+
"timestamp": true,
40+
"datetime": true,
41+
"longtext": true,
42+
"mediumtext": true,
43+
"varchar": true,
44+
"mediumblob": true,
45+
"blob": true,
46+
"boolean": true,
47+
"varbinary_rename": true
48+
},
49+
"index": {
50+
"TEST_TABLE_TINYINT_BIGINT": true
51+
},
52+
"constraint": {
53+
"TEST_TABLE_SMALLINT_BIGINT": true,
54+
"TEST_TABLE_TINYINT_REFERENCE_TABLE_TINYINT_REF": true
55+
}
56+
},
57+
"store": {
58+
"column": {
59+
"store_owner_id": true,
60+
"store_owner": true
61+
},
62+
"constraint": {
63+
"STORE_STORE_OWNER_ID_STORE_OWNER_OWNER_ID": true
64+
}
65+
},
66+
"store_owner": {
67+
"column": {
68+
"owner_id": true,
69+
"label": true
70+
},
71+
"constraint": {
72+
"": true
73+
}
74+
},
75+
"some_table": {
76+
"column": {
77+
"some_column": true
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)