Skip to content

Commit 02762c1

Browse files
committed
Merge branch 'QA'
Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents eab0f93 + b8fc4f9 commit 02762c1

6 files changed

Lines changed: 3419 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Fix PHP notice "Undefined index: name in src/Components/Key.php#206" for table keys using expressions (#347)
1414
* Added support for MySQL 8.0 table structure KEY expressions (#347)
1515
* Added support for KEY order (ASC/DESC) (#296)
16+
* Added missing KEY options for MySQL and MariaDB (#348)
1617

1718
## [5.4.2] - 2021-02-05
1819

@@ -87,6 +88,7 @@
8788
- Fix PHP notice "Undefined index: name in src/Components/Key.php#206" for table keys using functions (#347)
8889
- Fix MySQL 8.0 table structure KEY expression not recognized (#347)
8990
- Fix KEY order (ASC/DESC) not part of the KEY definition (#296)
91+
- Fix missing KEY options for MySQL and MariaDB (#348)
9092

9193
## [4.7.2] - 2021-02-05
9294

src/Components/Key.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Key extends Component
3131
public static $KEY_OPTIONS = [
3232
'KEY_BLOCK_SIZE' => [
3333
1,
34-
'var',
34+
'var=',
3535
],
3636
'USING' => [
3737
2,
@@ -45,6 +45,25 @@ class Key extends Component
4545
4,
4646
'var',
4747
],
48+
// MariaDB options
49+
'CLUSTERING' => [
50+
4,
51+
'var=',
52+
],
53+
'ENGINE_ATTRIBUTE' => [
54+
5,
55+
'var=',
56+
],
57+
'SECONDARY_ENGINE_ATTRIBUTE' => [
58+
5,
59+
'var=',
60+
],
61+
// MariaDB & MySQL options
62+
'VISIBLE' => 6,
63+
'INVISIBLE' => 6,
64+
// MariaDB options
65+
'IGNORED' => 10,
66+
'NOT IGNORED' => 10,
4867
];
4968

5069
/**

tests/Components/KeyTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,60 @@ public function testParseKeyWithLengthWithOptions(): void
142142
);
143143
}
144144

145+
public function testParseKeyWithLengthWithAllOptions(): void
146+
{
147+
$component = Key::parse(
148+
new Parser(),
149+
$this->getTokensList(
150+
// This is not a vary plausible example but it runs
151+
// Only ENGINE_ATTRIBUTE gives a not supported error but is still a valid syntax
152+
'KEY `alias_type_idx` (`alias_type`(10))'
153+
. ' COMMENT \'my comment\' VISIBLE KEY_BLOCK_SIZE=1'
154+
. ' INVISIBLE ENGINE_ATTRIBUTE \'foo\' SECONDARY_ENGINE_ATTRIBUTE=\'bar\' USING BTREE,'
155+
)
156+
);
157+
$this->assertEquals('KEY', $component->type);
158+
$this->assertEquals('alias_type_idx', $component->name);
159+
$this->assertEquals(new OptionsArray(
160+
[
161+
1 => [
162+
'name' => 'KEY_BLOCK_SIZE',
163+
'equals' => true,
164+
'expr' => '1',
165+
'value' => '1',
166+
],
167+
2 => [
168+
'name' => 'USING',
169+
'equals' => false,
170+
'expr' => 'BTREE',
171+
'value' => 'BTREE',
172+
],
173+
4 => [
174+
'name' => 'COMMENT',
175+
'equals' => false,
176+
'expr' => '\'my comment\'',
177+
'value' => 'my comment',
178+
],
179+
5 => [
180+
'name' => 'ENGINE_ATTRIBUTE',
181+
'equals' => true,
182+
'expr' => '\'foo\'',
183+
'value' => 'foo',
184+
],
185+
6 => 'VISIBLE',
186+
12 => 'INVISIBLE',
187+
13 => [
188+
'name' => 'SECONDARY_ENGINE_ATTRIBUTE',
189+
'equals' => true,
190+
'expr' => '\'bar\'',
191+
'value' => 'bar',
192+
],
193+
]
194+
), $component->options);
195+
$this->assertNull($component->expr);
196+
$this->assertSame([['name' => 'alias_type', 'length' => 10]], $component->columns);
197+
}
198+
145199
public function testParseKeyExpressionWithoutOptions(): void
146200
{
147201
$component = Key::parse(

tests/Parser/CreateStatementTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function createProvider(): array
4949
['parser/parseCreateTableLike'],
5050
['parser/parseCreateTableSpatial'],
5151
['parser/parseCreateTableTimestampWithPrecision'],
52+
['parser/parseCreateTableWithInvisibleKey'],
5253
['parser/parseCreateTrigger'],
5354
['parser/parseCreateUser'],
5455
['parser/parseCreateView'],
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE TABLE `animes_comments` (
2+
`anime_comment_id` bigint unsigned NOT NULL AUTO_INCREMENT,
3+
`anime_id` bigint unsigned NOT NULL,
4+
`user_id` bigint unsigned NOT NULL,
5+
`comment_text` varchar(500) COLLATE utf8mb4_general_ci DEFAULT NULL,
6+
`comment_at` datetime DEFAULT NULL,
7+
PRIMARY KEY (`anime_comment_id`),
8+
KEY `animes_comments_animes_fk` (`anime_id`) invisible,
9+
KEY `animes_comments_users_fk` (`user_id`),
10+
KEY `comment_at_idx` (`comment_at`) ,
11+
CONSTRAINT `animes_comments_animes_fk` FOREIGN KEY (`anime_id`) REFERENCES `animes` (`anime_id`) ON DELETE CASCADE ON UPDATE RESTRICT,
12+
CONSTRAINT `animes_comments_users_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE RESTRICT)

0 commit comments

Comments
 (0)