How do you initialize/seed your DB with/for static values? (e.g. post categories)

Imagine you'd need to put some static values in the DB, for example post categories. Each category gets a unique ID (string). These categories are not changed by any user, only be me, as the admin. Where and when would you put these static values into the database? I thought about three variants to create these post categories: #1) Put them into the database manually using whatever CLI/UI editor is available for the database. In my case this would be the Supabase table editor for a Postgres DB. Adding new categories or changing some will create havoc though, as all data related to the category has to be changed as well. So, not really an option. #2) Fill the data via Prisma seed. I guess the same problem remains: How to handle updates to the categories? #3) Create a Prisma migration where you execute hand-written SQL. Create your initial categories there. If you need to change one, create another migration. This has the benefit of being able to change related data that depends on the categories as well. Besides that, would you rather create the categories with random IDs or with a "fixed" string ID? Using fixed IDs could then also be done via enums (not in TypeScript, but the Prisma schema), so if you need a specific ID, you also get type-safe usage (in the app code via TypeScript). So, how do you handle static values in the DB? Maybe there's even a better way?
0 Replies
No replies yetBe the first to reply to this messageJoin