Skip to content

Support for specifying database URLs per test via an environment variable option in sqlx::test macro #3947

@simple-random

Description

@simple-random

I have found these related issues/pull requests

Relates to issues #2220, #3022

Description

sqlx::test currently relies on a hardcoded DATABASE_URL environment variable as the database URL to which connections are made when spinning up isolated test databases. However, I am working on an application that stores multiple database URLs in separate environment variables, each database having a separate set of migrations to be run.

Preferred solution

It would be useful to have a db_env_var option on the #[sqlx::test] macro that allows specifying which environment variable to use for the database URL for each test, defaulting to DATABASE_URL if not specified:

#[sqlx::test(db_env_var = "SOME_DATABASE_URL")]
async fn some_test(pool: PgPool) {
    // test code goes here
}

Is this a breaking change? Why or why not?

This should not be a breaking change, since sqlx::test without an explicit db_env_var would continue to default to DATABASE_URL as it does in the current implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions