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.
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()
toupsert()
functions. Theupsert()
function checks if data exists, and creates it only if it doesn't. See how thestudent.upsert()
functions work in the seed script for example. I want all other database calls to be updated toupsert()
functions.