Skip to content

Commit

Permalink
Bugfix to support postgres15
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <vitor@php.rio>
Signed-off-by: Simon L <szaimen@e.mail.de>
Co-Authored-By: Joas Schilling <213943+nickvergessen@users.noreply.github.com>
  • Loading branch information
2 people authored and szaimen committed Nov 11, 2022
1 parent 9d45845 commit eb7b682
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
42 changes: 39 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ services:
image: ghcr.io/nextcloud/continuous-integration-postgres-10:postgres-10
environment:
POSTGRES_USER: oc_autotest
POSTGRES_DB: oc_autotest_dummy
POSTGRES_DB: oc_autotest
POSTGRES_PASSWORD: owncloud
tmpfs:
- /var/lib/postgresql/data
Expand Down Expand Up @@ -491,7 +491,7 @@ services:
image: ghcr.io/nextcloud/continuous-integration-postgres-11:postgres-11
environment:
POSTGRES_USER: oc_autotest
POSTGRES_DB: oc_autotest_dummy
POSTGRES_DB: oc_autotest
POSTGRES_PASSWORD: owncloud
tmpfs:
- /var/lib/postgresql/data
Expand Down Expand Up @@ -527,7 +527,43 @@ services:
image: ghcr.io/nextcloud/continuous-integration-postgres-13:postgres-13
environment:
POSTGRES_USER: oc_autotest
POSTGRES_DB: oc_autotest_dummy
POSTGRES_DB: oc_autotest
POSTGRES_PASSWORD: owncloud
tmpfs:
- /var/lib/postgresql/data

trigger:
branch:
- master
- stable*
event:
- pull_request
- push

---
kind: pipeline
name: postgres15-php8.0

steps:
- name: submodules
image: ghcr.io/nextcloud/continuous-integration-alpine-git:latest
commands:
- git submodule update --init
- name: postgres-php8.0
image: ghcr.io/nextcloud/continuous-integration-php8.0:latest
commands:
- bash tests/drone-run-php-tests.sh || exit 0
- sleep 10 # gives the database enough time to initialize
- POSTGRES=15 NOCOVERAGE=true TEST_SELECTION=DB ./autotest.sh pgsql

services:
- name: cache
image: ghcr.io/nextcloud/continuous-integration-redis:latest
- name: postgres-15
image: ghcr.io/nextcloud/continuous-integration-postgres-15:latest
environment:
POSTGRES_USER: oc_autotest
POSTGRES_DB: oc_autotest
POSTGRES_PASSWORD: owncloud
tmpfs:
- /var/lib/postgresql/data
Expand Down
11 changes: 11 additions & 0 deletions lib/private/Setup/PostgreSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function setupDatabase($username) {
}

if ($canCreateRoles) {
$connectionMainDatabase = $this->connect();
//use the admin login data for the new database user

//add prefix to the postgresql user name to prevent collisions
Expand All @@ -70,6 +71,16 @@ public function setupDatabase($username) {
$this->dbPassword = \OC::$server->getSecureRandom()->generate(30, ISecureRandom::CHAR_ALPHANUMERIC);

$this->createDBUser($connection);

// Go to the main database and grant create on the public schema
// The code below is implemented to make installing possible with PostgreSQL version 15:
// https://www.postgresql.org/docs/release/15.0/
// From the release notes: For new databases having no need to defend against insider threats, granting CREATE permission will yield the behavior of prior releases
// Therefore we assume that the database is only used by one user/service which is Nextcloud
// Additional services should get installed in a separate database in order to stay secure
// Also see https://www.postgresql.org/docs/15/ddl-schemas.html#DDL-SCHEMAS-PATTERNS
$connectionMainDatabase->executeQuery('GRANT CREATE ON SCHEMA public TO ' . addslashes($this->dbUser));
$connectionMainDatabase->close();
}

$this->config->setValues([
Expand Down

2 comments on commit eb7b682

@gaudryc
Copy link

@gaudryc gaudryc commented on eb7b682 Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this patch simply does not work when I install a new instance of Nextcloud 25.0.2 Enterprise (Ubuntu 20.04, PostgreSQL 12.12).
The "maintenance:install" command stops with the following errors :

PostgreSQL username and/or password not valid
 -> You need to enter details of an existing account.
Trace: #0 /var/www/nextcloud/lib/private/Setup.php(353): OC\Setup\PostgreSQL->setupDatabase()
#1 /var/www/nextcloud/core/Command/Maintenance/Install.php(105): OC\Setup->install()
#2 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OC\Core\Command\Maintenance\Install->execute()
#3 /var/www/nextcloud/3rdparty/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#4 /var/www/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#5 /var/www/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#6 /var/www/nextcloud/lib/private/Console/Application.php(213): Symfony\Component\Console\Application->run()
#7 /var/www/nextcloud/console.php(100): OC\Console\Application->run()
#8 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')
#9 {main}

Previous: Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] FATAL:  database "nextcloud" does not exist
Trace: #0 /var/www/nextcloud/lib/private/Setup/PostgreSQL.php(110): OC\DB\Connection->connect()
#1 /var/www/nextcloud/lib/private/Setup.php(353): OC\Setup\PostgreSQL->setupDatabase()
#2 /var/www/nextcloud/core/Command/Maintenance/Install.php(105): OC\Setup->install()
#3 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OC\Core\Command\Maintenance\Install->execute()
#4 /var/www/nextcloud/3rdparty/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#5 /var/www/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#6 /var/www/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#7 /var/www/nextcloud/lib/private/Console/Application.php(213): Symfony\Component\Console\Application->run()
#8 /var/www/nextcloud/console.php(100): OC\Console\Application->run()
#9 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')
#10 {main}

To make work again, I have to change the setupDatabase method using the following solution :

  • comment "$connectionMainDatabase = $this->connect();" and "$connectionMainDatabase->close();".
  • replace $connectionMainDatabase by $connection in "$connectionMainDatabase->executeQuery('GRANT CREATE ON SCHEMA public TO ' . addslashes($this->dbUser));";

Thanks in advance to have a look to this issue.

Chris

@kesselb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gaudryc and thanks for your comment.
On GitHub, it's easy to miss comments on commits.

Please comment on the pull request directly: #34645

As a customer, you can also report an issue via https://portal.nextcloud.com/.
This is usually the fastest way to reach us.

Please sign in to comment.