How to add a unique for a combination?

This is my access schema:

export const access = pgTable("access", {
  id: text("id").primaryKey(),
  role: roles("role").default("member"),
  createdAt: timestamp("created_at", {
    withTimezone: true,
    mode: "date",
  })
    .defaultNow()
    .notNull(),
  organizationId: text("organization_id").references(() => organization.id),
  userId: text("user_id").references(() => user.id),
  
});


The combination of organizationId and userId must be unique. But only the combination. How can I achieve that?

I'm using Postgresql.

Thank you so much.
Was this page helpful?