Logging in to databases

If you’re a developer and need to do something in a database you’ll need to have the SpaceDeveloper permissions in the relevant space. If you have that permission and psql in your system’s path, then (perhaps) the easiest way to log in to a database is using the CloudFoundry plugin conduit (developed by the GDS PaaS team exactly for this purpose) to make the connection.

If this is the first time you’ve done this you’ll need to install the plugin first:

cf install-plugin conduit

The same command can be used to install any available updates for the plugin.

Once the plugin is installed make sure you’re in the right space and then use conduit to connect:

cf login
cf target -s preview
cf conduit digitalmarketplace_api_db -- psql

It is also possible to log in to an application’s database without conduit by making an ssh tunnel “through” the application using cf ssh’s -L option and using the credentials found in the app’s VCAP_SERVICES.

Resetting brief data with conduit

The functional tests require briefs with ‘closed’ status to be available on Preview and Staging. The tests cannot create ‘closed’ briefs themselves and rely on them being present in the cleaned data dump. Occasionally the data will need resetting, as all the closed briefs have been marked as ‘cancelled’, ‘awarded’ or ‘unsuccessful’ by the functional tests.

The ideal solution is to refresh the database using the Clean and apply database dump Jenkins job. This will take around an hour, so if you need a quicker solution (e.g. to unblock a release) you can use conduit to reset briefs:

cf login
cf target -s preview
cf conduit digitalmarketplace_api_db -- psql
=> UPDATE briefs set cancelled_at = NULL where cancelled_at IS NOT NULL;
=> \q


Double check you are NOT in the production environment before running this command!