How to create seed data on fly.io postgres instance
I created a new fly io launch and want to create same set of seed data which I do locally using
wasp db seed
on fly.io's postgres instance. How can I achieve it ?2 Replies
Hi @anand248. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To seed data on a Fly.io Postgres instance, you need to follow a two-step process:
1. Point your local app to use the production DB (just to seed it).
2. Open a tunnel towards the production DB so the local app can connect to it.
Here are the detailed steps:
1. Get the DB name and DB password:
- Run the following command to get the DB name:
Then write
\l
to find your DB name.
- To get the DB password, run:
Then write echo $OPERATOR_PASSWORD
.
2. Set the database URL in .env.server
:
Edit your .env.server
to contain the following line (with correct values in the place of <password>
and <db_name>
):
3. Open a tunnel so the production DB is available locally:
First, make sure nothing else is running on the port 5432, e.g. your local dev database (which you may have started with wasp db start
, or in some other way). Then, run:
Leave this terminal tab running and open a new terminal tab for future commands.
4. Seed the production DB:
Now you can run the command wasp db seed
to populate the production DB.
Remember to remove the DATABASE_URL
from the local .env.server
and close the tunnel after you're done.
For more details, you can refer to this Github issue (https://github.com/wasp-lang/wasp/issues/1464).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @anand248, 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?Yup, this issue covers it very well! One option, that depending on your use case could be easier for you, is also to potentially deploy your app with API route that runs the seeding logic, and then you make a call to that API once your app is up, and later remove it. It is a bit hackish solution, but it can be practical + you can protect it either by allowing only your user to run it or by secret password or something.