Where to place CSV file when seeding the database

I'm trying to seed the database with a CSV file but I'm struggling to figure out where to place the CSV file when running fs.createReadStream(path.join(process.cwd(), 'data.csv')). I'm using path.join(process.cwd(), 'data.csv') but the CSV file doesn't exist in .wasp/out/server/bundle/. Any help is appreciated!
5 Replies
kapa.ai
kapa.ai4w ago
Hi @KQATran. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain specific information about where to place a CSV file when seeding the database in Wasp. However, I can tell you that Wasp supports database seeding and you can run seed functions using the wasp db seed command or wasp db seed <seed-name> for a specific seed function (source (https://wasp-lang.dev/docs/data-model/backends#running-seed-functions)). For more detailed information on how to handle CSV files when seeding the database in Wasp, I would recommend checking the official Wasp documentation or reaching out to the Wasp community. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @KQATran, 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?
cmilazzo
cmilazzo4w ago
Hey @KQATran . From my experience (very limited so far!) it looks like you have to implement a js function to do the seeding, you can't just place a CSV file. In other words, read the CSV file into JS and put it into a JSON object. The js would be referenced in your main.wasp file as such: app MyApp { title: "My app", // ... db: { seeds: [ import devSeed from "@src/dbSeeds.js" ], } } https://wasp-lang.dev/docs/data-model/backends#writing-a-seed-function
Kenny
Kenny4w ago
Hey @cmilazzo thanks for replying! I've already created the seed function that reads the CSV file and populates the database. However, I'm having trouble figuring out how to pass the file path to the function. I've tried placing the file in the same directory as the seed script but it doesn't get carried over to .wasp/out/server/ where I guess the process is running. Just trying to figure out where to place the file so I can reference it when running wasp db seed
miho
miho4w ago
This is an open issue for Wasp: https://github.com/wasp-lang/wasp/issues/2175 In short, your local file-system is not the same as your production file-system will be. Take into account that the server app might restart, it might be in a container that might be deleted and recreated at some point (the local files are then gone). So, either we introduce some "assets" dir for the server which gets copied over - this is something for Wasp to implement. Or, maybe you have the seed file on S3 / or similar and download it on boot to some local location if it's missing. Another option would be what @cmilazzo mentioned, convert the CSV into JSON / JS and just import it into your JS so it gets bundled.
GitHub
Allow users to store private non-source files · Issue #2175 · wasp-...
We should give users a way to store private non-source files that the app uses (like the public dir, only private). Motivation From the message: https://discord.com/channels/686873244791210014/1260...
Kenny
Kenny4w ago
Appreciate the response @miho!
Want results from more Discord servers?
Add your server