fix: Patch PostgreSQL boolean type mismatch in batch inserts

The SQL adapter's createDocuments() unconditionally casts boolean values to
integers (line 2518 in SQL.php), but PostgreSQL rejects int values for native
BOOLEAN columns. The single-document path already has an instanceof check to
preserve booleans for Postgres, but createDocuments() was missed.

This patch applies the same fix via a PHP script run during Docker build.
Fixes 26 test failures across PostgreSQL Legacy, TablesDB, and GraphQL suites.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jake Barnby
2026-02-13 05:44:58 +13:00
co-authored by Claude Opus 4.6
parent e3c58a8c05
commit e3a39499f2
2 changed files with 43 additions and 0 deletions
+5
View File
@@ -32,6 +32,11 @@ WORKDIR /usr/src/code
COPY --from=composer /usr/local/src/vendor /usr/src/code/vendor
# Patch: Fix PostgreSQL boolean type mismatch in batch inserts (utopia-php/database#createDocuments).
# TODO: Remove once utopia-php/database is updated with the upstream fix.
COPY ./patches/fix-postgres-boolean.php /tmp/fix-postgres-boolean.php
RUN php /tmp/fix-postgres-boolean.php && rm /tmp/fix-postgres-boolean.php
# Add Source Code
COPY ./app /usr/src/code/app
COPY ./public /usr/src/code/public
+38
View File
@@ -0,0 +1,38 @@
<?php
/**
* Patch: Fix PostgreSQL boolean type mismatch in batch inserts.
*
* In utopia-php/database's SQL adapter, createDocuments() unconditionally casts
* boolean values to integers. PostgreSQL rejects this because it has a native
* BOOLEAN type and doesn't accept integer expressions for boolean columns.
*
* The single-document path (updateDocument) already has this fix (instanceof check),
* but createDocuments() was missed.
*
* TODO: Remove once utopia-php/database is updated with the upstream fix.
*/
$file = '/usr/src/code/vendor/utopia-php/database/src/Database/Adapter/SQL.php';
$content = file_get_contents($file);
if ($content === false) {
echo "ERROR: Could not read {$file}\n";
exit(1);
}
$search = '} else {
$value = (\is_bool($value)) ? (int)$value : $value;';
$replace = '} else {
if (!($this instanceof \Utopia\Database\Adapter\Postgres && \is_bool($value))) { $value = (\is_bool($value)) ? (int)$value : $value; }';
$patched = str_replace($search, $replace, $content);
if ($patched === $content) {
echo "WARNING: Patch pattern not found in {$file} - may already be fixed upstream\n";
exit(0);
}
file_put_contents($file, $patched);
echo "Patched PostgreSQL boolean type handling in {$file}\n";