From 6d37f74c2aa9eaef4de36372d25e97cfe973c903 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 25 Nov 2026 23:29:07 +0400 Subject: [PATCH 1/3] deps: require internal/dload CI jobs fetch database server binaries (Dolt, Doltgres, DoltLite) from GitHub releases with it. Assisted-By: Claude Opus 5.5 --- composer.json | 1 + composer.lock | 607 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 607 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4256412d..549a2817 100644 --- a/composer.json +++ b/composer.json @@ -58,6 +58,7 @@ "buggregator/trap": "^1.20", "cycle/testing": "^0.1.2", "ergebnis/composer-normalize": "^2.58", + "internal/dload": "^1.19", "llm/skills": "^1.20", "mockery/mockery": "^1.6", "roxblnfk/unpoly": "^1.8", diff --git a/composer.lock b/composer.lock index dbff7aef..e2a95185 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b6c871858863cbf486b7fe9087b44b87", + "content-hash": "7857c492fd8d2c5b58faa7677d774b27", "packages": [ { "name": "psr/container", @@ -1620,6 +1620,91 @@ "time": "2025-09-08T14:29:16+00:00", "published-time": "2025-09-08T16:46:06+00:00" }, + { + "name": "internal/dload", + "version": "1.19.1", + "source": { + "type": "git", + "url": "https://github.com/php-internal/dload.git", + "reference": "45055ece87fe40b7a2b62a8c0c2f04f82306bc7f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-internal/dload/zipball/45055ece87fe40b7a2b62a8c0c2f04f82306bc7f", + "reference": "45055ece87fe40b7a2b62a8c0c2f04f82306bc7f", + "shasum": "" + }, + "require": { + "internal/container": "^1.0", + "internal/destroy": "^1.0", + "internal/path": "^1.2", + "internal/toml": "^1.0.3", + "nyholm/psr7": "^1.8", + "php": ">=8.2", + "psr/container": "1 - 2", + "psr/http-client": "^1.0", + "react/async": "^3.2 || ^4.3", + "react/promise": "^2.10 || ^3.2", + "symfony/console": "^6.4 || ^7 || ^8", + "symfony/http-client": "^6.4 || ^7 || ^8" + }, + "require-dev": { + "buggregator/trap": "^1.15", + "composer/semver": "^3.4", + "dereuromark/composer-prefer-lowest": "^0.1.10", + "llm/skills": "^1.9", + "roxblnfk/unpoly": "^1.8.1", + "spiral/code-style": "^2.3.1", + "testo/bridge-mockery": "^0.1.2", + "testo/bridge-rector": "^0.2.4", + "testo/testo": "^0.10.46", + "vimeo/psalm": "^6.10 || ^7.0" + }, + "suggest": { + "ext-simplexml": "to support XML configs parsing" + }, + "bin": [ + "bin/dload" + ], + "type": "library", + "extra": { + "skills": { + "source": "skills" + } + }, + "autoload": { + "psr-4": { + "Internal\\DLoad\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Aleksei Gagarin (roxblnfk)", + "homepage": "https://github.com/roxblnfk" + } + ], + "description": "Downloads binaries.", + "keywords": [ + "download binaries", + "downloader" + ], + "support": { + "issues": "https://github.com/php-internal/dload/issues", + "source": "https://github.com/php-internal/dload/tree/1.19.1" + }, + "funding": [ + { + "url": "https://boosty.to/roxblnfk", + "type": "boosty" + } + ], + "time": "2026-10-28T13:14:24+00:00", + "published-time": "2026-10-28T13:14:40+00:00" + }, { "name": "internal/path", "version": "1.4.0", @@ -1687,6 +1772,64 @@ "time": "2026-09-08T10:51:37+00:00", "published-time": "2026-09-08T10:51:51+00:00" }, + { + "name": "internal/toml", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/php-internal/toml.git", + "reference": "b0e077794a179b0a39a4fba84185762a4425c472" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-internal/toml/zipball/b0e077794a179b0a39a4fba84185762a4425c472", + "reference": "b0e077794a179b0a39a4fba84185762a4425c472", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "buggregator/trap": "^1.13", + "internal/dload": "^1.11", + "phpunit/phpunit": "^10.5", + "spiral/code-style": "^2.3.0", + "ta-tikoma/phpunit-architecture-test": "^0.8.5", + "vimeo/psalm": "^6.13" + }, + "type": "library", + "autoload": { + "psr-4": { + "Internal\\Toml\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Aleksei Gagarin (roxblnfk)", + "homepage": "https://github.com/roxblnfk" + } + ], + "description": "TOML 1.0/1.1 parser and encoder", + "keywords": [ + "toml" + ], + "support": { + "issues": "https://github.com/php-internal/toml/issues", + "source": "https://github.com/php-internal/toml/tree/1.1.3" + }, + "funding": [ + { + "url": "https://boosty.to/roxblnfk", + "type": "boosty" + } + ], + "time": "2026-06-28T16:28:37+00:00", + "published-time": "2026-06-28T16:28:55+00:00" + }, { "name": "justinrainbow/json-schema", "version": "6.14.0", @@ -2069,6 +2212,59 @@ "time": "2024-09-09T07:06:30+00:00", "published-time": "2024-09-09T07:07:05+00:00" }, + { + "name": "psr/http-client", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client" + }, + "time": "2023-09-23T14:17:50+00:00", + "published-time": "2023-09-23T14:18:12+00:00" + }, { "name": "psr/http-factory", "version": "1.1.0", @@ -2179,6 +2375,229 @@ "time": "2023-04-04T09:54:51+00:00", "published-time": "2023-04-04T09:55:35+00:00" }, + { + "name": "react/async", + "version": "v4.3.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/async.git", + "reference": "635d50e30844a484495713e8cb8d9e079c0008a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/async/zipball/635d50e30844a484495713e8cb8d9e079c0008a5", + "reference": "635d50e30844a484495713e8cb8d9e079c0008a5", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "react/event-loop": "^1.2", + "react/promise": "^3.2 || ^2.8 || ^1.2.1" + }, + "require-dev": { + "phpstan/phpstan": "1.10.39", + "phpunit/phpunit": "^9.6" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "React\\Async\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Async utilities and fibers for ReactPHP", + "keywords": [ + "async", + "reactphp" + ], + "support": { + "issues": "https://github.com/reactphp/async/issues", + "source": "https://github.com/reactphp/async/tree/v4.3.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2024-06-04T14:40:02+00:00", + "published-time": "2024-06-04T14:42:16+00:00" + }, + { + "name": "react/event-loop", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/event-loop.git", + "reference": "ba276bda6083df7e0050fd9b33f66ad7a4ac747a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/event-loop/zipball/ba276bda6083df7e0050fd9b33f66ad7a4ac747a", + "reference": "ba276bda6083df7e0050fd9b33f66ad7a4ac747a", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + }, + "suggest": { + "ext-pcntl": "For signal handling support when using the StreamSelectLoop" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\EventLoop\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "ReactPHP's core reactor event loop that libraries can use for evented I/O.", + "keywords": [ + "asynchronous", + "event-loop" + ], + "support": { + "issues": "https://github.com/reactphp/event-loop/issues", + "source": "https://github.com/reactphp/event-loop/tree/v1.6.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2025-11-17T20:46:25+00:00", + "published-time": "2025-11-17T20:47:32+00:00" + }, + { + "name": "react/promise", + "version": "v3.3.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "23444f53a813a3296c1368bb104793ce8d88f04a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/23444f53a813a3296c1368bb104793ce8d88f04a", + "reference": "23444f53a813a3296c1368bb104793ce8d88f04a", + "shasum": "" + }, + "require": { + "php": ">=7.1.0" + }, + "require-dev": { + "phpstan/phpstan": "1.12.28 || 1.4.10", + "phpunit/phpunit": "^9.6 || ^7.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "React\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "support": { + "issues": "https://github.com/reactphp/promise/issues", + "source": "https://github.com/reactphp/promise/tree/v3.3.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2025-08-19T18:57:03+00:00", + "published-time": "2025-08-19T19:13:36+00:00" + }, { "name": "roxblnfk/unpoly", "version": "1.8.2", @@ -2475,6 +2894,192 @@ "time": "2026-11-02T10:56:49+00:00", "published-time": "2026-11-04T11:28:12+00:00" }, + { + "name": "symfony/http-client", + "version": "v7.4.25", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client.git", + "reference": "fe047cdc68aee54b315b2f142ab4c0e9c705cefc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client/zipball/fe047cdc68aee54b315b2f142ab4c0e9c705cefc", + "reference": "fe047cdc68aee54b315b2f142ab4c0e9c705cefc", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "psr/log": "^1|^2|^3", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/http-client-contracts": "~3.4.4|^3.5.2", + "symfony/polyfill-php83": "^1.29", + "symfony/service-contracts": "^2.5|^3" + }, + "conflict": { + "amphp/amp": "<2.5", + "amphp/socket": "<1.1", + "php-http/discovery": "<1.15", + "symfony/http-foundation": "<6.4" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "1.0", + "symfony/http-client-implementation": "3.0" + }, + "require-dev": { + "amphp/http-client": "^4.2.1|^5.0", + "amphp/http-tunnel": "^1.0|^2.0", + "guzzlehttp/promises": "^1.4|^2.0", + "nyholm/psr7": "^1.0", + "php-http/httplug": "^1.0|^2.0", + "psr/http-client": "^1.0", + "symfony/amphp-http-client-meta": "^1.0|^2.0", + "symfony/cache": "^6.4|^7.0|^8.0", + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/http-foundation": "^6.4.50|^7.4.23|^8.1.11", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0", + "symfony/rate-limiter": "^6.4|^7.0|^8.0", + "symfony/stopwatch": "^6.4|^7.0|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", + "homepage": "https://symfony.com", + "keywords": [ + "http" + ], + "support": { + "source": "https://github.com/symfony/http-client/tree/v7.4.25" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-11-27T13:02:26+00:00", + "published-time": "2026-11-27T14:42:41+00:00" + }, + { + "name": "symfony/http-client-contracts", + "version": "v3.8.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client-contracts.git", + "reference": "f9f94260f787446c6fd430b2ae1969fe41ae1ba8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/f9f94260f787446c6fd430b2ae1969fe41ae1ba8", + "reference": "f9f94260f787446c6fd430b2ae1969fe41ae1ba8", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, + "branch-alias": { + "dev-main": "3.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Test/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to HTTP clients", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/http-client-contracts/tree/v3.8.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-10-04T15:04:25+00:00", + "published-time": "2026-11-04T11:25:37+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.37.0", From 7a5307bf289d4009c9772b236033fbd0fd75a847 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 25 Nov 2026 23:29:28 +0400 Subject: [PATCH 2/3] ci: run the SQLite suites against DoltLite DoltLite is a SQLite fork with the sqlite3_* API, so pdo_sqlite runs on it once the library is preloaded. The preload has no effect on setup-php builds, so the suites run in the official php image. dload.xml describes DoltLite, since dload does not know it. Assisted-By: Claude Opus 5.5 --- .github/workflows/doltlite.yml | 67 ++++++++++++++++++++++++++++++++++ dload.xml | 17 +++++++++ 2 files changed, 84 insertions(+) create mode 100644 .github/workflows/doltlite.yml create mode 100644 dload.xml diff --git a/.github/workflows/doltlite.yml b/.github/workflows/doltlite.yml new file mode 100644 index 00000000..24a87bd5 --- /dev/null +++ b/.github/workflows/doltlite.yml @@ -0,0 +1,67 @@ +--- + +name: doltlite + +on: # yamllint disable-line rule:truthy + push: + branches: + - 2.x + pull_request: null + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + sqlite: + # DoltLite is a SQLite fork exporting the sqlite3_* API: preloaded, it replaces libsqlite3 under pdo_sqlite. + # The preload does not reach setup-php's pdo_sqlite, so the tests run in the official image, whose pdo_sqlite + # links libsqlite3 dynamically; Composer and dload stay on the host PHP. + name: SQLite suites on DoltLite · PHP ${{ matrix.php }} + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + php: + - '8.4' + steps: + - name: 📦 Check out the codebase + uses: actions/checkout@v7 + with: + persist-credentials: false + + - name: 🛠️ Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: pdo, pdo_sqlite, mbstring + ini-values: error_reporting=E_ALL, memory_limit=-1 + coverage: none + + - name: 📥 Install dependencies with composer + uses: ramsey/composer-install@v4 + env: + COMPOSER_ROOT_VERSION: 2.x-dev + with: + dependency-versions: locked + + - name: 📥 Download DoltLite + env: + GITHUB_TOKEN: ${{ github.token }} + run: vendor/bin/dload get doltlite --path=runtime/doltlite + + - name: ℹ️ Check that pdo_sqlite runs on DoltLite + run: >- + docker run --rm -v "$PWD:/app" -w /app -e LD_PRELOAD=/app/runtime/doltlite/libdoltlite.so php:${{ matrix.php }}-cli + php -r 'echo (new PDO("sqlite::memory:"))->query("SELECT dolt_version()")->fetchColumn(), PHP_EOL;' + + - name: 🧪 SQLite tests + run: >- + docker run --rm -v "$PWD:/app" -w /app -e LD_PRELOAD=/app/runtime/doltlite/libdoltlite.so php:${{ matrix.php }}-cli + php vendor/bin/testo --suite=Feature/SQLite --suite=Regression/SQLite + +... diff --git a/dload.xml b/dload.xml new file mode 100644 index 00000000..e1f57797 --- /dev/null +++ b/dload.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + From c8a85a7d693eb7224ae928ac76e2377e50910b7b Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 2 Dec 2026 22:55:05 +0400 Subject: [PATCH 3/3] fix(SQLite): read enum values regardless of how the table SQL is formatted The values of an enum's CHECK constraint come from sqlite_master.sql, and the parser expected the exact text Cycle writes: one column per line and `IN (` with a space. Tables created by other tools, and SQLite builds that store a canonical CREATE text (DoltLite), lost their enum values, and values containing a comma were split. The constraint is now searched in the whole definition with any spacing, and the values are read as SQL string literals. Assisted-By: Claude Opus 5.5 --- src/Driver/SQLite/Schema/SQLiteColumn.php | 67 +++++++++------ src/Driver/SQLite/Schema/SQLiteTable.php | 12 +-- .../SQLite/Schema/EnumIntrospectionTest.php | 83 +++++++++++++++++++ vendor-bin/psalm/psalm-baseline.xml | 4 - 4 files changed, 124 insertions(+), 42 deletions(-) create mode 100644 tests/Feature/SQLite/Schema/EnumIntrospectionTest.php diff --git a/src/Driver/SQLite/Schema/SQLiteColumn.php b/src/Driver/SQLite/Schema/SQLiteColumn.php index 78d2451f..1c549651 100644 --- a/src/Driver/SQLite/Schema/SQLiteColumn.php +++ b/src/Driver/SQLite/Schema/SQLiteColumn.php @@ -178,33 +178,18 @@ public static function createInstance( } if ($column->type === 'enum') { - //Quoted column name - $quoted = $schema['identifier']; - - foreach ($schema['table'] as $columnSchema) { - //Looking for enum values in column definition code - if ( - \preg_match( - "/{$quoted} +enum.*?CHECK *\\({$quoted} in \\((.*?)\\)\\)/i", - \trim($columnSchema), - $matches, - ) - ) { - $enumValues = \explode(',', $matches[1]); - foreach ($enumValues as &$value) { - //Trimming values - if (\preg_match("/^'?(.*?)'?$/", \trim($value), $matches)) { - //In database: 'value' - $value = $matches[1]; - } - - unset($value); - } - unset($value); - - $column->enumValues = $enumValues; - } - } + /** @var non-empty-string|list $definition */ + $definition = $schema['table']; + /** @var non-empty-string $name */ + $name = $schema['name']; + /** @var non-empty-string $identifier */ + $identifier = $schema['identifier']; + + $column->enumValues = self::parseEnumValues( + \is_array($definition) ? \implode("\n", $definition) : $definition, + $name, + $identifier, + ); } return $column; @@ -260,4 +245,32 @@ protected function quoteEnum(DriverInterface $driver): string { return ''; } + + /** + * Reads the values of the `CHECK ( IN (...))` constraint of an enum column from + * `sqlite_master.sql`. + * + * SQLite keeps that text as it was written, and SQLite builds such as DoltLite store their own + * canonical form instead, so the parser does not rely on line breaks or spacing: the whole + * definition is searched, and the values are read as SQL string literals. + * + * @return list + */ + private static function parseEnumValues(string $definition, string $name, string $identifier): array + { + $column = \sprintf('(?:%s|%s)', \preg_quote($identifier, '/'), \preg_quote($name, '/')); + // Each `''` can only be read one way here; with an ambiguous literal or an optional comma + // PCRE backtracks exponentially and hits its limit on longer lists. + $literal = "'[^']*(?:''[^']*)*'"; + + $pattern = "/{$column}\\s+enum\\b.*?CHECK\\s*\\(\\s*{$column}\\s*IN\\s*\\(" + . "\\s*({$literal}(?:\\s*,\\s*{$literal})*)?\\s*\\)\\s*\\)/is"; + if (!\preg_match($pattern, $definition, $matches) || !isset($matches[1])) { + return []; + } + + \preg_match_all("/'([^']*(?:''[^']*)*)'/", $matches[1], $values); + + return \array_map(static fn(string $value): string => \str_replace("''", "'", $value), $values[1]); + } } diff --git a/src/Driver/SQLite/Schema/SQLiteTable.php b/src/Driver/SQLite/Schema/SQLiteTable.php index 817f20a4..42f7d720 100644 --- a/src/Driver/SQLite/Schema/SQLiteTable.php +++ b/src/Driver/SQLite/Schema/SQLiteTable.php @@ -33,22 +33,12 @@ protected function resetIntrospectionCache(): void #[\Override] protected function fetchColumns(): array { - /** - * Parsing column definitions. - */ + // PRAGMA TABLE_INFO does not report CHECK constraints, so the enum values are parsed from the table SQL. $definition = $this->driver->query( "SELECT sql FROM sqlite_master WHERE type = 'table' and name = ?", [$this->getFullName()], )->fetchColumn(); - /* - * There is not really many ways to get extra information about column - * in SQLite, let's parse table schema. As mention, Cycle SQLite - * schema reader will support fully only tables created by Cycle as we - * expecting every column definition be on new line. - */ - $definition = \explode("\n", $definition); - $result = []; foreach ($this->columnSchemas(['table' => $definition]) as $schema) { //Making new column instance diff --git a/tests/Feature/SQLite/Schema/EnumIntrospectionTest.php b/tests/Feature/SQLite/Schema/EnumIntrospectionTest.php new file mode 100644 index 00000000..60cb317a --- /dev/null +++ b/tests/Feature/SQLite/Schema/EnumIntrospectionTest.php @@ -0,0 +1,83 @@ +database->table('enums')->getSchema(); + $schema->primary('id'); + $schema->enum('status', ['a,b', "it's", 'x)', 'plain']); + $schema->save(); + + $column = $this->database->table('enums')->getSchema()->column('status'); + + Assert::same($column->getEnumValues(), ['a,b', "it's", 'x)', 'plain']); + } + + #[DataSet([<<<'SQL' + CREATE TABLE enums( "id" integer PRIMARY KEY NOT NULL, "status" enum(8) NULL DEFAULT 'x' CHECK("status" IN('x', 'y')), "name" text) + SQL], 'single line without spaces before brackets')] + #[DataSet([<<<'SQL' + CREATE TABLE enums ( + id integer PRIMARY KEY NOT NULL, + status enum(8) NULL CHECK (status IN ('x', 'y')), + name text + ) + SQL], 'unquoted column name')] + #[DataSet([<<<'SQL' + CREATE TABLE enums ( + "id" integer PRIMARY KEY NOT NULL, + "status" enum(8) NULL + CHECK ( "status" in ( 'x' , + 'y' ) ), + "name" text + ) + SQL], 'constraint spread over lines')] + public function readsValuesFromTableSqlNotWrittenByCycle(string $sql): void + { + $this->database->getDriver()->execute($sql); + + $column = $this->database->table('enums')->getSchema()->column('status'); + + Assert::same($column->getAbstractType(), 'enum'); + Assert::same($column->getEnumValues(), ['x', 'y']); + } + + public function doesNotTakeValuesOfColumnWhoseNameEndsWithTheSameName(): void + { + $this->database->getDriver()->execute(<<<'SQL' + CREATE TABLE enums (id integer PRIMARY KEY NOT NULL, my_kind enum(4) CHECK (my_kind IN ('c', 'd')), kind enum(4) CHECK (kind IN ('a', 'b'))) + SQL); + + $schema = $this->database->table('enums')->getSchema(); + + Assert::same($schema->column('kind')->getEnumValues(), ['a', 'b']); + Assert::same($schema->column('my_kind')->getEnumValues(), ['c', 'd']); + } + + public function skipsConstraintWithExtraConditionOnLongValueList(): void + { + $values = \implode(', ', \array_fill(0, 20, "'it''s'")); + $this->database->getDriver()->execute(<<database->table('enums')->getSchema()->column('status'); + + Assert::same($column->getEnumValues(), ['x', 'y']); + } +} diff --git a/vendor-bin/psalm/psalm-baseline.xml b/vendor-bin/psalm/psalm-baseline.xml index 58ba3d73..dce3995b 100644 --- a/vendor-bin/psalm/psalm-baseline.xml +++ b/vendor-bin/psalm/psalm-baseline.xml @@ -2822,14 +2822,11 @@ - - - @@ -2937,7 +2934,6 @@ -