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')),
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | defaultconfig-index-fix-1844748-4.patch | 407 bytes | bigjim |
| #1 | defaultconfig-index-fix-1844748.patch | 405 bytes | danquah |
Comments
Comment #1
danquah commentedAttaching patch
Comment #2
kasperg commentedMarking as needs review since there a patch attached.
Comment #3
tricasse commentedThe 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.
Comment #4
bigjim commentedre-rolled patch from #1, this fixed the issue for me.
Comment #5
josebc commentedMarking this as RTBC
Comment #6
wizonesolutions+1 on this getting committed. Anything getting in the way?