UniTrackApp / dashboard

📊 Attendance monitoring platform for universities with powerful data analytics and visualizations. Built with Next.js.
https://unitrack-dashboard.vercel.app
GNU General Public License v3.0
5 stars 1 forks source link

Update seed script to upsert data instead of creating them #127

Open aryanprince opened 11 months ago

aryanprince commented 11 months ago

Issue

Let's say I'm in development. I will start off by spinning up a new docker database for local development that has no data. And then I'll run my seed script to add some temporary data to our new database.

I'm testing some stuff by creating new records and deleting some. Now I have messed up our original records and I want to go back to all info that was added by seed script.

But seed script doesn't work since it tries to add data when it already exists. This can be fixed by creating a whole new database and re-running seed script, but that's too much work.

solulu

This can be fixed by switching all the create() to upsert() functions. The upsert() function checks if data exists, and creates it only if it doesn't. See how the student.upsert() functions work in the seed script for example. I want all other database calls to be updated to upsert() functions.