Can you add a unique to an existing table? supabase + drizzle
I am using supabase and drizzle in my Next.js application and unfortunately noticed a year later I forgot to add a
unique().on()
for a table that holds voter ballots. 🫠I thought everything was fine and dandy and no duplicates were being inserted into the DB until this week when I noticed some. 😬
The schema for this table looks like
And I am thinking of adding (table) => [unique().on(table.userId, table.division, table.week, table.year, table.sportId)],
to it and then generating and then migrating. I guess my question is, will this break anything? I believe I removed all the duplicates and want to make sure I get this in there before more votes get added.5 Replies
You should have a staging environment where you test such changes. This is how folks developing production applications work. I don't know drizzle inner workings but it should generate a migration file before applying it, so you can look at the generated migration file and see what actions it will perform and see if any of them are destructive.
Gotcha, yeah I need to figure out a way to seed my local Supabase with what is in production so I have a bunch of data to work with 😅
I was not good about testing locally in the beginning since the project was small 😬🥲 but now it has grown to a point where I need to be careful.
I'd suggest getting your schema setup in a local instance and then seed the database with some data and try performing the drizzle schema change to see if there are any issues. This isn't something I'd rely on someone on the internet to tell me as they don't have my environment setup or know my exact setup.
Any docs on how to get the data from my prod DB to my local/seeding my local db?
You should never pull production data into your local instance, especially if it's sensitive data. You should create fake dummy data for your local instance.