Issue #2999586 by interX, andypost, mondrake: Properly deprecate db_add_index
parent
061c632f3c
commit
2a4fa156c4
|
@ -972,7 +972,8 @@ function db_drop_unique_key($table, $name) {
|
|||
* @see \Drupal\Core\Database\Schema::addIndex()
|
||||
*/
|
||||
function db_add_index($table, $name, $fields, array $spec) {
|
||||
return Database::getConnection()->schema()->addIndex($table, $name, $fields, $spec);
|
||||
@trigger_error('db_add_index() is deprecated in Drupal 8.0.x and will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addIndex() on it. For example, $injected_database->schema()->addIndex($table, $name, $fields, $spec). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
|
||||
Database::getConnection()->schema()->addIndex($table, $name, $fields, $spec);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* Update hooks and schema definition for the update_test_schema module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*
|
||||
|
@ -44,7 +46,7 @@ if ($schema_version >= 8001) {
|
|||
];
|
||||
|
||||
// Add a column.
|
||||
db_add_index('update_test_schema_table', 'test', ['a'], $table);
|
||||
Database::getConnection()->schema()->addIndex('update_test_schema_table', 'test', ['a'], $table);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -426,4 +426,24 @@ class DatabaseLegacyTest extends DatabaseTestBase {
|
|||
$this->assertSame(3, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deprecation of the db_add_index() function.
|
||||
*
|
||||
* @expectedDeprecation db_add_index() is deprecated in Drupal 8.0.x and will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addIndex() on it. For example, $injected_database->schema()->addIndex($table, $name, $fields, $spec). See https://www.drupal.org/node/2993033
|
||||
*/
|
||||
public function testDbAddIndex() {
|
||||
$table_specification = [
|
||||
'fields' => [
|
||||
'age' => [
|
||||
'description' => "The person's age",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertNull(db_add_index('test', 'test', ['age'], $table_specification));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue