Database Studio with Fly.io
Last checked with Wasp 0.24 and Fly CLI 0.4.11.
This guide depends on external libraries or services, so it may become outdated over time. We do our best to keep it up to date, but make sure to check their documentation for any changes.This guide shows you how to connect to your production database on Fly.io and run wasp db studio to inspect or modify your data.
You are about to point your local tooling at the live production database. Make sure to understand the Security Considerations before proceeding.
Prerequisites
Overview
To connect to your production database, you'll need to:
- Get the database name
- Get the database password
- Open a tunnel to the database
- Configure your local environment
- Run
wasp db studio
Step 1: Get the Database Name
Connect to your Postgres app (replace some-test-db with your actual database app name):
fly postgres connect -a some-test-db
Once connected, list all databases:
\l
Your database name will typically follow the pattern server_name_with_underscores. For example, if your server app is named some-test-server, the database name would be some_test_server.
Type \q to exit the Postgres prompt.
Step 2: Get the Database Password
SSH into your database app:
fly ssh console -a some-test-db
Then retrieve the password:
echo $OPERATOR_PASSWORD
Copy this password and type exit to leave the SSH session.
Step 3: Open a Database Tunnel
Stop wasp start first. It runs the development database on port 5432, which the tunnel needs, and after Step 4 your local server would connect to the production database.
The tunnel below needs local port 5432 to be free. Stop any other database or process using that port.
Open the tunnel:
fly proxy 5432 -a some-test-db
Keep this terminal tab open and use a new terminal for the following steps.
Step 4: Configure the Database URL
Edit your .env.server file to point to the production database:
DATABASE_URL=postgres://postgres:<password>@localhost:5432/<db_name>
Replace <password> with the password from Step 2 and <db_name> with the database name from Step 1.
For example:
DATABASE_URL=postgres://postgres:myDatabasePassword@localhost:5432/some_test_server
Step 5: Run Database Studio
Now you can run Prisma Studio to browse and edit your production data:
wasp db studio
This will open a web interface where you can view and modify your database records.
Security Considerations
- Any changes you make to production data are immediate and may be hard or impossible to undo
- Back up your database before making changes
- Consider using a read-only user for routine inspections
- Remember to restore your
.env.serverto point to your local database when you're done - Close the tunnel when finished by terminating the
fly proxycommand - Never commit production credentials to version control