From e05c6aa3077047079eccc530124f0923f9dbde8c Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 11 Jun 2025 20:15:57 +0200 Subject: [PATCH] :bug: Fix SQLite comment parsing when table and column have same name and both have a comment --- src/Schema/SQLiteSchemaManager.php | 2 +- tests/Schema/SQLiteSchemaManagerTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Schema/SQLiteSchemaManager.php b/src/Schema/SQLiteSchemaManager.php index 2e156374b8a..c3ae276a1a1 100644 --- a/src/Schema/SQLiteSchemaManager.php +++ b/src/Schema/SQLiteSchemaManager.php @@ -390,7 +390,7 @@ private function parseTableCommentFromSQL(string $table, string $sql): ?string private function parseColumnCommentFromSQL(string $column, string $sql): string { $pattern = '{[\s(,]' . $this->buildIdentifierPattern($column) - . '(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i'; + . '\s(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s+--[^\n]*\n?)+)}i'; if (preg_match($pattern, $sql, $match) !== 1) { return ''; diff --git a/tests/Schema/SQLiteSchemaManagerTest.php b/tests/Schema/SQLiteSchemaManagerTest.php index f7ad776cd32..1a267e4adb3 100644 --- a/tests/Schema/SQLiteSchemaManagerTest.php +++ b/tests/Schema/SQLiteSchemaManagerTest.php @@ -201,6 +201,14 @@ public static function getDataColumnComment(): iterable PRIMARY KEY(id) )', ], + 'Column name equals table name and both have a comment' => [ + 'column comment', + 'user', + 'CREATE TABLE "user" --table comment + ( + "user" INT --column comment + )' + ] ]; }