Skip to content

Commit e13132b

Browse files
authored
[9.x] Fix postgresql build (#39531)
* Fix PostgreSQL build * wip * Gracefully handle schema key deprecation
1 parent 5e0b273 commit e13132b

File tree

3 files changed

+57
-47
lines changed

3 files changed

+57
-47
lines changed

.github/workflows/databases.yml

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -132,49 +132,49 @@ jobs:
132132
DB_CONNECTION: mysql
133133
DB_USERNAME: root
134134

135-
# pgsql:
136-
# runs-on: ubuntu-20.04
137-
138-
# services:
139-
# postgresql:
140-
# image: postgres:14
141-
# env:
142-
# POSTGRES_DB: forge
143-
# POSTGRES_USER: forge
144-
# POSTGRES_PASSWORD: password
145-
# ports:
146-
# - 5432:5432
147-
# options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
148-
149-
# strategy:
150-
# fail-fast: true
151-
152-
# name: PostgreSQL 14
153-
154-
# steps:
155-
# - name: Checkout code
156-
# uses: actions/checkout@v2
157-
158-
# - name: Setup PHP
159-
# uses: shivammathur/setup-php@v2
160-
# with:
161-
# php-version: 8.1
162-
# extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_pgsql
163-
# tools: composer:v2
164-
# coverage: none
165-
166-
# - name: Install dependencies
167-
# uses: nick-invision/retry@v1
168-
# with:
169-
# timeout_minutes: 5
170-
# max_attempts: 5
171-
# command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
172-
173-
# - name: Execute tests
174-
# run: vendor/bin/phpunit tests/Integration/Database --verbose --exclude-group MySQL
175-
# env:
176-
# DB_CONNECTION: pgsql
177-
# DB_PASSWORD: password
135+
pgsql:
136+
runs-on: ubuntu-20.04
137+
138+
services:
139+
postgresql:
140+
image: postgres:14
141+
env:
142+
POSTGRES_DB: forge
143+
POSTGRES_USER: forge
144+
POSTGRES_PASSWORD: password
145+
ports:
146+
- 5432:5432
147+
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
148+
149+
strategy:
150+
fail-fast: true
151+
152+
name: PostgreSQL 14
153+
154+
steps:
155+
- name: Checkout code
156+
uses: actions/checkout@v2
157+
158+
- name: Setup PHP
159+
uses: shivammathur/setup-php@v2
160+
with:
161+
php-version: 8.1
162+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_pgsql
163+
tools: composer:v2
164+
coverage: none
165+
166+
- name: Install dependencies
167+
uses: nick-invision/retry@v1
168+
with:
169+
timeout_minutes: 5
170+
max_attempts: 5
171+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
172+
173+
- name: Execute tests
174+
run: vendor/bin/phpunit tests/Integration/Database --verbose --exclude-group MySQL
175+
env:
176+
DB_CONNECTION: pgsql
177+
DB_PASSWORD: password
178178

179179
mssql:
180180
runs-on: ubuntu-20.04

src/Illuminate/Database/Connectors/PostgresConnector.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ protected function configureTimezone($connection, array $config)
9393
*/
9494
protected function configureSearchPath($connection, $config)
9595
{
96-
if (isset($config['search_path'])) {
97-
$searchPath = $this->quoteSearchPath($this->parseSearchPath($config['search_path']));
96+
if (isset($config['search_path']) || isset($config['schema'])) {
97+
$searchPath = $this->quoteSearchPath(
98+
$this->parseSearchPath($config['search_path'] ?? $config['schema'])
99+
);
98100

99101
$connection->prepare("set search_path to {$searchPath}")->execute();
100102
}
@@ -114,6 +116,8 @@ protected function parseSearchPath($searchPath)
114116
$searchPath = $matches[0];
115117
}
116118

119+
$searchPath = $searchPath ?? [];
120+
117121
array_walk($searchPath, function (&$schema) {
118122
$schema = trim($schema, '\'"');
119123
});

src/Illuminate/Database/Schema/PostgresBuilder.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ public function getAllTables()
134134
{
135135
return $this->connection->select(
136136
$this->grammar->compileGetAllTables(
137-
$this->parseSearchPath($this->connection->getConfig('search_path'))
137+
$this->parseSearchPath(
138+
$this->connection->getConfig('search_path') ?: $this->connection->getConfig('schema')
139+
)
138140
)
139141
);
140142
}
@@ -148,7 +150,9 @@ public function getAllViews()
148150
{
149151
return $this->connection->select(
150152
$this->grammar->compileGetAllViews(
151-
$this->parseSearchPath($this->connection->getConfig('search_path'))
153+
$this->parseSearchPath(
154+
$this->connection->getConfig('search_path') ?: $this->connection->getConfig('schema')
155+
)
152156
)
153157
);
154158
}
@@ -237,6 +241,8 @@ protected function parseSearchPath($searchPath)
237241
$searchPath = $matches[0];
238242
}
239243

244+
$searchPath = $searchPath ?? [];
245+
240246
array_walk($searchPath, function (&$schema) {
241247
$schema = trim($schema, '\'"');
242248

0 commit comments

Comments
 (0)