Skip to content
Snippets Groups Projects
Verified Commit fdacae95 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3159113 by daffie, saxenaakansha30, quietone: PostgreSQL Duplicate...

Issue #3159113 by daffie, saxenaakansha30, quietone: PostgreSQL Duplicate table error for alter index queries
parent 97bdbe88
No related branches found
No related tags found
33 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8323Fix source code editing and in place front page site studio editing.,!6278Issue #3187770 by godotislate, smustgrave, catch, quietone: Views Rendered...,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!673Issue #3214208: FinishResponseSubscriber could create duplicate headers,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #67202 passed with warnings
Pipeline: drupal

#67212

    Pipeline: drupal

    #67210

      Pipeline: drupal

      #67207

        +1
        ......@@ -161,12 +161,14 @@ protected function buildTableNameCondition($table_name, $operator = '=', $add_pr
        *
        * @param $table
        * The name of the table in drupal (no prefixing).
        * @param bool $add_prefix
        * Boolean to indicate whether the table name needs to be prefixed.
        *
        * @return bool
        * TRUE if the given table exists, otherwise FALSE.
        */
        public function tableExists($table) {
        $condition = $this->buildTableNameCondition($table);
        public function tableExists($table, bool $add_prefix = TRUE) {
        $condition = $this->buildTableNameCondition($table, '=', $add_prefix);
        $condition->compile($this->connection, $this);
        // Normally, we would heartily discourage the use of string
        // concatenation for conditionals like this however, we
        ......
        ......@@ -62,8 +62,8 @@ public function providerTestGetLegacyDrupalVersion() {
        'schema_version' => '1678',
        'exception' => NULL,
        'table_map' => [
        ['system', TRUE],
        ['key_value', FALSE],
        ['system', TRUE, TRUE],
        ['key_value', TRUE, FALSE],
        ],
        ],
        'D6' => [
        ......@@ -71,8 +71,8 @@ public function providerTestGetLegacyDrupalVersion() {
        'schema_version' => '6057',
        'exception' => NULL,
        'table_map' => [
        ['system', TRUE],
        ['key_value', FALSE],
        ['system', TRUE, TRUE],
        ['key_value', TRUE, FALSE],
        ],
        ],
        'D7' => [
        ......@@ -80,8 +80,8 @@ public function providerTestGetLegacyDrupalVersion() {
        'schema_version' => '7065',
        'exception' => NULL,
        'table_map' => [
        ['system', TRUE],
        ['key_value', FALSE],
        ['system', TRUE, TRUE],
        ['key_value', TRUE, FALSE],
        ],
        ],
        'D8' => [
        ......@@ -89,8 +89,8 @@ public function providerTestGetLegacyDrupalVersion() {
        'schema_version' => serialize('8976'),
        'exception' => NULL,
        'table_map' => [
        ['system', FALSE],
        ['key_value', TRUE],
        ['system', TRUE, FALSE],
        ['key_value', TRUE, TRUE],
        ],
        ],
        'D9' => [
        ......@@ -98,8 +98,8 @@ public function providerTestGetLegacyDrupalVersion() {
        'schema_version' => serialize('9270'),
        'exception' => NULL,
        'table_map' => [
        ['system', FALSE],
        ['key_value', TRUE],
        ['system', TRUE, FALSE],
        ['key_value', TRUE, TRUE],
        ],
        ],
        'Not drupal' => [
        ......@@ -107,8 +107,8 @@ public function providerTestGetLegacyDrupalVersion() {
        'schema_version' => "not drupal I guess",
        'exception' => NULL,
        'table_map' => [
        ['system', FALSE],
        ['key_value', FALSE],
        ['system', TRUE, FALSE],
        ['key_value', TRUE, FALSE],
        ],
        ],
        'D5 almost' => [
        ......@@ -116,8 +116,8 @@ public function providerTestGetLegacyDrupalVersion() {
        'schema_version' => '123',
        'exception' => NULL,
        'table_map' => [
        ['system', TRUE],
        ['key_value', FALSE],
        ['system', TRUE, TRUE],
        ['key_value', TRUE, FALSE],
        ],
        ],
        'D5/6/7 Exception' => [
        ......@@ -125,8 +125,8 @@ public function providerTestGetLegacyDrupalVersion() {
        'schema_version' => NULL,
        'exception' => new DatabaseExceptionWrapper(),
        'table_map' => [
        ['system', TRUE],
        ['key_value', FALSE],
        ['system', TRUE, TRUE],
        ['key_value', TRUE, FALSE],
        ],
        ],
        'D8/9 Exception' => [
        ......@@ -134,8 +134,8 @@ public function providerTestGetLegacyDrupalVersion() {
        'schema_version' => NULL,
        'exception' => new DatabaseExceptionWrapper(),
        'table_map' => [
        ['system', FALSE],
        ['key_value', TRUE],
        ['system', TRUE, FALSE],
        ['key_value', TRUE, TRUE],
        ],
        ],
        ];
        ......
        ......@@ -506,8 +506,8 @@ protected function createPrimaryKeySql($fields) {
        /**
        * {@inheritdoc}
        */
        public function tableExists($table) {
        $prefixInfo = $this->getPrefixInfo($table, TRUE);
        public function tableExists($table, $add_prefix = TRUE) {
        $prefixInfo = $this->getPrefixInfo($table, $add_prefix);
        return (bool) $this->connection->query("SELECT 1 FROM pg_tables WHERE schemaname = :schema AND tablename = :table", [':schema' => $prefixInfo['schema'], ':table' => $prefixInfo['table']])->fetchField();
        }
        ......@@ -586,7 +586,11 @@ public function renameTable($table, $new_name) {
        preg_match('/^' . preg_quote($table_name) . '__(.*)__' . preg_quote($index_type) . '/', $index->indexname, $matches);
        $index_name = $matches[1];
        }
        $this->connection->query('ALTER INDEX "' . $this->defaultSchema . '"."' . $index->indexname . '" RENAME TO ' . $this->ensureIdentifiersLength($new_name, $index_name, $index_type));
        // The renaming of an index will fail when the there exists an table with
        // the same name as the renamed index.
        if (!$this->tableExists($this->ensureIdentifiersLength($new_name, $index_name, $index_type), FALSE)) {
        $this->connection->query('ALTER INDEX "' . $this->defaultSchema . '"."' . $index->indexname . '" RENAME TO ' . $this->ensureIdentifiersLength($new_name, $index_name, $index_type));
        }
        }
        // Ensure the new table name does not include schema syntax.
        ......
        ......@@ -307,4 +307,60 @@ public function testPgsqlSequences(): void {
        }
        /**
        * Tests the method tableExists().
        */
        public function testTableExists() {
        $table_name = 'test_table';
        $table_specification = [
        'fields' => [
        'id' => [
        'type' => 'int',
        'default' => NULL,
        ],
        ],
        ];
        $this->schema->createTable($table_name, $table_specification);
        $prefixed_table_name = $this->connection->getPrefix($table_name) . $table_name;
        // Three different calls to the method Schema::tableExists() with an
        // unprefixed table name.
        $this->assertTrue($this->schema->tableExists($table_name));
        $this->assertTrue($this->schema->tableExists($table_name, TRUE));
        $this->assertFalse($this->schema->tableExists($table_name, FALSE));
        // Three different calls to the method Schema::tableExists() with a
        // prefixed table name.
        $this->assertFalse($this->schema->tableExists($prefixed_table_name));
        $this->assertFalse($this->schema->tableExists($prefixed_table_name, TRUE));
        $this->assertTrue($this->schema->tableExists($prefixed_table_name, FALSE));
        }
        /**
        * Tests renaming a table where the new index name is equal to the table name.
        */
        public function testRenameTableWithNewIndexNameEqualsTableName() {
        // Special table names for colliding with the PostgreSQL new index name.
        $table_name_old = 'some_new_table_name__id__idx';
        $table_name_new = 'some_new_table_name';
        $table_specification = [
        'fields' => [
        'id' => [
        'type' => 'int',
        'default' => NULL,
        ],
        ],
        'indexes' => [
        'id' => ['id'],
        ],
        ];
        $this->schema->createTable($table_name_old, $table_specification);
        // Renaming the table can fail for PostgreSQL, when a new index name is
        // equal to the old table name.
        $this->schema->renameTable($table_name_old, $table_name_new);
        $this->assertTrue($this->schema->tableExists($table_name_new));
        }
        }
        ......@@ -28,8 +28,8 @@ class Schema extends DatabaseSchema {
        /**
        * {@inheritdoc}
        */
        public function tableExists($table) {
        $info = $this->getPrefixInfo($table);
        public function tableExists($table, $add_prefix = TRUE) {
        $info = $this->getPrefixInfo($table, $add_prefix);
        // Don't use {} around sqlite_master table.
        return (bool) $this->connection->query('SELECT 1 FROM [' . $info['schema'] . '].sqlite_master WHERE type = :type AND name = :name', [':type' => 'table', ':name' => $info['table']])->fetchField();
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment