diff --git a/core/modules/field/field.install b/core/modules/field/field.install index b95e202..020791d 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -496,66 +496,67 @@ function field_update_8006(&$sandbox) { $field_config = $deleted_fields[$sandbox['index'] - count($config_names)]; } - $field = new Field($field_config); // Prepare updated schema data structures. - $primary_key_data = array( - 'entity_type', - 'entity_id', - 'deleted', - 'delta', - 'langcode', - ); - $primary_key_revision = array( - 'entity_type', - 'entity_id', - 'revision_id', - 'deleted', - 'delta', - 'langcode', - ); - $langcode_index = array( - 'langcode', - ); - $field_langcode = array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'default' => '', - ); + $field = new Field($field_config); $tables = array( array( 'old_table' => 'field_data_' . $field_config['name'], 'new_table' => DatabaseStorageController::_fieldTableName($field), - 'primary_key' => $primary_key_data, + 'primary_key' => array( + 'entity_id', + 'deleted', + 'delta', + 'langcode', + ), ), array( 'old_table' => 'field_revision_' . $field_config['name'], 'new_table' => DatabaseStorageController::_fieldRevisionTableName($field), - 'primary_key' => $primary_key_revision, + 'primary_key' => array( + 'entity_id', + 'revision_id', + 'deleted', + 'delta', + 'langcode', + ), ), ); + + // Move the field data to the new table. foreach ($tables as $table_data) { + // Split data from the old "per field" table to the new "per entity type and + // field" table. $new_table = $table_data['new_table']; $original_table = empty($field_config['deleted']) ? $table_data['old_table'] : 'old_' . $new_table; if (db_table_exists($original_table)) { + // Create the new table, with the same schema as the old one. if (!db_table_exists($new_table)) { db_copy_table($original_table, $new_table); } + // Copy relevant rows. $from_query = db_select($original_table, 'original') ->fields('original') ->condition('entity_type', $field_config['entity_type']); db_insert($new_table) ->from($from_query) ->execute(); - } - // Do not update tables which already have the langcode column, - // created during the upgrade before this update function. - if (db_field_exists($new_table, 'language')) { + // Drop the 'entity_type' column and previous primary key. db_drop_primary_key($new_table); - db_drop_index($new_table, 'language'); - db_change_field($new_table, 'language', 'langcode', $field_langcode); + db_drop_field($new_table, 'entity_type'); + // Rename 'language' to 'langcode'. Tables created during the upgrade + // before this update function might already have the langcode column. + if (db_field_exists($new_table, 'language')) { + db_drop_index($new_table, 'language'); + db_change_field($new_table, 'language', 'langcode', array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + )); + db_add_index($new_table, 'langcode', array('langcode')); + } + // Create new primary key. db_add_primary_key($new_table, $table_data['primary_key']); - db_add_index($new_table, 'langcode', $langcode_index); } } diff --git a/core/modules/file/file.install b/core/modules/file/file.install index db307b9..bce7aee 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -248,10 +248,10 @@ function file_update_dependencies() { 'file' => 8001, ); - // Convert the 'fid' column of file fields to 'target_id' after fields and - // instances have been moved to the config system. + // Convert the 'fid' column of file fields to 'target_id' after the field + // tables have been reorganized. $dependencies['file'][8003] = array( - 'field' => 8003, + 'field' => 8006, ); return $dependencies; } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php index 27fa88b..22ce7f9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php @@ -219,6 +219,7 @@ function testFieldUpgradeToConfig() { $field_entity = new Field($deleted_field); $table_name = DatabaseStorageController::_fieldTableName($field_entity); $this->assertEqual("field_deleted_data_" . substr(hash('sha256', $deleted_field['uuid']), 0, 10), $table_name); + $this->assertTrue(db_table_exists($table_name)); // Check that creation of a new node works as expected. $value = $this->randomName(); diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 421fe92..1de9d59 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -204,14 +204,10 @@ function taxonomy_field_schema($field) { */ function taxonomy_update_dependencies() { // Convert the 'tid' column of the taxonomy reference field to 'target_id' - // after fields and instances have been moved to the config system... + // after the field tables have been reorganized. $dependencies['taxonomy'][8007] = array( 'field' => 8003, ); - // ... but before the field storage tables are split. - $dependencies['field'][8006] = array( - 'taxonomy' => 8007, - ); return $dependencies; } @@ -366,15 +362,15 @@ function taxonomy_update_8007() { $field_config = config($config_name); // Only update taxonomy reference fields that use the default SQL storage. if ($field_config->get('type') == 'taxonomy_term_reference') { - $field_name = $field_config->get('name'); + $field = new Field($field_config->get()); $tables = array( - 'field_data_' . $field_name, - 'field_revision_' . $field_name, + DatabaseStorageController::_fieldTableName($field), + DatabaseStorageController::_fieldRevisionTableName($field), ); foreach ($tables as $table_name) { - db_change_field($table_name, $field_name . '_tid', $field_name . '_target_id', array( + db_change_field($table_name, $field->name . '_tid', $field->name . '_target_id', array( 'description' => 'The ID of the target entity.', 'type' => 'int', 'unsigned' => TRUE, @@ -382,8 +378,8 @@ function taxonomy_update_8007() { )); // Change the index. - db_drop_index($table_name, $field_name . '_tid'); - db_add_index($table_name, $field_name . '_target_id', array($field_name . '_target_id')); + db_drop_index($table_name, $field->name . '_tid'); + db_add_index($table_name, $field->name . '_target_id', array($field->name . '_target_id')); } // Update the indexes in field config as well.