Skip to content

stash db commands fail with cryptic error when DATABASE_URL is not exported #376

@coderdan

Description

@coderdan

Symptom

Running any DB-touching command without DATABASE_URL exported in the shell (or already in a loaded .env* file) fails with:

Error: Invalid stash.config.ts
  - databaseUrl: Invalid input: expected nonoptional, received undefined

The error is misleading — stash.config.ts correctly references process.env.DATABASE_URL. The real problem is that the CLI has no fallback chain when env is empty: no --database-url flag, no Supabase auto-discovery, no interactive prompt.

Affects

  • stash db install
  • stash db push
  • stash db upgrade
  • stash db status
  • stash db validate
  • stash db test-connection
  • stash schema build

Common ways users specify DB URLs that we don't currently handle

  • --database-url <url> flag (not implemented).
  • mise.toml / direnv / shell exports — covered if they populate process.env.DATABASE_URL before the CLI runs, but no graceful failure mode otherwise.
  • Local Supabase via supabase status — not auto-discovered.
  • "I have the URL handy, just let me paste it" — no interactive fallback.

Fix

Add a layered resolver that walks: flag → env → supabase status (when the project looks like Supabase) → interactive prompt → fail with a clear source-naming error. Resolved URL is populated into process.env.DATABASE_URL in-process; the stash.config.ts template stays a declarative env reference (no secrets written to disk). The source is logged so users know where the URL came from.

After a prompt-sourced run, the CLI nudges the user to set DATABASE_URL in their existing dotenv file so they don't get re-prompted.

Skipped sources fall through silently (e.g. supabase binary missing). CI=true and non-TTY stdin both skip the prompt and fail fast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions