Drush Help and sql-sanitize
So, 2 very overlooked commands in Drush that I’ve needed to use for a project recently.
First off, drush help which allows you to get a man page about a command in drush.
example: drush help sql-sanitize
this returns a bunch of information about the drush command that you’re asking for. It lists the parameters you can pass in and other useful information. It’s also even quicker than opening Chrome and googling ‘how do I use sql-sanatize’
To start - a HUGE warning. DO NOT run this on a production or live server. The whole purpose of this is to sanitise the the data - i.e. wiping out the passwords, email addresses, and - with some magic - any field that might contain personal data. The purpose of the command is to protect private information and it’s not reversible.
So, now you know the risks... here’s how to use it!
in its simplest form, running drush sql-sanitize in a drupal directory will prompt you to enter ‘y’ to replace all the passwords with the word ‘password’ and change all the email addresses to be [email protected].
This is probably all you need. I mean, if you’re feeling lucky you can add -y to that command so it’ll do it without prompting (probably keep that one for a jenkins job though I reckon)
Drush sql-sanitize on steroids:
So, you could run this command to personalise things a bit:
drush sql-sanitize --sanitize-email="fakeemail+%uid@localhost" --sanitize-password="test123" -y
this changes the email addresses of all the users to be fakeemail+their_user_id_number@localhost and changes their password to be test123 (and due to the -y does it without prompting... hence never get this ANYWHERE NEAR production... like, EVER...)
You can extend this even further by using hook_drush_sql_sync_sanitize to update other fields such as twitter accounts, linked in etc. There’s a great how to on this here: https://www.codeenigma.com/support/blog/doing-more-drush-sql-sanitize