Skip to content

GH-46: Syncdb with #42#50

Merged
zHelmet merged 10 commits into
GH-46from
bugfix/GH-46-syncdb
May 18, 2026
Merged

GH-46: Syncdb with #42#50
zHelmet merged 10 commits into
GH-46from
bugfix/GH-46-syncdb

Conversation

@zHelmet
Copy link
Copy Markdown
Contributor

@zHelmet zHelmet commented Mar 9, 2026

Overview

  • Use direct call for the docker to prevent In some rare occasions calling yq from ddev alias does something to params #42, and avoid using eval on any scripts to make it more secure
  • Add --skip-hooks option as used in ddev to provide way to manually enter deploy commands
  • Remove unnecessary confirmation prompts since the command is deliberately invoked by the user.
  • Ensure DDEV_APPROOT is set for any downstream consumers.

Remove unnecessary confirmation prompts since the command is deliberately invoked by the user. Build the import-db command as an array instead of using eval, and pass --skip-hooks flag through to ddev import-db when requested. Remove post-run hints that are redundant when hooks handle deployment steps.
@zHelmet zHelmet changed the title GH-46: Syncdb GH-46: Syncdb with #42 Mar 9, 2026
@zHelmet zHelmet marked this pull request as ready for review March 9, 2026 06:44
Copy link
Copy Markdown
Member

@tormi tormi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Santeri! I think I'll add --deploy hook in #47 next.


# Sanitize imported database (remove sensitive data).
drush sqlsan -y || { display_error_message "Database sanitization failed"; exit 1; }
drush deploy -y || { display_error_message "Drupal deploy failed"; exit 1; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be on by default. Let's introduce --deploy flag instead with drush deploy and drush uli included.

Copy link
Copy Markdown
Contributor Author

@zHelmet zHelmet Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the --skip-hooks these are not executed so no need for flag on it, i rather would keep this since on a normal workflow i want to have dev at the latest configs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

95% of time I also need to import configs and update db right after import so I would enable deploy by default too. In rare cases I need to debug production db locally, there's the --skip-hooks

Only thing against deploy is the the fact that it relies on drush version. It seems in rare cases running clear cache first can cause db errors and that's done in 12.x
https://www.drush.org/12.x/deploycommand/
In newer versions config import is first:
https://www.drush.org/14.x/deploycommand/

If we can't agree on this here, then maybe meeting is needed.

# --- 6. Read remote alias details from Drush ---
if ! alias_details=$(ddev drush sa "$SITE_ALIAS" 2>&1); then
# --- 5. Read remote alias details from Drush ---
if ! alias_details=$(ddev drush sa "$SITE_ALIAS" --format=yaml 2>&1); then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread wunderio/core/tooling/syncdb.sh Outdated
fi

# --- 4. Prepare dumps directory ---
# --- 3. Prepare dumps directory ---
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping a database should always be accompanied by a warning, I would keep it and the --force flag.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning is okay but extra steps for just to import is kinda tedious. If that would be needed i suggest you promote this feature to be added upstream to ddev

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's remove --force. I'll commit the change.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could still add warning right at the start of the command for people who are not familiar with this command or if somebody accidentally ran it. It could be in red. They still have time to cancel because db is removed after import is done.

@tormi @zHelmet

Comment thread wunderio/core/wdr-core.sh
PROJECT_ROOT="$PWD"
fi
# Ensure DDEV_APPROOT is set for any downstream consumers.
DDEV_APPROOT="$PROJECT_ROOT"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread README.md
ddev syncdb <alias> # e.g. ddev syncdb prod
ddev syncdb prod --backup # Back up local DB before overwriting
ddev syncdb prod --force # Skip confirmation prompt
ddev syncdb prod --skip-hooks # Skip ddev hooks
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

@tormi
Copy link
Copy Markdown
Member

tormi commented Mar 24, 2026

Thanks again for the work on this!

I still have concerns about the --skip-hooks flag, including from a GDPR/data safety perspective.

The issue

--skip-hooks bypasses both drush sqlsan AND drush deploy. This means developers can accidentally import production data with real PII (Personally Identifiable Information):

ddev syncdb prod --skip-hooks  # No sanitization!

The local database would then contain:

  • Real customer emails and names (users_field_data)
  • Session tokens (potential for session hijacking)
  • Form submissions with contact details
  • Any custom PII fields

If a developer's laptop is lost, stolen, or compromised - that's a GDPR violation.

Additionally, the current approach doesn't support a common use case: running sanitization WITHOUT deployment. With --skip-hooks, it's all-or-nothing - you either get both sqlsan + deploy, or neither.

Safer alternative

This PR is based on my GH-46 branch (PR #47), which intentionally takes a different approach:

Aspect This PR #50 (--skip-hooks) PR #47 GH-46 (--deploy)
Sanitization Opt-out (risky) Always runs via DDEV hooks
Deployment Opt-out Opt-in with --deploy
Sanitize without deploy Not possible Default behavior
GDPR safety Developer must remember Safe by default
# PR #47 (GH-46) approach
ddev syncdb prod           # imports + sanitizes (safe default, no deploy)
ddev syncdb prod --deploy  # imports + sanitizes + deploys

Suggestion

Could we consider merging the improvements from this PR (alias parsing, error handling) back into PR #47, but:

  1. Remove --skip-hooks from syncdb
  2. Keep --deploy as opt-in

Happy to discuss further!

@zHelmet
Copy link
Copy Markdown
Contributor Author

zHelmet commented Mar 24, 2026

Remove --skip-hooks from syncdb

Skip hooks has much higher value since there even might be some project specific hooks to run which are not always wanted. I would rather take this another way. Add sanitation into syncdb script and keep the --skip-hooks

@tormi
Copy link
Copy Markdown
Member

tormi commented Mar 24, 2026

So --skip-hooks would just be a ddev flag without any custom logic? 👍 then.

@zHelmet zHelmet merged commit 39f0e36 into GH-46 May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants