When I attempt to install a site that uses defaultconfig on a sqlite database the install fails with:

PDOException: SQLSTATE[HY000]: General error: 1 table "defaultconfig_optionals" has more than one primary key: CREATE TABLE {defaultconfig_optionals} (
 oid INTEGER PRIMARY KEY AUTOINCREMENT CHECK (oid>= 0),
 name VARCHAR(255) NOT NULL,
 status INTEGER NOT NULL DEFAULT 0,
 PRIMARY KEY (name)
);
; Array
(
)
 in db_create_table() (line 2688 of /var/lib/jenkins/jobs/ida/workspace/site/includes/database/database.inc).

It is caused by the index of the table being described wrong in the following function:

function defaultconfig_optional_table_original() {
  return array(
    'description' => 'Table containing what optionals should be enabled.',
    'export' => array(
      'api' => array(
        'owner' => 'defaultconfig',
        'api' => 'defaultconfig_optionals_settings',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
      'key' => 'name',
      'key name' => 'Name',
      'primary key' => 'oid',
      'identifier' => 'preset',
      'default hook' => 'defaultconfig_optionals_settings',
      'load callback' => 'defaultconfig_optional_load',
    ),
    'fields' => array(
      'oid' => array(
        'description' => 'Serial id for this preset. Only used for internal lookups.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'no export' => TRUE,
      ),
      'name' => array(
        'description' => 'Machine-readable name for the exportable to be controlled.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'status' => array(
        'description' => 'Indicates if this exporatble should be on or off.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('oid', 'name'),
  );
}

The issues seems to be caused by the primary-key definition, as far as I can tell from the code the serial-type of oid makes it into a primary key by its own right, and when name is then also added as a primary key sqlite complains.

I've attached a patch that changes the composite primary-key into a a "normal" index instead.

    'indexes' => array('name_lookup' => array('oid', 'name')),

Comments

danquah’s picture

StatusFileSize
new405 bytes

Attaching patch

kasperg’s picture

Status: Active » Needs review

Marking as needs review since there a patch attached.

tricasse’s picture

The patch doesn't fix it for me.

This may be interesting: #1571842: Check the database schemas for common issues to improve portability for more info on primary keys / SQLite.

bigjim’s picture

StatusFileSize
new407 bytes

re-rolled patch from #1, this fixed the issue for me.

josebc’s picture

Status: Needs review » Reviewed & tested by the community

Marking this as RTBC

wizonesolutions’s picture

+1 on this getting committed. Anything getting in the way?