1

drush config:import has the --source flag to specify where the import should come from. drush config:export has the --destination flag to specify where the import should go.

I am trying to automate a system for determining if update hooks have modified configuration, to avoid the problem documented in #3110362 If an update hook modifies configuration, then old configuration is imported, the changes made by the update hook are forever lost.

To do so I will export the config to a temporary directory, like:

drush config:export --destination=/tmp/check-issue-3110362

Then I will run the updates

drush updb -y

Then I want to run a diff between the database config and the config in /tmp/check-issue-3110362, but the following does not work:

drush config:status --source=/tmp/check-issue-3110362
# The "--source" option does not exist. 
drush config:status --destination=/tmp/check-issue-3110362
# The "--destination" option does not exist. 

How can I tell drush config:status to use a specific directory to check against the database?

My version of Drush is 10.3.6

2 Answers 2

2

You can use the config:export command with the --no parameter to prevent the actual export.

drush config:export --destination=/tmp/check-issue-3110362 --diff --no

The return value $? of Drush will tell you if there are differences between the database and the directory containing YAML files:

  • 0 means no differences
  • 1 means differences

Therefore, you can combine this into an if statement:

if ! drush config:export --destination=/tmp/check-issue-3110362 --no; then
  # Act on the change here.
  echo "Something in the config was changed."
fi
1

There's no option to do this with drush config:status. See the drush 10 documentation for config:status.

Presumably, you want to check if the config has changed so you can export it to your sync directories. Why not export it to them directly? If there are no changes, there will be no changes. But if there are changes, you'll see them in your repository, e.g. with git status.

I've always used Moshe's recommendation from comment #7 in your linked issue:

You must get your configuration right before you run a config import. Specifically, the config in the import must represent the values AFTER hook_updated_n runs. The developer workflow I advocate is to run the hook_update_n() locally, run drush config:export, and and then commit the results. Only then is the saved config ready to be imported.

I.e., start with a site in a clean state in your local environment:

  1. Update your project(s) with composer.
  2. Run drush updb to perform the db updates
  3. Run drush cex to export any config changes made during those updates
  4. Add any changes to your repo, commit, and push.
  5. Pull the changes on your new environment
  6. Run drush deploy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.