W
Wasp•5d ago
mario.p

How to use wasp cli with a built project on a prod server?

Hi! I'm trying to release my first project with WASP on a staging server. I would like to understand how I can use the wasp cli with a built project. The idea is to be able to use the "wasp db" features mainly, such as the ability to seed or access "wasp db studio" even if it is not a recommended practice in production. I managed, obviously, to deploy everything using Docker, I can also install the wasp utility but rightly it does not find a wasp project to hook into. Do you have any ideas? Thanks!
9 Replies
kapa.ai
kapa.ai•5d ago
Hi @mario.p. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Using Wasp CLI with a Production Database Great question about using Wasp CLI tools with your deployed project! While the Wasp CLI is primarily designed for local development, there is a way to interact with your production database using tools like wasp db studio and wasp db seed. Connecting to Your Production Database The key approach is to create a tunnel to your production database and then point your local Wasp CLI to use that connection. Here's how you can do it with Fly.io (similar approaches would work for other providers): 1. Create a tunnel to your production database:
fly proxy 5432 -a <your-db-app-name>

fly proxy 5432 -a <your-db-app-name>

Leave this terminal running to keep the tunnel open Github Issue #1464. 2. Set up your local environment to use the production database: Create or modify your local .env.server file to include:
DATABASE_URL=postgres://<user>:<password>@localhost:5432/<db_name>

DATABASE_URL=postgres://<user>:<password>@localhost:5432/<db_name>


You'll need to get your database credentials: - For the database name, you can run:
fly postgres connect -a <your-db-app-name>
\l

fly postgres connect -a <your-db-app-name>
\l

- For the password:
fly ssh console -a <your-db-app-name>
echo $OPERATOR_PASSWORD

fly ssh console -a <your-db-app-name>
echo $OPERATOR_PASSWORD

3. Now you can run Wasp CLI commands:
wasp db studio

wasp db studio

or
wasp db seed <seed-name>

wasp db seed <seed-name>

Important Warnings - Be extremely careful when connecting to production databases! Always double-check what commands you're running. - Remember to remove the production DATABASE_URL from your .env.server file after you're done to avoid accidentally modifying your production database later Discord Support Thread. - This approach is meant for occasional administrative tasks, not regular development work. Alternative Approach You can also use the DATABASE_URL environment variable inline for one-off commands:
DATABASE_URL=<production-db-url> wasp db seed myProductionSeed
DATABASE_URL=<production-db-url> wasp db seed myProductionSeed
This is useful for seeding a fresh staging or production database Connecting to a Database. Remember that these approaches require you to have a local Wasp project with the same schema as your production app, but you're connecting it to your production database. I hope this helps with your staging deployment! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @mario.p, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Vinny (@Wasp)
Vinny (@Wasp)•5d ago
Hey @mario.p did the bot answer your question?
mario.p
mario.pOP•5d ago
I am not sure, I mean, wasp db studio will work with the suggested approach? I don't think so
MEE6
MEE6•5d ago
Wohooo @mario.p, you just became a Waspeteer level 2!
Vinny (@Wasp)
Vinny (@Wasp)•5d ago
yes it will. I do it all the time. are you using fly?
mario.p
mario.pOP•5d ago
Nope, to be honest, never tried. Then I just need to try it. I will asap so
Vinny (@Wasp)
Vinny (@Wasp)•5d ago
Cool. once you've deployed to FLY, you can follow those instructions above. Let me know if you have any questions after trying it out 🙂
mario.p
mario.pOP•5d ago
Thanks Vinny, I will! @Vinny (@Wasp) it worked like a charm! Thank you 🙂
Vinny (@Wasp)
Vinny (@Wasp)•5d ago
awesome. glad it worked !

Did you find this page helpful?