How do I seed production DB hosted on Fly
I want to seed my production database that is being hosted on Fly.io
I tried SSH'ing into the server and running
wasp db seed
but it says wasp command not found. Same thing if I SSH into the DB as well8 Replies
I also tried setting the DATABASE_URL locally in
.env.server
to the one given when deploying, and then running wasp db seed
locally, but that says can't connect to the DBOutput of
npm run db-seed
on the serverOh hey good question, I believe @miho and/or @Vinny (@Wasp) will have a good answer for this one!
Would appreciate it 😁
So to answer your question, I deployed an app quickly to Fly.
I set
seeding-test
as my deployment name so:
- my DB app is seeding-test-db
- my server app is seeding-test-server
Seeding a production database is a two step process:
1️⃣ pointing your local app to use the production DB (just to seed it)
2️⃣ opening a tunnel towards the production DB so the local app can connect to it
But there are some details we need to get first: DB name and DB password
Getting the DB name:
and then write the following:
you'll find your DB name there.
By convention, it should be server_name_with_underscores
, for me it was seeding_test_server
.
Getting the DB password:
then
With all this info, we can finally seed the production DB:
1️⃣ Setting the database URL in .env.server
2️⃣ Opening a tunnel so the production DB is available locally
Running the command wasp db seed
should populate the production DB now 👏
⚠️ Cleanup: remove the DATABASE_URL
from the local .env.server
and close the tunnelThis did the trick, thank you so much for the detailed response!
Thank you for a good question, it helps us fill the gaps in our docs as well 🙂
@miho this is awesome! Oh yeah we need this in our docs. It would also be very cool if we had a command that this this, at least to some degree, for our users, that could be a nice addition.