-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #000: Adding Site Schema test. #184
Issue #000: Adding Site Schema test. #184
Conversation
drupal:export: | ||
desc: The opposite of drupal:update, exports the site's configuration and schema to code. | ||
cmds: | ||
- composer update --lock | ||
- ./vendor/bin/drush {{.site}} --yes cache:clear plugin | ||
- ./vendor/bin/drush {{.site}} --yes updatedb --no-cache-clear | ||
- ./vendor/bin/drush {{.site}} --yes cache:rebuild | ||
- ./vendor/bin/drush {{.site}} --yes config:export | ||
- task: site-schema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused about how this task would be used as it seems to run some of the update process - do you have an example workflow that it would be used in please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the documentation from another project where this has been integrated.
Site-schema check
This check is based on https://github.com/eiriksm/drush-site-schema , and is intended to verify if the site-schema.yml file is up-to-date with the information from the database. When there is a mismatch, this can be an indicator that DB updates weren't executed or their changes might not be accurately captured in version control.
In order to fix failures from this check, devs are expected to make sure the command:
lando drush @[SITE].local site-schema --format=yaml > site-schema.yml
is executed whenever there is a code change that includes new DB update hooks.
This means executing the command and committing the changes:
After installing a new module (core, contrib, or custom)
After [updating Drupal code]
Note: This check needs a bootstrappable site to check against, and in order to avoid having to build the full stack only for this check, this is executed as part of the "Functional phpunit tests" job in CircleCI, after the environment is ready, and before running the PHPUnit tests.
It was introduced so that any time an update hook occurs that there's a manual check to see if there are configuration changes that could potentially be reverted back to a default state. When an update hook is run and a developer confirms there is or is not any new configuration they would update the site-schema.yml file so it matches the update hook number in the module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexis-saransig-lullabot the command you have listed here just exports the site-schema which makes sense for the task drupal:export
integration.
What's missing is the schema check which should happen on each PR.
Here's the code we have running on the other project where this is being used.
- run:
name: Check that the site-schema file is up-to-date
command: '/var/www/html/scripts/check-site-schema.sh @test.ci'
Here is the contents of that file
#!/bin/bash
cd /var/www/html || exit
if [[ -z "$1" ]]; then
echo "This script needs a site alias to run.";
exit 42;
else
SITE_ALIAS=$1;
fi
# We need an already-committed schema to begin with.
if [ ! -f "site-schema.yml" ]; then
echo "The site-schema.yml file does not exist. Aborting."
exit 42;
fi
# Export the current schema from DB into a new file.
./vendor/bin/drush "$SITE_ALIAS" site-schema --format=yaml > site-schema-db.yml
# Compare the two.
echo "Comparing site-schema between DB and exported file."
diff -C 5 site-schema.yml site-schema-db.yml > diff.txt
if [ -s diff.txt ]; then
echo "There are differences between the schema in DB and in the site-schema file. Did you update code without exporting config and/or updating the schema file?"
echo "Differences:"
cat diff.txt
exit 42
else
echo "No differences found between DB and the site-schema file."
fi
We discussed this today and opened this as a follow up: #529 - so closing this PR for now |
Adds Site Schema testing.
Link: https://github.com/eiriksm/drush-site-schema