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 well
8 Replies
Heisenberg
HeisenbergOP14mo ago
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 DB
Heisenberg
HeisenbergOP14mo ago
Output of npm run db-seed on the server
No description
martinsos
martinsos14mo ago
Oh hey good question, I believe @miho and/or @Vinny (@Wasp) will have a good answer for this one!
Heisenberg
HeisenbergOP14mo ago
Would appreciate it 😁
miho
miho14mo ago
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:
fly postgres connect -a seeding-test-db
fly postgres connect -a seeding-test-db
and then write the following:
\l
\l
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:
fly ssh console -a seeding-test-db
fly ssh console -a seeding-test-db
then
echo $OPERATOR_PASSWORD
echo $OPERATOR_PASSWORD
With all this info, we can finally seed the production DB: 1️⃣ Setting the database URL in .env.server
DATABASE_URL=postgres://postgres:<password>@localhost:5432/<db_name>
DATABASE_URL=postgres://postgres:<password>@localhost:5432/<db_name>
2️⃣ Opening a tunnel so the production DB is available locally
fly proxy 5432 -a seeding-test-db
fly proxy 5432 -a seeding-test-db
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 tunnel
Heisenberg
HeisenbergOP14mo ago
This did the trick, thank you so much for the detailed response!
miho
miho14mo ago
Thank you for a good question, it helps us fill the gaps in our docs as well 🙂
martinsos
martinsos14mo ago
@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.
Want results from more Discord servers?
Add your server