From 7085bc471764dc396c8277c1be58307a66d9c2e4 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 28 Mar 2024 18:24:41 +0100 Subject: [PATCH] Fixes --- src/Internal/Driver/PostgresArray.php | 14 ++++++++++---- tests/OrmTest.php | 5 +---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Internal/Driver/PostgresArray.php b/src/Internal/Driver/PostgresArray.php index 1fe6b6c..1d2eae3 100644 --- a/src/Internal/Driver/PostgresArray.php +++ b/src/Internal/Driver/PostgresArray.php @@ -104,9 +104,9 @@ class PostgresArray extends SqlArray ); "); - $result = $connection->query("DESCRIBE \"bytea_{$config->table}\""); + $result = $connection->query("SELECT * FROM information_schema.columns WHERE table_name='bytea_{$config->table}'"); while ($column = $result->fetchRow()) { - ['Field' => $key, 'Type' => $type, 'Null' => $null] = $column; + ['column_name' => $key, 'data_type' => $type, 'is_nullable' => $null] = $column; $type = \strtoupper($type); if (\str_starts_with($type, 'BIGINT')) { $type = 'BIGINT'; @@ -119,8 +119,14 @@ class PostgresArray extends SqlArray $connection->query("ALTER TABLE \"bytea_{$config->table}\" DROP \"$key\""); continue; } - if ($expected !== $type || $null !== 'NO') { - $connection->query("ALTER TABLE \"bytea_{$config->table}\" MODIFY \"$key\" $expected NOT NULL"); + if ($expected !== $type) { + if ($expected === 'BIGINT') { + $expected .= " USING $key::bigint"; + } + $connection->query("ALTER TABLE \"bytea_{$config->table}\" ALTER COLUMN \"$key\" TYPE $expected"); + } + if ($null !== 'NO') { + $connection->query("ALTER TABLE \"bytea_{$config->table}\" ALTER COLUMN \"$key\" SET NOT NULL"); } } diff --git a/tests/OrmTest.php b/tests/OrmTest.php index c79e15b..78c736d 100644 --- a/tests/OrmTest.php +++ b/tests/OrmTest.php @@ -62,10 +62,7 @@ final class OrmTest extends TestCase $f = []; foreach (['redis' => 6379, 'mariadb' => 3306, 'postgres' => 5432] as $image => $port) { $f []= async(function () use ($image, $port) { - await([ - async(self::shellExec(...), "docker pull $image"), - async(self::shellExec(...), "docker rm -f test_$image 2>/dev/null") - ]); + self::shellExec("docker rm -f test_$image 2>/dev/null"); $args = match ($image) { 'postgres' => '-e POSTGRES_HOST_AUTH_METHOD=trust',