When installing or updating the latest dev-version, the database update throws an error. The new table "ldapauth_users" wont get created. It looks like the generated SQL contains a syntax error - the plain word "Array" instead of the content of an array. My database is Postgres 9.1

  • warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "Array" LINE 10: CONSTRAINT ldapauth_users_puid_uniq_key UNIQUE (Array) ^ in /usr/local/www/drupal6/includes/database.pgsql.inc on line 138.
  • user warning: query: CREATE TABLE ldapauth_users ( luid serial CHECK (luid >= 0), uid int CHECK (uid >= 0) NOT NULL, sid smallint NOT NULL, machine_name varchar(255) NOT NULL, dn text(512) NOT NULL, puid text(512) NOT NULL, PRIMARY KEY (luid), CONSTRAINT ldapauth_users_uid_key UNIQUE (uid), CONSTRAINT ldapauth_users_puid_uniq_key UNIQUE (Array) ) in /usr/local/www/drupal6/includes/database.inc on line 551.
  • warning: pg_query() [function.pg-query]: Query failed: ERROR: relation "ldapauth_users" does not exist in /usr/local/www/drupal6/includes/database.pgsql.inc on line 138.
  • user warning: query: CREATE INDEX ldapauth_users_puid_idx_idx ON ldapauth_users (substr(puid, 1, 255)) in /usr/local/www/drupal6/includes/database.inc on line 551.

Comments

cgmonroe’s picture

Assigned: Unassigned » cgmonroe
Status: Active » Needs review
StatusFileSize
new2.35 KB
new1.57 KB

Ok, I traced this back to a Drupal core PostGres api bug: #1148856: Postgres schema doesn't support keylength on a unique index.

This is happening because I was trying to insure that the uid and puid values were unique using SQL constraints. But since the puid could defined as an LDAP dn, the puid field needs to be a "text" field. MySQL needs a max length to index text fields... but PostGres doesn't and the API doesn't convert the schema definition properly.

Anyway, hoping for a fix in core (especially 6.x) is like waiting for snow in Miami. So here's a patch that tests for Postgres and sets up the unique key schema differently than for mysql.

I've also include the patched ldapauth.install file. To use test with this just replace the existing ldapauth.install with this one.

If this fixes the problem as expected, I'll commit it.

superhenne’s picture

StatusFileSize
new2.39 KB

This solved the first problem but introduced another one - text fields do not have a length property in postgres. For a test i removed all "length" properties in ldapauth.install and now it works.

  • warning: pg_query() [function.pg-query]: Query failed: ERROR: type modifier is not allowed for type "text" LINE 6: dn text(512) NOT NULL, ^ in /usr/local/www/drupal6/includes/database.pgsql.inc on line 138.
  • user warning: query: CREATE TABLE ldapauth_users ( luid serial CHECK (luid >= 0), uid int CHECK (uid >= 0) NOT NULL, sid smallint NOT NULL, machine_name varchar(255) NOT NULL, dn text(512) NOT NULL, puid text(512) NOT NULL, PRIMARY KEY (luid), CONSTRAINT ldapauth_users_uid_key UNIQUE (uid), CONSTRAINT ldapauth_users_puid_uniq_key UNIQUE (puid) ) in /usr/local/www/drupal6/includes/database.inc on line 551.
  • warning: pg_query() [function.pg-query]: Query failed: ERROR: relation "ldapauth_users" does not exist in /usr/local/www/drupal6/includes/database.pgsql.inc on line 138.
  • user warning: query: CREATE INDEX ldapauth_users_puid_idx_idx ON ldapauth_users (substr(puid, 1, 255)) in /usr/local/www/drupal6/includes/database.inc on line 551.
cgmonroe’s picture

Sigh, I wish I could just assume that everyone would be using MySQL > 5.0.3.. then I could just use varchar(512). But the Drupal minimum for 6 is MySQL 4.0... Anyway, removing the lengths sounds like the best thing to do.

FWIW - The length was intended to help save some space and provide a bit of optimization (some versions of MySQL will let small length text fields be cached in memory rather than assume they need to be on disk because they are large). But reviewing the code, the ldapauth_users info isn't retrieved that much, so it shouldn't be a big performance hit.

These extra changes will be committed soon. Thanks for helping work out the PostGres issues.

cgmonroe’s picture

Status: Needs review » Fixed

Fix for this included in changes just committed.

See: #1475272: 6.x-1.0 Release Candidate 1 Status

Status: Fixed » Closed (fixed)

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