Issue #2999588 by mondrake, longwave, voleger: Properly deprecate db_index_exists
parent
82e7ad802a
commit
5e582a62c4
|
@ -650,6 +650,7 @@ function db_field_names($fields) {
|
|||
* @see \Drupal\Core\Database\Schema::indexExists()
|
||||
*/
|
||||
function db_index_exists($table, $name) {
|
||||
@trigger_error('db_index_exists() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call indexExists() on it. For example, $injected_database->schema()->indexExists($table, $name). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
|
||||
return Database::getConnection()->schema()->indexExists($table, $name);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\system\Functional\Entity\Update;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
|
@ -25,19 +26,21 @@ class SqlContentEntityStorageSchemaIndexTest extends UpdatePathTestBase {
|
|||
* Tests entity and field schema database updates and execution order.
|
||||
*/
|
||||
public function testIndex() {
|
||||
$schema = Database::getConnection()->schema();
|
||||
|
||||
// The initial Drupal 8 database dump before any updates does not include
|
||||
// the entity ID in the entity field data table indices that were added in
|
||||
// https://www.drupal.org/node/2261669.
|
||||
$this->assertTrue(db_index_exists('node_field_data', 'node__default_langcode'), 'Index node__default_langcode exists prior to running updates.');
|
||||
$this->assertFalse(db_index_exists('node_field_data', 'node__id__default_langcode__langcode'), 'Index node__id__default_langcode__langcode does not exist prior to running updates.');
|
||||
$this->assertFalse(db_index_exists('users_field_data', 'user__id__default_langcode__langcode'), 'Index users__id__default_langcode__langcode does not exist prior to running updates.');
|
||||
$this->assertTrue($schema->indexExists('node_field_data', 'node__default_langcode'), 'Index node__default_langcode exists prior to running updates.');
|
||||
$this->assertFalse($schema->indexExists('node_field_data', 'node__id__default_langcode__langcode'), 'Index node__id__default_langcode__langcode does not exist prior to running updates.');
|
||||
$this->assertFalse($schema->indexExists('users_field_data', 'user__id__default_langcode__langcode'), 'Index users__id__default_langcode__langcode does not exist prior to running updates.');
|
||||
|
||||
// Running database updates should update the entity schemata to add the
|
||||
// indices from https://www.drupal.org/node/2261669.
|
||||
$this->runUpdates();
|
||||
$this->assertFalse(db_index_exists('node_field_data', 'node__default_langcode'), 'Index node__default_langcode properly removed.');
|
||||
$this->assertTrue(db_index_exists('node_field_data', 'node__id__default_langcode__langcode'), 'Index node__id__default_langcode__langcode properly created on the node_field_data table.');
|
||||
$this->assertTrue(db_index_exists('users_field_data', 'user__id__default_langcode__langcode'), 'Index users__id__default_langcode__langcode properly created on the user_field_data table.');
|
||||
$this->assertFalse($schema->indexExists('node_field_data', 'node__default_langcode'), 'Index node__default_langcode properly removed.');
|
||||
$this->assertTrue($schema->indexExists('node_field_data', 'node__id__default_langcode__langcode'), 'Index node__id__default_langcode__langcode properly created on the node_field_data table.');
|
||||
$this->assertTrue($schema->indexExists('users_field_data', 'user__id__default_langcode__langcode'), 'Index users__id__default_langcode__langcode properly created on the user_field_data table.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\system\Functional\Update;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
|
@ -44,9 +45,11 @@ class UpdateSchemaTest extends BrowserTestBase {
|
|||
* Tests that update hooks are properly run.
|
||||
*/
|
||||
public function testUpdateHooks() {
|
||||
$connection = Database::getConnection();
|
||||
|
||||
// Verify that the 8000 schema is in place.
|
||||
$this->assertEqual(drupal_get_installed_schema_version('update_test_schema'), 8000);
|
||||
$this->assertFalse(db_index_exists('update_test_schema_table', 'test'), 'Version 8000 of the update_test_schema module is installed.');
|
||||
$this->assertFalse($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8000 of the update_test_schema module is installed.');
|
||||
|
||||
// Increment the schema version.
|
||||
\Drupal::state()->set('update_test_schema_version', 8001);
|
||||
|
@ -62,7 +65,7 @@ class UpdateSchemaTest extends BrowserTestBase {
|
|||
// Ensure schema has changed.
|
||||
$this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
|
||||
// Ensure the index was added for column a.
|
||||
$this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
|
||||
$this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\FunctionalTests\Update;
|
|||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* Tests the update path base class.
|
||||
|
@ -75,11 +76,13 @@ class UpdatePathTestBaseTest extends UpdatePathTestBase {
|
|||
* Test that updates are properly run.
|
||||
*/
|
||||
public function testUpdateHookN() {
|
||||
$connection = Database::getConnection();
|
||||
|
||||
// Increment the schema version.
|
||||
\Drupal::state()->set('update_test_schema_version', 8001);
|
||||
$this->runUpdates();
|
||||
|
||||
$select = \Drupal::database()->select('watchdog');
|
||||
$select = $connection->select('watchdog');
|
||||
$select->orderBy('wid', 'DESC');
|
||||
$select->range(0, 5);
|
||||
$select->fields('watchdog', ['message']);
|
||||
|
@ -92,7 +95,7 @@ class UpdatePathTestBaseTest extends UpdatePathTestBase {
|
|||
// Ensure schema has changed.
|
||||
$this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
|
||||
// Ensure the index was added for column a.
|
||||
$this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
|
||||
$this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -322,6 +322,15 @@ class DatabaseLegacyTest extends DatabaseTestBase {
|
|||
$this->assertFalse(db_drop_index('test', 'no_such_index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deprecation of the db_index_exists() function.
|
||||
*
|
||||
* @expectedDeprecation db_index_exists() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call indexExists() on it. For example, $injected_database->schema()->indexExists($table, $name). See https://www.drupal.org/node/2993033
|
||||
*/
|
||||
public function testDbIndexExists() {
|
||||
$this->assertFalse(db_index_exists('test', 'no_such_index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deprecation of the db_drop_unique_key() function.
|
||||
*
|
||||
|
|
|
@ -50,11 +50,11 @@ class RegressionTest extends DatabaseTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests the db_index_exists() function.
|
||||
* Tests the Schema::indexExists() method.
|
||||
*/
|
||||
public function testDBIndexExists() {
|
||||
$this->assertSame(TRUE, db_index_exists('test', 'ages'), 'Returns true for existent index.');
|
||||
$this->assertSame(FALSE, db_index_exists('test', 'nosuchindex'), 'Returns false for nonexistent index.');
|
||||
$this->assertSame(TRUE, $this->connection->schema()->indexExists('test', 'ages'), 'Returns true for existent index.');
|
||||
$this->assertSame(FALSE, $this->connection->schema()->indexExists('test', 'nosuchindex'), 'Returns false for nonexistent index.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue