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:
cloud auth - authenticated
cloud ship - app created, environment created, database cluster + schema provisioned automatically
- Deploy failed because
DB_CONNECTION defaulted to sqlite
- Set
DB_CONNECTION=pgsql via cloud environment:variables --action=set
- Deploy failed again:
connection to server at "127.0.0.1", port 5432 failed: Connection refused
- 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
- 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
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 shiporcloud 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 theDB_HOST,DB_PORT,DB_USERNAME,DB_PASSWORD, andDB_DATABASEvariables 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:
cloud auth- authenticatedcloud ship- app created, environment created, database cluster + schema provisioned automaticallyDB_CONNECTIONdefaulted tosqliteDB_CONNECTION=pgsqlviacloud environment:variables --action=setconnection to server at "127.0.0.1", port 5432 failed: Connection refuseddatabase-cluster:list --jsonand setDB_HOST,DB_PORT,DB_USERNAME,DB_PASSWORD,DB_DATABASEindividuallyThe entire flow should have been:
cloud database:attach <database-id> <environment-id>and Cloud handles the injection, exactly like the dashboard does.Proposed commands
Why this matters
cloud shipcreates the database but doesn't attach it to the environment, so the deploy immediately fails.DB_HOST/DB_PASSWORDas 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