Issue #2994561 by andypost: Properly deprecate db_create_table
parent
36570233d8
commit
52100ba127
|
@ -589,6 +589,7 @@ function db_condition($conjunction) {
|
|||
* @see \Drupal\Core\Database\Schema::createTable()
|
||||
*/
|
||||
function db_create_table($name, $table) {
|
||||
@trigger_error('db_create_table() 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 createTable() on it. For example, $injected_database->schema()->createTable($name, $table). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
|
||||
return Database::getConnection()->schema()->createTable($name, $table);
|
||||
}
|
||||
|
||||
|
|
|
@ -151,4 +151,25 @@ class DatabaseLegacyTest extends DatabaseTestBase {
|
|||
$this->assertSame(['test_field'], db_field_names(['test_field']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deprecation of the db_create_table() function.
|
||||
*
|
||||
* @expectedDeprecation db_create_table() 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 createTable() on it. For example, $injected_database->schema()->createTable($name, $table). See https://www.drupal.org/node/2993033
|
||||
*/
|
||||
public function testDbCreateTable() {
|
||||
$name = 'test_create_table';
|
||||
$table = [
|
||||
'fields' => [
|
||||
'id' => [
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
];
|
||||
db_create_table($name, $table);
|
||||
$this->assertTrue($this->connection->schema()->tableExists($name));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ class TransactionTest extends DatabaseTestBase {
|
|||
],
|
||||
'primary key' => ['id'],
|
||||
];
|
||||
db_create_table('database_test_1', $table);
|
||||
$this->connection->schema()->createTable('database_test_1', $table);
|
||||
|
||||
$this->assertTrue($this->connection->inTransaction(), 'In transaction inside nested transaction.');
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ class TransactionTest extends DatabaseTestBase {
|
|||
],
|
||||
'primary key' => ['id'],
|
||||
];
|
||||
db_create_table('database_test_' . ++$count, $table);
|
||||
$this->connection->schema()->createTable('database_test_' . ++$count, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue