Database Refreshing Pattern in Drupal 8 – Testing Config Changes
I’ve been working on some Drupal 8 migration work. Given that most of the work I’m doing takes place in “config” I have to keep refreshing/reinstalling the config on my site. For a long time I would use Configuration Installer to pull in the changes I’ve made before repeatedly testing the migrations. The pattern is: Develop, overwrite config, test, develop, overwrite config, test.
Just recently, weeks into the migration work, I realized that there are certain things that aren’t working properly unless I do a full uninstall/reinstall of my custom migrate module, and then even still there are certain things that migrate holds onto that were causing my testing to be unpredictable. As a result I’ve moved back to the trusty pattern of “resetting” the entire database (pre-migration) between checks. I recognize that this won’t work if you have a huge database, but the set of commands takes less than 20 seconds to run on my machine, so it’s hardly an issue.
This would work for any Drupal development where you have to keep testing changes repeatedly. The simple approach is to get the database to where you want it (before the change you want to repeatedly test) and take a snapshot, then use this snapshot over and over again. It sounds really simple right? That’s because it is; there’s nothing new or earth-shattering here, folks.
Here are the commands with notes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#### PREPARE THE REPEATED-REFRESH STARTING POINT #### # Drop the database locally drush sql-drop -y # Grab remote copy of DB from system of record # Database already at a good starting point? Skip this step. drush sql-sync @myremotesite.dev @self -y # Log into Drupal before we dump the DB so that each time we restore the DB we stay logged in # Dump the local DB to a local file drush sql-dump --structure-tables-key=common > ~/db_snapshots/mysite-latest.sql #### THE PATTERN #### # STEP 1: Do development # STEP 2: Refresh the entire system and pull in new config # You could combine all of these into a one liner (; or && separators) drush sql-drop -y drush sql-cli < ~/db_snapshots/mysite-latest.sql -y drush config-import --partial --source=modules/custom/mymodule/config/install -y # STEP 3: # Test, continue development, and repeat |