Repository navigation
feat(config): read staging's DB from DATABASE_URL__STAGING when present - #509
Merged
Merged
Conversation
A MyKinsta restore of a live backup copies production's shared/.env onto staging, which then points at production's database credentials while staging has a database of its own. With DATABASE_URL__STAGING kept in both environments' .env, staging (detected by hostname) still finds its own. Ref generoi/arter#172. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fleet rollout of https://github.com/generoi/arter/pull/172 into the template, so new sites start with it: staging keeps working after a MyKinsta restore of a live backup.
Problem
A restore copies production's files to staging, including
shared/.env. Staging then has production's DB credentials, but Kinsta gave staging a database of its own, so every request (and the staging deploy'swp:update) fails with "Error establishing a database connection".Change
On staging,
DATABASE_URL__STAGINGreplacesDATABASE_URLentirely and goes through the same parser. Keep staging's URL in both environments'shared/.env; a restore then brings it along with everything else.\bstaging\bingethostname()), not by.env, so production's.envmust not setWP_ENVIRONMENT_TYPE. Check that before adding the variable.DATABASE_URL/DB_*as before.DATABASE_URLrule still applies: a password containing@,:or/won't parse.Tested by loading
config/application.phpwith fake env values:.envhasDB_*+ staging URLDB_*+ staging URLDB_*DB_*onlyDB_*Using it on a site
Add
DATABASE_URL__STAGING=mysql://<user>:<pass>@localhost/<db>(from MyKinsta → staging → Database access) to both production's and staging'sshared/.env.Open question: if Kinsta regenerates staging's DB credentials on every restore (not only when staging is recreated), the stored URL goes stale and this doesn't help. A test restore on a site answers that.
The harness ran against another repo's
vendor/, because this one's lock wants PHP 8.5 and the host has 8.4; the file only needs roots/wp-config, oscarotero/env and vlucas/phpdotenv to load. Pint passes and the pre-commit hook ran.🤖 Generated with Claude Code