I'm trying to upgrade my ldap module from ldap-7.x-1.0-beta12 to ldap-7.x-2.0-beta5. The upgrade fails during 'drush updb' with the error message "Duplicate column: 7 ERROR: column "groupusermembershipsattrexists" of relation "ldap_servers" already exists". I'm using Postgres as database.

The 7108 update fails like this:

$ drush updb
Initialized Drupal 7.22 root directory at /Users/gaa041/u/w3.uib.no/drupal                                                                                    [notice]
Initialized Drupal site w3.uib.9zlhb.xip.io at sites/w3.uib.9zlhb.xip.io                                                                                      [notice]
The following updates are pending:

ldap_servers module :
  7106 -   add account_name_attr field to ldap_servers table
  7107 -    remove allow_conflicting_drupal_accts from ldap_servers table
  7108 -   add group related fields to ldap_servers table
  7109 -   adjust group related fields to ldap_servers table
  7110 -   adjust group related fields to ldap_servers table
  7111 -   add field groupTestGroupDnWriteable to ldap_servers table
  7112 -   add field testingDrupalUserDn to ldap_servers table
  7201 -   upgrade as much as feasible for 7.1 to 7.2 branch
  7202 -   make ldap_servers.bind_method field small int instead of tiny int for ctools bug
  7203 -   make all schema field names lowercase in ldap server to deal with cronic case sensitivity issues
  7204 -   Add picture_attr field in schema
  7205 -   fix any double serialized ldap server basedns
  7206 -   Add LDAP Referrals fields in schema

Do you wish to run all pending updates? (y/n): y
/usr/local/bin/php /Users/gaa041/p/drush/drush.php --php=/usr/local/bin/php  --backend=2 --verbose --root=/Users/gaa041/drupal                    [notice]
--uri=http://w3.uib.9zlhb.xip.io  updatedb-batch-process 18770 18770 2>&1
Initialized Drupal 7.22 root directory at /Users/gaa041/u/w3.uib.no/drupal                                                                                    [notice]
Initialized Drupal site w3.uib.9zlhb.xip.io at sites/w3.uib.9zlhb.xip.io                                                                                      [notice]
Executing ldap_servers_update_7106                                                                                                                            [notice]
Undefined variable: msg ldap_servers.install:273                                                                                                              [notice]
Performed update: ldap_servers_update_7106                                                                                                                 [ok]
Executing ldap_servers_update_7107                                                                                                                            [notice]
Performed update: ldap_servers_update_7107                                                                                                                 [ok]
Executing ldap_servers_update_7108                                                                                                                            [notice]
SQLSTATE[42701]: Duplicate column: 7 ERROR:  column "groupusermembershipsattrexists" of relation "ldap_servers" already exists                             [error]
Performed update: ldap_servers_update_7108                                                                                                                 [ok]
Command dispatch complete                                                                                                                                     [notice]
Finished performing updates.                                                                                                                               [ok]
Command dispatch complete                                                                                                                                     [notice]

Comments

gaas’s picture

The problem is that db_field_exists('ldap_servers', 'groupFunctionalityUnused') returns FALSE when the column was created with an all lowercase name. This makes the updates try to create various columns that already exists.

I verified that if I apply this hack to Drupal core, then all the update tasks completes.

diff --git a/includes/database/schema.inc b/includes/database/schema.inc
index d3943b2..8fcd55f 100644
--- a/includes/database/schema.inc
+++ b/includes/database/schema.inc
@@ -353,7 +353,7 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface {
    */
   public function fieldExists($table, $column) {
     $condition = $this->buildTableNameCondition($table);
-    $condition->condition('column_name', $column);
+    $condition->condition('column_name', drupal_strtolower($column));
     $condition->compile($this->connection, $this);
     // Normally, we would heartily discourage the use of string
     // concatenation for conditionals like this however, we
steinmb’s picture

Version: 7.x-2.0-beta5 » 7.x-2.x-dev

What db. was this seen on? Some DB collations schema is *_ci.

steinmb’s picture

Title: Update 7108 fails: Duplicate column: 7 ERROR: column "groupusermembershipsattrexists" of relation "ldap_servers" already exists » ldap_servers_update_7108 groupfunctionalityunused already exists, break 7.x-2.x upgrade
Priority: Normal » Major

PHP 5.4.15 (cli) (built: Jun 25 2013 10:07:48)
Drupal 7.23
PostgreSQL 9.2.4
Upgrade from 7.x-1.0-beta12 - 7.x-2.0-beta5/7.x-1.x-dev

ldap_servers_update_7108 "groupusermembershipsattrexists" of relation "ldap_servers" already exists

                                             Unlogged table "public.\ "
             Column             |          Type           |                             Modifiers
--------------------------------+-------------------------+--------------------------------------------------------------------
 sid                            | character varying(20)   | not null
 numeric_sid                    | integer                 | not null default nextval('ldap_servers_numeric_sid_seq'::regclass)
 name                           | character varying(255)  | not null
 status                         | smallint                | not null default 0
 ldap_type                      | character varying(20)   |
 address                        | character varying(255)  | not null
 port                           | integer                 | not null default 389
 tls                            | smallint                | not null default 0
 bind_method                    | smallint                | not null default 0
 binddn                         | character varying(511)  |
 bindpw                         | character varying(255)  |
 basedn                         | text                    |
 user_attr                      | character varying(255)  | not null
 account_name_attr              | character varying(255)  | default ''::character varying
 mail_attr                      | character varying(255)  |
 mail_template                  | character varying(255)  |
 unique_persistent_attr         | character varying(64)   |
 user_dn_expression             | character varying(255)  |
 ldap_to_drupal_user            | character varying(1024) |
 testing_drupal_username        | character varying(255)  |
 group_object_category          | character varying(64)   |
 search_pagination              | smallint                | default 0
 search_page_size               | integer                 | default 1000
 weight                         | integer                 | not null default 0
 groupfunctionalityunused       | smallint                | default 0
 groupnested                    | smallint                | default 0
 groupsearchall                 | smallint                | default 0
 groupusermembershipsattrexists | smallint                | default 0
 groupderivefromdn              | smallint                | default 0
Indexes:
    "ldap_servers_pkey" PRIMARY KEY, btree (numeric_sid)
    "ldap_servers_name_key" UNIQUE CONSTRAINT, btree (name)
Check constraints:
    "ldap_servers_numeric_sid_check" CHECK (numeric_sid >= 0)

Further down the upgrade path do we try to address this in ldap_servers_update_7203() were all the case sensitive columns are renamed, though I doubt that is actually will work then it is running db_field_exists() with cased values.

This break any upgrade paths from 7.x-1.x to 7.x-2.x not that we really need one. Uninstalling and installing again is not very hard but we should document that it is not supported.

johnbarclay’s picture

StatusFileSize
new11.86 KB

here's a patch to check for mixed and lowercase table names. please test. I don't think this is so much a bug in core as inconsistency over time of table names in ldap.

steinmb’s picture

Title: ldap_servers_update_7108 groupfunctionalityunused already exists, break 7.x-2.x upgrade » 7.x-2.x to 7.x-2.x upgrade path broken on ci database systems
Status: Active » Needs review
StatusFileSize
new12.59 KB

Thanx for the swift reply :)

The patch did not work, blew up on three different places:

1. syntax error, unexpected '{' in ldap/ldap_servers/ldap_servers.install, line 313
2. Segmentation fault: 11
3. Call to undefined function ldap_servers_ldap_servers_db_field_exists() in ldap/ldap_servers/ldap_servers.install on line 301

Have tried to fix these but this prob. needs some more testing.

steinmb’s picture

Title: 7.x-2.x to 7.x-2.x upgrade path broken on ci database systems » 7.x-1.x to 7.x-2.x upgrade path broken on ci database systems
johnbarclay’s picture

Category: bug » feature

1 to 2 update is not supported. Turning this into task

steinmb’s picture

Category: feature » bug
StatusFileSize
new13.83 KB

Get rid of warning from: ldap_servers_update_7112
array_keys() expects parameter 1 to be array, null given ldap_servers.install:662

steinmb’s picture

Category: bug » task

Cross post

grahl’s picture

Status: Needs review » Closed (won't fix)

Upgrade path per module policy no longer being worked on.