Skip to content

Commit e05c6aa

Browse files
committed
🐛 Fix SQLite comment parsing when table and column have same name and both have a comment
1 parent b18e917 commit e05c6aa

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Schema/SQLiteSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ private function parseTableCommentFromSQL(string $table, string $sql): ?string
390390
private function parseColumnCommentFromSQL(string $column, string $sql): string
391391
{
392392
$pattern = '{[\s(,]' . $this->buildIdentifierPattern($column)
393-
. '(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i';
393+
. '\s(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s+--[^\n]*\n?)+)}i';
394394

395395
if (preg_match($pattern, $sql, $match) !== 1) {
396396
return '';

tests/Schema/SQLiteSchemaManagerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ public static function getDataColumnComment(): iterable
201201
PRIMARY KEY(id)
202202
)',
203203
],
204+
'Column name equals table name and both have a comment' => [
205+
'column comment',
206+
'user',
207+
'CREATE TABLE "user" --table comment
208+
(
209+
"user" INT --column comment
210+
)'
211+
]
204212
];
205213
}
206214

0 commit comments

Comments
 (0)