Problem/Motivation

Currently we are working on making it possible to change the schema name for a PostgreSQL site installation in issue #1060476: Multiple issues when PostgreSQL is used with non-public schema. Once this feature is successfully made it would be necessary to add a option to change the schema name during or after installation.

Steps to reproduce

Install a clean site and/or try to change the schema name.

Proposed resolution

Add the option to change the schema name during the installation of a clean site in the advanced options tab.
Add the option to set the schema name in the settings.php file, in case the user wants to change this afterwards.

Create tests for the newly added option.

Remaining tasks

Write the patch with the test.
Review the patch.
Commit the patch.

User interface changes

Extra option during installation.

API changes

Data model changes

Release notes snippet

TBD

Comments

Arantxio created an issue. See original summary.

arantxio’s picture

Created this issue as follow up on the related issue (#1060476), as proposed by @catch on Slack.

daffie’s picture

Issue summary: View changes
Status: Active » Postponed
arantxio’s picture

arantxio’s picture

Status: Active » Needs review
StatusFileSize
new4.03 KB

I've just created the change record and here is a patch that seems to be working correctly and also tests if it works during installation.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All code changes look good to me.
The option has been added to the installer.
Testing has been added.
The default.settings.php have been updated.
The CR and Is are in order.
For me it is RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 5: 3328215-5.patch, failed testing. View results

arantxio’s picture

Status: Needs work » Reviewed & tested by the community

There was a issue with the test bot, but that seems to be resolved. Patch still applies and also tests are still succeeding. Back to RTBC.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +ddd2023

I was confused about where this is actually used, and why we were adding this to the documentation here, but #1060476: Multiple issues when PostgreSQL is used with non-public schema added this feature without documenting it.

  1. +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php
    @@ -313,6 +313,15 @@ public function getFormOptions(array $database) {
    +      // PostgreSQL's Max Identifier Length Is 63 Bytes.
    

    Title case is not appropriate here:

    // PostgreSQL's maximum identifier length is 63 characters.
    
  2. +++ b/core/modules/pgsql/tests/src/Functional/InstallerNonDefaultSchemaTest.php
    @@ -0,0 +1,63 @@
    +    if ($connection_info['default']['driver'] !== 'pgsql') {
    +      // The schema option is only available for PostgreSQL.
    +      $this->markTestSkipped("This test does not support the {$connection_info['default']['driver']} database driver.");
    +    }
    

    Is this necessary now we have per-driver tests? Why would the Postgres tests run at all if we are in a MySQL CI environment?

_utsavsharma’s picture

StatusFileSize
new683 bytes
new4.04 KB

Tried to address pointer 1.
Please review.

poker10’s picture

Thanks for working on this.

In addition to points from @longwave, there is at least one additional issue with the patch.

The new schema input field is not required. Therefore it could be left blank. In case you left that input blank, Drupal will not install, but throws an error:

Failed to CREATE a test table on your database server with the command CREATE TABLE {drupal_install_test} (id int NOT NULL PRIMARY KEY). The server reports the following message: SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near """" LINE 1: CREATE TABLE ""."drupal_install_test" (id int NOT NULL PRIMA... ^: CREATE TABLE ""."drupal_install_test" (id int NOT NULL PRIMARY KEY); Array ( ) .

When we compare it with the port input field, which is not required as well, Drupal will install in case you leave the port field empty. Therefore we need to either mark the schema field as required, or fix the additional handling of the value in case it is left empty (and use public instead).

I have not tested this further with empty schema in settings.php (whether the default public is used in this case as well), but will do it after the installation process will be working.

Not sure about the "Needs backport to D7" tag - I think, that the D7 is not working 100% correctly on schema different from public (it was not fixed unlike the D10), so probably there is no point in addressing this in D7 unless the schema usage has been fixed.

vadim.jin’s picture

StatusFileSize
new280.95 KB

Does someone faced with next issue during re-installation drupal using drush command?
So, I have Drupal 10 site core, PostGreSQL database and use non-public schema. I have applied patches from the corresponding article. And It gives me result - I can make clean install site when my schema doesnot have any tables. But if I trying to re-install site by run 'drush si' command I faced with an error "To start over you ust empty your existing database".
When drupal ask:

You are about to:
 * DROP all tables in your 'db_name' database.

I choose yes and I got the error.
error

But if I do the same steps using 'public' schema I can successfully re-install the site and before installation all tables will be dropped.

daffie’s picture

@vadim.jin: Support for Drupal on PostgreSQL in another schema then public is something that is at the moment not supported. Would be great if we can make it work. You could work on this this by creating a PR and I will review it.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.