Problem/Motivation

The minimum required version of PostgreSQL is 10. In the Connection class of the PostgreSQL driver we have the following code:

  public function upsert($table, array $options = []) {
    // Use the (faster) native Upsert implementation for PostgreSQL >= 9.5.
    if (version_compare($this->version(), '9.5', '>=')) {
      $class = $this->getDriverClass('NativeUpsert');
    }
    else {
      $class = $this->getDriverClass('Upsert');
    }

    return new $class($this, $table, $options);
  }

The method is no longer necessary.

Proposed resolution

1. Remove the method Drupal\Core\Database\Driver\pgsql\Connection::upsert().
2. Then remove the class Drupal\Core\Database\Driver\pgsql\Upsert.
3. After that rename the class Drupal\Core\Database\Driver\pgsql\NativeUpsert to Drupal\Core\Database\Driver\pgsql\Upsert.
4. In the renamed class, change the class name from "NativeUpsert" to "Upsert" and remove the link to http://www.postgresql.org/docs/9.5/static/sql-insert.html#SQL-ON-CONFLICT.
5. The file "core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/NativeUpsert.php" can also be removed.

Remaining tasks

TBD

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

TBD

Comments

daffie created an issue. See original summary.

daffie’s picture

Issue summary: View changes
daffie’s picture

Issue summary: View changes
rik-dev’s picture

Assigned: Unassigned » rik-dev
rik-dev’s picture

Status: Active » Needs review
StatusFileSize
new12.85 KB
daffie’s picture

Status: Needs review » Needs work

Unfortunately the patch does not apply. Therefore I am not able to do a full review. Most of what the patch should do is correct. For now I have only 2 remarks:

  1. +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Upsert.php
    @@ -2,10 +2,9 @@
    -use Drupal\Core\Database\Query\Upsert as QueryUpsert;
    

    This use-statement will still be needed. This class is a subclass of the base Upsert class.

  2. +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Upsert.php
    @@ -2,10 +2,9 @@
    - * PostgreSQL implementation of \Drupal\Core\Database\Query\Upsert.
    + * PostgreSQL implementation of native \Drupal\Core\Database\Query\Upsert.
    

    This change is not necessary.

rik-dev’s picture

StatusFileSize
new12.67 KB

@daffie Thanks for took it to look. The patch was updated.

rik-dev’s picture

Status: Needs work » Needs review
daffie’s picture

@rik-dev: Your newest patch does not apply on my local machine. Did you do a "git pull" before creating your patch?

rik-dev’s picture

StatusFileSize
new12.67 KB

@daffie sure, I made "git pull" before patch that. Try this one.

rik-dev’s picture

@daffie After renamed the file Drupal\Core\Database\Driver\pgsql\NativeUpsert to Drupal\Core\Database\Driver\pgsql\Upsert I got the same error, what do I do wrong?

daffie’s picture

@rik-dev: Are you using the 9.1.x branch?

rik-dev’s picture

@daffie: no, I’m using 9.0 branch?

daffie’s picture

@rik-dev: Did you do a git mv ...? See: https://git-scm.com/docs/git-mv.

daffie’s picture

Status: Needs review » Needs work

@daffie: no, I’m using 9.0 branch?

The patch should land in the 9.1.x branch. Please use that branch.

rik-dev’s picture

Status: Needs work » Needs review
StatusFileSize
new12.72 KB

@daffie: sorry, Previously I made some patches for the 9.0 version and I didn't notice it. Thanks man:)

Status: Needs review » Needs work

The last submitted patch, 16: 3129560-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rik-dev’s picture

Status: Needs work » Needs review
daffie’s picture

Waiting for the result of the testbot.

One nitpick:

+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Upsert.php
@@ -6,6 +6,7 @@
+ *

This line does not need to be added here. The extra line in the docblock.

@rik-dev: Could you with the naming of patches take into account the comment number. Now they are all pointing to comment #5. Thank you for working on this issue.

rik-dev’s picture

@daffie: Yeap, sure. Thanks for your feedback.

daffie’s picture

Status: Needs review » Needs work

Back to needs work for the nitpick from comment #19.

rik-dev’s picture

This is a little change from comment #19. I did it, no worries.

rik-dev’s picture

Status: Needs work » Needs review
daffie’s picture

Status: Needs review » Reviewed & tested by the community

All code changes look good to me.
For me it is RTBC.

rik-dev’s picture

Assigned: rik-dev » Unassigned
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Do we care about BC here? Like will this break the fallback driver. To me it looks like it will - see https://git.drupalcode.org/project/pgsql_fallback/-/blob/1.0.x/src/Drive...

daffie’s picture

Status: Needs work » Reviewed & tested by the community

AFAIK there is no need for a BC layer. After this patch lands the PostgreSQL fallback driver has then only an unused class called NativeUpsert. Which can then safely be removed. Maybe I am missing something? If so, then please explain? For now, back to RTBC. Thank you @alexpott for thinking about a BC layer.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
  /**
   * {@inheritdoc}
   */
  public function minimumVersion() {
    return '9.6';
  }

Ah that's what I missed. From the fallback - so yeah there will be one unused class in the db driver. But that doesn't matter.

Committed 50a5a16 and pushed to 9.1.x. Thanks!

  • alexpott committed 50a5a16 on 9.1.x
    Issue #3129560 by rik-dev, daffie: Remove for PostgreSQL database driver...
amateescu’s picture

Title: Remove for PostgreSQL database driver the workaround for the Upsert class » Remove the Upsert implementation for PostgreSQL < 9.5

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.