Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By mondrake on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.7.x
Introduced in version:
8.7.0
Issue links:
Description:
The Schema::fieldSetDefault
and Schema::fieldSetNoDefault
methods have been deprecated in favor of using Schema::changeField
method, in order to ensure more control to database schema changes.
While there is no current usage of the deprecated methods in core at the time of deprecation, its potential usage is most likely in update hooks, where it is now recommended to call changeField
passing in a full field (column) specification for the changes needed to the database schema.
Before:
...
$injected_database_connection->schema()->fieldSetDefault('mytable', 'field1', 0);
...
$injected_database_connection->schema()->fieldSetNoDefault('mytable', 'field2');
...
After:
...
$injected_database_connection->schema()->changeField('mytable', 'field1', 'field1', [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
]);
...
$injected_database_connection->schema()->changeField('mytable', 'field2', 'field2', [
'type' => 'int',
'not null' => TRUE,
]);
...
Impacts:
Module developers
Comments
Not a good reason for change
Why would the API be made more difficult to use on purpose? I have an update hook that needs to change the default value of fields containing existing data, and with this method it would be fine. Switching to use changeField will likely fall foul of the 'can't change tables with existing data' rule.
Can I also say: impacts on module/theme/etc devs should prevent change records being actioned until the work is complete - not half baked.