This commit is contained in:
Daniil Gentili 2024-03-28 18:24:41 +01:00
parent 21ad5239e1
commit 7085bc4717
2 changed files with 11 additions and 8 deletions

View File

@ -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()) { while ($column = $result->fetchRow()) {
['Field' => $key, 'Type' => $type, 'Null' => $null] = $column; ['column_name' => $key, 'data_type' => $type, 'is_nullable' => $null] = $column;
$type = \strtoupper($type); $type = \strtoupper($type);
if (\str_starts_with($type, 'BIGINT')) { if (\str_starts_with($type, 'BIGINT')) {
$type = 'BIGINT'; $type = 'BIGINT';
@ -119,8 +119,14 @@ class PostgresArray extends SqlArray
$connection->query("ALTER TABLE \"bytea_{$config->table}\" DROP \"$key\""); $connection->query("ALTER TABLE \"bytea_{$config->table}\" DROP \"$key\"");
continue; continue;
} }
if ($expected !== $type || $null !== 'NO') { if ($expected !== $type) {
$connection->query("ALTER TABLE \"bytea_{$config->table}\" MODIFY \"$key\" $expected NOT NULL"); 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");
} }
} }

View File

@ -62,10 +62,7 @@ final class OrmTest extends TestCase
$f = []; $f = [];
foreach (['redis' => 6379, 'mariadb' => 3306, 'postgres' => 5432] as $image => $port) { foreach (['redis' => 6379, 'mariadb' => 3306, 'postgres' => 5432] as $image => $port) {
$f []= async(function () use ($image, $port) { $f []= async(function () use ($image, $port) {
await([ self::shellExec("docker rm -f test_$image 2>/dev/null");
async(self::shellExec(...), "docker pull $image"),
async(self::shellExec(...), "docker rm -f test_$image 2>/dev/null")
]);
$args = match ($image) { $args = match ($image) {
'postgres' => '-e POSTGRES_HOST_AUTH_METHOD=trust', 'postgres' => '-e POSTGRES_HOST_AUTH_METHOD=trust',