feat: support DATABASE_URL_TEST env var override in #[sqlx::test]#4312
Open
compiledbyutkarsh wants to merge 1 commit into
Open
feat: support DATABASE_URL_TEST env var override in #[sqlx::test]#4312compiledbyutkarsh wants to merge 1 commit into
compiledbyutkarsh wants to merge 1 commit into
Conversation
Allow #[sqlx::test] to use DATABASE_URL_TEST env var when set, falling back to DATABASE_URL if not present. This enables users to configure a dedicated test database user with elevated permissions (e.g. superuser for Postgres) while keeping production/dev credentials separate, following the principle of least privilege. Fixes transact-rs#4302
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.
Summary
Fixes #4302
Changes
sqlx-postgres/src/testing/mod.rs: Updated bothtest_contextandcleanup_test_dbsto checkDATABASE_URL_TESTfirst, falling back toDATABASE_URLsqlx-mysql/src/testing/mod.rs: Same change applied for MySQL testingMotivation
#[sqlx::test]requires a superuser connection to create/drop test databases. Many users want to keep their test credentials separate from development/production credentials following the principle of least privilege.With this change, users can set
DATABASE_URL_TESTto a superuser connection string for tests while keepingDATABASE_URLpointing to a restricted user for normal development.Behavior
DATABASE_URL_TESTis set, it is used for#[sqlx::test]DATABASE_URL_TESTis not set, falls back toDATABASE_URL(existing behavior preserved — no breaking change)Testing
Existing behavior is unchanged when
DATABASE_URL_TESTis not set. New behavior activates only whenDATABASE_URL_TESTis explicitly provided.