Skip to content

DATABASE_URL must be set for sqlx mig add #1391

Closed

Description

@jplatte

Not a big deal since I usually have DATABASE_URL in .env anyways, but I just noticed in a new project before creating .env that sqlx mig add init failed with

error: The DATABASE_URL environment variable must be set

Which there doesn't seem to be a good reason for.

Activity

  1. abonander commented on Aug 20, 2021

    @abonander
    Collaborator

    Yeah, it's purely because we're requiring it unconditionally: https://github.com/launchbadge/sqlx/blob/master/sqlx-cli/src/lib.rs#L18-L22

    clap has support for getting values from the environment, so we could move this to the Opt definitions, e.g.:

    #[derive(clap::Clap)]
    enum MigrateOpt {
        Add {
            #[clap(long, env)]
            database_url: String,
            // ...
        }
    }

    It'd just be a bit annoying to have to do this for every command.

    The error message that Clap generates if you omit DATABASE_URL isn't really helpful though as it defaults to suggesting it as --database-url=... and doesn't mention environment variables at all except in the output of --help.

  2. added
    cli
    good first issue
    on Aug 20, 2021
  3. xpe commented on Sep 7, 2021

    @xpe
    Contributor

    The commit made in this issue (0e51272) led to a regression (#1431) where a .env file isn't read in time for clap argument parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easycligood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions