Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aryanprince opened this issue Dec 9, 2023 · 0 comments
Open

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

aryanprince opened this issue Dec 9, 2023 · 0 comments
Assignees
Labels
🗃️ database Prisma, migrations, schema all go here ♻️ refactor Neither fixes a bug nor adds a feature

Comments

@aryanprince
Copy link
Member

aryanprince commented Dec 9, 2023

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.

@aryanprince aryanprince added ♻️ refactor Neither fixes a bug nor adds a feature 🗃️ database Prisma, migrations, schema all go here labels Dec 9, 2023
@aryanprince aryanprince added this to the Final Presentation milestone Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗃️ database Prisma, migrations, schema all go here ♻️ refactor Neither fixes a bug nor adds a feature
Projects
None yet
Development

No branches or pull requests

2 participants