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, text,
timestamp, timestamp,
uuid, uuid,
unique,
} from "drizzle-orm/pg-core"; } from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm"; 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(
id: uuid("id").primaryKey().notNull().defaultRandom(), "region",
name: text("name").notNull().unique(), {
countryId: uuid("countryId").notNull(), 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 }) => ({ export const regionsRelations = relations(regions, ({ many, one }) => ({
wines: many(wines), wines: many(wines),