Is there a way to construct a table using a
WHEN
SQL tag?
I am interested in setting up a table similar to this:
"members_table", { id: serial("id").primaryKey(), email: text("email").notNull(), team_id: text("team_id").notNull(), deleted_at: timestamp("deleted_at"), },
I would like the uniqueness constraint to be implemented as follows:
CREATE UNIQUE INDEX email_team_id_unique_idx ON members_table (email, team_id) WHERE deleted_at IS NULL;
But in Drizzle. Can this be achieved?
I want to ensure that the same email and team_id cannot be duplicated. For example, [email protected] cannot exist in both team_id A and B, while [email protected] can be in A with deleted_at as NULL, and [email protected] can be in A with deleted_at set to August 15th, 2024 simultaneously. I hope this clarifies things.
I am working with Next.js, Neon, and PostgreSQL if that influences anything 🙂
I have experimented quite a bit, but without success. I am still relatively new to Drizzle and with a vast amount of documentation, it can be challenging to pinpoint exactly what I need. Any suggestions are appreciated, as there is a good chance you may have more knowledge on the subject than I do xD