Migrated data from rabbit_hole_update_8106 is lost when running drush deploy

Created on 23 May 2025, 14 days ago

Problem/Motivation

The drush deploy command is an effort to standardize how Drupal deployments work. It's effectively a wrapper around the following commands:

drush updatedb --no-cache-clear
drush cache:rebuild
drush config:import
drush cache:rebuild
drush deploy:hook

When I update rabbit_hole to 2.0.0-beta1, push this update to production and run drush deploy, I end up with all data from the previous base fields lost.

Steps to reproduce

On my local environment, I ran the update hooks, exported and committed the new config. The updated dependencies and exported config are then pushed to the production environment and drush deploy is run after. The new fields are then created and filled during drush updatedb --no-cache-clear, after which drush config:import runs. That deletes the previously created rabbit_hole__settings fields and recreates them. This happens because the config UUIDs of the exported fields are different from the ones created during the update hook. Apart from that, the config is identical.

Proposed resolution

Change rabbit_hole_update_8106 to be a post update hook. These are intended for updating data. In normal update hooks you're not supposed to do that, these are more about updating config.

When we do that, the fields are still recreated during drush config:import but that doesn't matter since the data is only migrated afterwards.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇧🇪Belgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dieterholvoet
  • 🇧🇪Belgium dieterholvoet Brussels

    Never mind, I was wrong. Post update hooks also run before config import. Only deploy hooks run after config import, but those are a Drush specific concept so probably not a good idea to introduce here. The alternative is to make sure the fields aren't recreated, so no data is lost. I'll try to come up with a solution.

  • 🇧🇪Belgium dieterholvoet Brussels

    Update hooks updating data should still be post update hooks though, so I'll leave that in the MR.

  • Pipeline finished with Failed
    14 days ago
    Total: 408s
    #504616
  • 🇧🇪Belgium dieterholvoet Brussels

    The alternative is to make sure the fields aren't recreated, so no data is lost.

    Yeah, there doesn't seem to be a way to do that. updatedb creates and fills the fields and config:import overwrites them. The only way I can think about is to add a rabbit_hole_field_config_insert() hook and migrate the field there, after it's created. Not sure if we can use the Batch API at that point though.

    For my own purposes, I'm going to create a separate MR that makes this a deploy hook. It's a relatively easy and sufficient fix for people using Drush.

  • Pipeline finished with Failed
    14 days ago
    Total: 338s
    #504623
  • 🇧🇪Belgium dieterholvoet Brussels

    I can confirm that the deploy hook in MR !86 does the job, but like I said before only for people using drush deploy.

  • Pipeline finished with Failed
    14 days ago
    Total: 349s
    #504657
  • Pipeline finished with Failed
    14 days ago
    Total: 414s
    #504711
  • 🇦🇺Australia jannakha Brisbane!

    The issue can be that drush deploy assumes up to date configuration (it's for deployment only) as it doesn't run config:export after updatedb, if there are any schema changes the old updatedb will update the schema, but config:import will import old schema in - that might create issues, like missing config, etc

    Follow steps in Deployment of a new feature with configuration management - note actions on LOCAL ENVIRONMENT before running drush deploy on server.

  • 🇧🇪Belgium dieterholvoet Brussels

    I'm aware of that, that's not the problem here. I described those steps in 'Steps to reproduce'.

Production build 0.71.5 2024