updated schema so same region name can exist in differentcountries

This commit is contained in:
christian 2024-06-02 07:54:09 +02:00
parent f0125fd472
commit 7590e54392

View File

@ -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", {
export const regions = createTable(
"region",
{
id: uuid("id").primaryKey().notNull().defaultRandom(),
name: text("name").notNull().unique(),
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),