diff --git a/src/server/db/schema.ts b/src/server/db/schema.ts index cba41e4..06eec43 100644 --- a/src/server/db/schema.ts +++ b/src/server/db/schema.ts @@ -7,6 +7,7 @@ import { text, timestamp, uuid, + unique, } from "drizzle-orm/pg-core"; import { relations } from "drizzle-orm"; @@ -95,11 +96,17 @@ export const subRegionsRelations = relations(subRegions, ({ many, one }) => ({ }), })); -export const regions = createTable("region", { - id: uuid("id").primaryKey().notNull().defaultRandom(), - name: text("name").notNull().unique(), - countryId: uuid("countryId").notNull(), -}); +export const regions = createTable( + "region", + { + id: uuid("id").primaryKey().notNull().defaultRandom(), + name: text("name").notNull(), + countryId: uuid("countryId").notNull(), + }, + (t) => ({ + uniqueRegion: unique().on(t.name, t.countryId), + }), +); export const regionsRelations = relations(regions, ({ many, one }) => ({ wines: many(wines),