Problem/Motivation

As the db_change_field() method is deprecated, we should no longer use it in Drupal core.

Proposed resolution

Let's replace with \Drupal::database()->schema()->changeField().

Remaining tasks

  • Replace db_change_field() in documentation.
  • Replace db_change_field() with \Drupal::database()->schema()->changeField(); in code

Follow-up issue will be needed to inject the proper service after all the replacing is done.

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ieguskiza created an issue. See original summary.

ieguskiza’s picture

Status: Active » Needs review
FileSize
3.21 KB

Added first patch for revision.

ieguskiza’s picture

ieguskiza’s picture

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

cilefen’s picture

I am reparenting this to the meta of all things replacing db_

daffie’s picture

Status: Needs review » Needs work

Patch looks good, but I do have some remarks:

  1. +++ b/core/lib/Drupal/Core/Database/Schema.php
    @@ -518,9 +519,9 @@ public function fieldExists($table, $column) {
    +   * db_drop_{primary_key,unique_key,index}() before calling Schema::changeField().
    

    You cannot have more then 80 characters on a line with documentation.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
    @@ -129,7 +129,7 @@ function testSchema() {
    +    Database::getConnection()->schema()->changeField('test_table', 'test_serial', 'test_serial', array('type' => 'serial', 'not null' => TRUE, 'description' => 'Changed column description.'), array('primary key' => array('test_serial')));
    
    @@ -728,7 +728,7 @@ protected function assertFieldChange($old_spec, $new_spec, $test_data = NULL) {
    +    Database::getConnection()->schema()->changeField($table_name, 'test_field', 'test_field', $new_spec);
    

    Please use \Drupal::database() instead of Database::getConnection().

  3. +++ b/core/lib/Drupal/Core/Database/Schema.php
    @@ -535,7 +536,7 @@ public function fieldExists($table, $column) {
    +   * $injected_database->schema()->changeField('foo', 'bar', 'bar',
    

    Can we change this also to \Drupal::database()->schema()->changeField().

darkdim’s picture

Version: 8.4.x-dev » 8.3.x-dev
Assigned: ieguskiza » darkdim
Status: Needs work » Needs review
FileSize
3.34 KB

Changed

darkdim’s picture

darkdim’s picture

Fixed correction in #7 comment

cilefen’s picture

Version: 8.3.x-dev » 8.4.x-dev

This is probably not happening in 8.3 and note that we are trying to move doc changes to #2849745: Replace documentation recommending db_*() wrappers.

daffie’s picture

FileSize
1.41 KB

The patch is the same as the patch from comment #10, only without the documentation changes. Those will be done in #2849745: Replace documentation recommending db_*() wrappers.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All code changes are good.
All instances of the usage of db_drop_table() are replaced.
The patch looks good to me.
Because the patch was written by @darkdim, am I allowed to change the status to RTBC.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Thanks all. Those two usages are the self-tests of this function. So, this issue should maybe be closed as a duplicate of the docs one and whatever issue we file to look at the SchemaTest and other DB Kernel tests as a whole.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Assigned: darkdim » andypost

In #2848817-28: Replace all calls to db_table_exists, which is deprecated. I found one more test for refactoring

Actually docs issue is blocked on #2319859: [META] Deprecate contents of database.inc so here needs work to throw exception, working on it

andypost’s picture

Assigned: andypost » Unassigned
Status: Needs work » Needs review
FileSize
2.04 KB
3.43 KB

Kind of that should be enough

Status: Needs review » Needs work

The last submitted patch, 18: 2820179-18.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review
FileSize
480 bytes
3.59 KB

Maybe it makes sense to create a separate test class for all deprecated functions testing?

Anyway this needs to be annotated with @group legacy to test expected exceptions but this makes all patches with such deprecated to require reroll if one commited like #2848952-33: Replace all calls to db_merge(), which is deprecated

Status: Needs review » Needs work

The last submitted patch, 20: 2820179-20.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review
FileSize
1.26 KB
3.46 KB

As #2848812: Replace all calls to db_set_active, which is deprecated. better to annotate per method

Also fixed version

Status: Needs review » Needs work

The last submitted patch, 22: 2820179-db_change_field-22.patch, failed testing. View results

piggito’s picture

Status: Needs work » Needs review
FileSize
3.41 KB
1.06 KB

Fixed expectedDeprecation annotation

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Issue tags: +Needs reroll

Patch no longer applies.

Mile23’s picture

Status: Needs review » Needs work
voleger’s picture

mondrake’s picture

Title: [PP-2] Replace usages of deprecated method db_change_field() » Replace usages of deprecated method db_change_field()
Status: Postponed » Needs review
Issue tags: -Needs reroll

Here's a reroll + fixes to documentation.

We still miss a CR reference in the deprecation message. How about doing #2947946: Create change record for all deprecated db_* functions first and having a single Change Record with all the db* functions deprecated + directions on how to get the database connection being discussed in #2991337: Document the recommended ways to obtain the database connection object, instead of as many CRs as the deprecation issues?

mondrake’s picture

mondrake’s picture

FileSize
5.97 KB
2.39 KB

Added reference to CR https://www.drupal.org/node/2993033

I think this is done now?

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks it ready

The last submitted patch, 24: 2820179-db_change_field-24.patch, failed testing. View results

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed dcbb276 and pushed to 8.7.x. Thanks!

  • catch committed dcbb276 on 8.7.x
    Issue #2820179 by andypost, mondrake, darkdim, piggito, ieguskiza,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.