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
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
You'll need to get your database credentials: - For the database name, you can run: - For the password: 3. Now you can run Wasp CLI commands: or 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
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:
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:
You'll need to get your database credentials: - For the database name, you can run: - For the password: 3. Now you can run Wasp CLI commands: or 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:
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?Hey @mario.p did the bot answer your question?
I am not sure, I mean, wasp db studio will work with the suggested approach? I don't think so
Wohooo @mario.p, you just became a Waspeteer level 2!
yes it will. I do it all the time. are you using fly?
Nope, to be honest, never tried. Then I just need to try it. I will asap so
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 🙂
Thanks Vinny, I will!
@Vinny (@Wasp) it worked like a charm! Thank you 🙂
awesome. glad it worked !