Skip to content

Commit

Permalink
Merge pull request #554 from MoonE/support-alter-table-with-column-ch…
Browse files Browse the repository at this point in the history
…eck-constraint

Allow parsing ALTER TABLE statement with column check constraint
  • Loading branch information
MauricioFauth authored May 23, 2024
2 parents 29f982a + 692cecf commit f136374
Show file tree
Hide file tree
Showing 4 changed files with 435 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
} elseif (($token->value === ',') && ($brackets === 0)) {
break;
}
} elseif (! self::checkIfTokenQuotedSymbol($token) && $token->type !== Token::TYPE_STRING) {
} elseif (
! self::checkIfTokenQuotedSymbol($token) &&
$token->type !== Token::TYPE_STRING &&
$token->value !== 'CHECK'
) {
if (isset(Parser::$STATEMENT_PARSERS[$arrayKey]) && Parser::$STATEMENT_PARSERS[$arrayKey] !== '') {
$list->idx++; // Ignore the current token
$nextToken = $list->getNext();
Expand Down
1 change: 1 addition & 0 deletions tests/Parser/AlterStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function alterProvider(): array
['parser/parseAlterTablePartitionByRange1'],
['parser/parseAlterTablePartitionByRange2'],
['parser/parseAlterTableCoalescePartition'],
['parser/parseAlterTableAddColumnWithCheck'],
['parser/parseAlterTableAddSpatialIndex1'],
['parser/parseAlterTableDropAddIndex1'],
['parser/parseAlterTableDropColumn1'],
Expand Down
1 change: 1 addition & 0 deletions tests/data/parser/parseAlterTableAddColumnWithCheck.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `xx` ADD `json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`json`));
Loading

0 comments on commit f136374

Please sign in to comment.