Skip to content

Commit a54e80c

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

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
@@ -227,7 +227,7 @@ private function parseTableCommentFromSQL(string $table, string $sql): ?string
227227
private function parseColumnCommentFromSQL(string $column, string $sql): string
228228
{
229229
$pattern = '{[\s(,]' . $this->buildIdentifierPattern($column)
230-
. '(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i';
230+
. '\s(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s+--[^\n]*\n?)+)}i';
231231

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

tests/Schema/SQLiteSchemaManagerTest.php

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

0 commit comments

Comments
 (0)