Skip to content

Missing command: database:attach / database:detach to link databases to environments #130

@JoshSalway

Description

@JoshSalway

Problem

There is no CLI command (or API endpoint) to attach a database to an environment. This is currently only possible through the Cloud dashboard.

When deploying via CLI (cloud ship or cloud deploy), you can create a database cluster (database-cluster:create) and a database schema (database:create), but there is no way to attach that database to an environment so that Cloud injects the DB_HOST, DB_PORT, DB_USERNAME, DB_PASSWORD, and DB_DATABASE variables automatically.

Note

This was encountered while testing with a local development branch of the Cloud CLI (with various fixes and improvements), but the limitation is the same on the published CLI. The blocker is the REST API itself -- there is no attach/detach endpoint exposed, so no CLI (official or otherwise) can implement this functionality until the API supports it.

Real-world scenario

I was deploying a Laravel app to Cloud entirely via CLI:

  1. cloud auth - authenticated
  2. cloud ship - app created, environment created, database cluster + schema provisioned automatically
  3. Deploy failed because DB_CONNECTION defaulted to sqlite
  4. Set DB_CONNECTION=pgsql via cloud environment:variables --action=set
  5. Deploy failed again: connection to server at "127.0.0.1", port 5432 failed: Connection refused
  6. Had to manually look up the cluster connection details from database-cluster:list --json and set DB_HOST, DB_PORT, DB_USERNAME, DB_PASSWORD, DB_DATABASE individually
  7. Cloud warned about "overwriting 2 injected variables" because the database was attached via the dashboard previously but the env vars weren't being injected properly

The entire flow should have been: cloud database:attach <database-id> <environment-id> and Cloud handles the injection, exactly like the dashboard does.

Proposed commands

cloud database:attach <database> <environment>    # Attach a database to an environment
cloud database:detach <database> <environment>    # Detach a database from an environment

Why this matters

  • Full CLI deployment flow is broken without it. You can't go from zero to deployed app purely via CLI if your app needs a database (which is most apps).
  • CI/CD pipelines can't provision and wire up databases automatically.
  • cloud ship creates the database but doesn't attach it to the environment, so the deploy immediately fails.
  • Manual env var workaround is fragile. Hardcoding DB_HOST/DB_PASSWORD as env vars bypasses Cloud's injection system, conflicts with injected variables, and breaks if credentials rotate.

Blocked by API

This requires a new API endpoint. The current REST API has no attach/detach resource-to-environment endpoints. The CLI can implement the commands once the API supports it.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions