Skip to content

Commit 495f335

Browse files
committed
Attempt creating db anyway
1 parent 73b4267 commit 495f335

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Internal/Driver/PostgresArray.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ public function __construct(DbArrayBuilder $config, Serializer $serializer)
6464
$_ = self::$mutex->acquire($dbKey);
6565

6666
if (!isset(self::$connections[$dbKey])) {
67+
try {
68+
$db = $settings->config->getDatabase();
69+
$user = $settings->config->getUser();
70+
$connection = new PostgresConnectionPool($settings->config->withDatabase(null));
71+
72+
$result = $connection->query("SELECT * FROM pg_database WHERE datname = '{$db}'");
73+
74+
// Replace with getRowCount once it gets fixed
75+
if (!\iterator_count($result)) {
76+
$connection->query("
77+
CREATE DATABASE {$db}
78+
OWNER {$user}
79+
ENCODING utf8
80+
");
81+
}
82+
$connection->close();
83+
} catch (\Throwable) {
84+
}
6785
self::$connections[$dbKey] = new PostgresConnectionPool($settings->config, $settings->maxConnections, $settings->idleTimeout);
6886
}
6987

tests/OrmTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static function setUpBeforeClass(): void
9494
self::shellExec("docker rm -f test_$image 2>/dev/null");
9595

9696
$args = match ($image) {
97-
'postgres' => '-e POSTGRES_HOST_AUTH_METHOD=trust -e POSTGRES_DB=test',
97+
'postgres' => '-e POSTGRES_HOST_AUTH_METHOD=trust',
9898
'mariadb' => '-e MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1',
9999
default => ''
100100
};

0 commit comments

Comments
 (0)