#986992 follow-up by yched, sun: Robustify upgrade path.
parent
15ec48062c
commit
2d9916e6f6
|
@ -113,27 +113,31 @@ function field_sql_storage_update_7001(&$sandbox) {
|
|||
$sandbox['tables'] = array();
|
||||
$results = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
|
||||
->fields('fc')
|
||||
->condition('storage_module', 'field_sql_storage')
|
||||
->execute();
|
||||
foreach ($results as $field) {
|
||||
if ($field['deleted']) {
|
||||
$sandbox['tables'][] = "field_deleted_data_{$field['id']}";
|
||||
$sandbox['tables'][] = "field_deleted_revision_{$field['id']}";
|
||||
$sandbox['tables']["field_deleted_data_{$field['id']}"] = 'data';
|
||||
$sandbox['tables']["field_deleted_revision_{$field['id']}"] = 'revision';
|
||||
}
|
||||
else {
|
||||
$sandbox['tables'][] = "field_data_{$field['field_name']}";
|
||||
$sandbox['tables'][] = "field_revision_{$field['field_name']}";
|
||||
$sandbox['tables']["field_data_{$field['field_name']}"] = 'data';
|
||||
$sandbox['tables']["field_revision_{$field['field_name']}"] = 'revision';
|
||||
}
|
||||
}
|
||||
reset($sandbox['tables']);
|
||||
|
||||
$sandbox['total'] = count($sandbox['tables']);
|
||||
$sandbox['progress'] = 0;
|
||||
}
|
||||
|
||||
if ($sandbox['tables']) {
|
||||
$table = array_pop($sandbox['tables']);
|
||||
// Grab the next table to process.
|
||||
$table = key($sandbox['tables']);
|
||||
$type = array_shift($sandbox['tables']);
|
||||
|
||||
if (db_table_exists($table)) {
|
||||
// Add the 'entity_type' column.
|
||||
// Add the 'entity_type' column.
|
||||
if (!db_field_exists($table, 'entity_type')) {
|
||||
$column = array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
|
@ -151,12 +155,20 @@ function field_sql_storage_update_7001(&$sandbox) {
|
|||
->execute();
|
||||
}
|
||||
|
||||
// Add indexes for the 'entity_type' column.
|
||||
db_drop_primary_key($table);
|
||||
db_add_primary_key($table, array('entity_type', 'entity_id', 'deleted', 'delta', 'language'));
|
||||
// Index the new column.
|
||||
db_add_index($table, 'entity_type', array('entity_type'));
|
||||
}
|
||||
|
||||
// Drop the 'etid' column.
|
||||
// Use the 'entity_type' column in the primary key.
|
||||
db_drop_primary_key($table);
|
||||
$primary_keys = array(
|
||||
'data' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
|
||||
'revision' => array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language'),
|
||||
);
|
||||
db_add_primary_key($table, $primary_keys[$type]);
|
||||
|
||||
// Drop the 'etid' column.
|
||||
if (db_field_exists($table, 'etid')) {
|
||||
db_drop_field($table, 'etid');
|
||||
}
|
||||
|
||||
|
@ -178,6 +190,25 @@ function field_sql_storage_update_7001(&$sandbox) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix primary keys in field revision data tables.
|
||||
*/
|
||||
function field_sql_storage_update_7002() {
|
||||
$results = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
|
||||
->fields('fc')
|
||||
->condition('storage_module', 'field_sql_storage')
|
||||
->execute();
|
||||
foreach ($results as $field) {
|
||||
// Revision tables of deleted fields do not need to be fixed, since no new
|
||||
// data is written to them.
|
||||
if (!$field['deleted']) {
|
||||
$table = "field_revision_{$field['field_name']}";
|
||||
db_drop_primary_key($table);
|
||||
db_add_primary_key($table, array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "defgroup field-updates-6.x-to-7.x"
|
||||
*/
|
||||
|
|
|
@ -159,7 +159,6 @@ function _field_sql_storage_schema($field) {
|
|||
'description' => 'The sequence number for this data item, used for multi-value fields',
|
||||
),
|
||||
),
|
||||
// @todo Is the primary key needed at all ?
|
||||
'primary key' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
|
||||
'indexes' => array(
|
||||
'entity_type' => array('entity_type'),
|
||||
|
@ -196,12 +195,10 @@ function _field_sql_storage_schema($field) {
|
|||
}
|
||||
}
|
||||
|
||||
// Construct the revision table. The primary key includes
|
||||
// revision_id but not entity_id so that multiple revision loads can
|
||||
// use the IN operator.
|
||||
// Construct the revision table.
|
||||
$revision = $current;
|
||||
$revision['description'] = "Revision archive storage for {$deleted}field {$field['id']} ({$field['field_name']})";
|
||||
$revision['primary key'] = array('entity_type', 'revision_id', 'deleted', 'delta', 'language');
|
||||
$revision['primary key'] = array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language');
|
||||
$revision['fields']['revision_id']['not null'] = TRUE;
|
||||
$revision['fields']['revision_id']['description'] = 'The entity revision id this data is attached to';
|
||||
|
||||
|
|
Loading…
Reference in New Issue