Skip to content

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

@aryanprince

Description

@aryanprince

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.

Metadata

Metadata

Assignees

Labels

♻️ refactorNeither fixes a bug nor adds a feature🗃️ databasePrisma, migrations, schema all go here

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions