I am introducing new configuration to an entity in Drupal that adds a few new boolean fields. The problem is, even though I set the default value as TRUE in the UI, this is only for new entities. Existing entities will have no value, or false, when evaluated in code.
I would like to script a change in that will default all existing entities to TRUE when the configuration is introduced for backwards compatibility, and only run it that one time.
Typical deployment scripts advise running updb first before cim with Drush. This creates a conflict when trying to attempt this.
Pantheon deployment script example:
if (isset($_ENV['PANTHEON_ENVIRONMENT'])) {
$status = 0;
$config_directory = dirname(__FILE__) . '/config/default';
passthru("drush updb --yes", $status);
passthru("drush cim --yes", $status);
passthru("drush cim --yes", $status);
passthru("drush cim --yes", $status);
passthru("drush updb --yes", $status);
passthru("drush cr", $status);
if ($status == 0) {
echo('Configuration imported and database updated.' . "\n");
} else {
echo('Configuration not imported / database not updated. Drush command returned an error.' . "\n");
}
}
Is there a better way to do changes like this that only run once without causing script like the one above to fail?