added wine types and subregions. removed indexes for now
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m29s
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m29s
This commit is contained in:
parent
cf33077aa0
commit
4914e314c9
@ -1,8 +1,9 @@
|
||||
import {
|
||||
boolean,
|
||||
index,
|
||||
integer,
|
||||
pgEnum,
|
||||
pgTableCreator,
|
||||
serial,
|
||||
text,
|
||||
timestamp,
|
||||
uniqueIndex,
|
||||
@ -13,7 +14,6 @@ import { relations } from "drizzle-orm";
|
||||
export const createTable = pgTableCreator((name) => `wine-shop_${name}`);
|
||||
|
||||
// Producer Schema
|
||||
|
||||
export const producers = createTable(
|
||||
"producer",
|
||||
{
|
||||
@ -21,84 +21,95 @@ export const producers = createTable(
|
||||
name: text("name").notNull(),
|
||||
description: text("description").notNull(),
|
||||
imageUrl: text('imageUrl'),
|
||||
country: text("country").notNull(),
|
||||
countryId: uuid("countryId").notNull(),
|
||||
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updatedAt").defaultNow(),
|
||||
|
||||
},
|
||||
(producers) => {
|
||||
return {
|
||||
uniqueIdx: uniqueIndex("producers").on(producers.id),
|
||||
nameIdx: index("producer_name").on(producers.name),
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
// one to man realtion producer -> wines
|
||||
export const producersRelations = relations(producers, ({ many, one }) => ({
|
||||
// one-to-many relation producer -> wines
|
||||
export const producersRelations = relations(producers, ({ many }) => ({
|
||||
wines: many(wines),
|
||||
countries: one(countries, {
|
||||
fields: [producers.country],
|
||||
references: [countries.id]
|
||||
})
|
||||
}));
|
||||
|
||||
// Wines schema
|
||||
export const typeEnum = pgEnum('type', ['sparkling', 'white', 'red', 'sweet', 'other']);
|
||||
|
||||
export const wines = createTable(
|
||||
"wine",
|
||||
{
|
||||
id: uuid("id").primaryKey(),
|
||||
name: text("name").notNull(),
|
||||
type: typeEnum("type").notNull(),
|
||||
description: text("description"),
|
||||
imageUrl: text('imageUrl'),
|
||||
producer: text("producer").notNull(),
|
||||
region: text("region").notNull(),
|
||||
country: text("country").notNull(),
|
||||
producerId: uuid("producerId").notNull(),
|
||||
subRegionId: uuid("subRegionId"),
|
||||
regionId: uuid("regionId").notNull(),
|
||||
countryId: uuid("countryId").notNull(),
|
||||
price: integer("price").notNull(),
|
||||
inStock: boolean("inStock").notNull().default(false),
|
||||
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updatedAt").defaultNow(),
|
||||
},
|
||||
(wines) => {
|
||||
return {
|
||||
uniqueIdx: uniqueIndex("wines").on(wines.id),
|
||||
};
|
||||
);
|
||||
|
||||
// many-to-one relationship wine -> producer
|
||||
export const winesRelations = relations(wines, ({ one }) => ({
|
||||
producer: one(producers, {
|
||||
fields: [wines.producerId],
|
||||
references: [producers.id],
|
||||
}),
|
||||
subregion: one(subRegions, {
|
||||
fields: [wines.subRegionId],
|
||||
references: [subRegions.id],
|
||||
}),
|
||||
region: one(regions, {
|
||||
fields: [wines.regionId],
|
||||
references: [regions.id],
|
||||
}),
|
||||
country: one(countries, {
|
||||
fields: [wines.countryId],
|
||||
references: [countries.id],
|
||||
})
|
||||
}));
|
||||
|
||||
export const subRegions = createTable(
|
||||
"subRegion",
|
||||
{
|
||||
id: uuid("id").primaryKey().notNull(),
|
||||
name: text("name").notNull().unique(),
|
||||
regionId: uuid("regionId").notNull(),
|
||||
},
|
||||
);
|
||||
|
||||
//many to one relationship wine -> producer
|
||||
export const winesRelations = relations(wines, ({ one }) => ({
|
||||
producer: one(producers, {
|
||||
fields: [wines.producer],
|
||||
references: [producers.id],
|
||||
}),
|
||||
regions: one(regions, {
|
||||
fields: [wines.region],
|
||||
export const subRegionsRelations = relations(subRegions, ({ many, one }) => ({
|
||||
wines: many(wines),
|
||||
region: one(regions, {
|
||||
fields: [subRegions.regionId],
|
||||
references: [regions.id]
|
||||
}),
|
||||
countries: one(countries, {
|
||||
fields: [wines.country],
|
||||
references: [countries.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const regions = createTable(
|
||||
"region",
|
||||
{
|
||||
id: serial("id").primaryKey().notNull(),
|
||||
id: uuid("id").primaryKey().notNull(),
|
||||
name: text("name").notNull().unique(),
|
||||
country: text("country").notNull(),
|
||||
},
|
||||
(regions) => {
|
||||
return {
|
||||
uniqueIdx: uniqueIndex("regions").on(regions.id),
|
||||
};
|
||||
countryId: uuid("countryId").notNull(),
|
||||
},
|
||||
);
|
||||
|
||||
export const regionsRelations = relations(regions, ({ many, one }) => ({
|
||||
wines: many(wines),
|
||||
countries: one(countries, {
|
||||
fields: [regions.country],
|
||||
subRegions: many(subRegions),
|
||||
country: one(countries, {
|
||||
fields: [regions.countryId],
|
||||
references: [countries.id]
|
||||
})
|
||||
}));
|
||||
@ -106,18 +117,12 @@ export const regionsRelations = relations(regions, ({ many, one }) => ({
|
||||
export const countries = createTable(
|
||||
"country",
|
||||
{
|
||||
id: serial("id").primaryKey().notNull(),
|
||||
id: uuid("id").primaryKey().notNull(),
|
||||
name: text("name").notNull(),
|
||||
},
|
||||
(countries) => {
|
||||
return {
|
||||
uniqueIdx: uniqueIndex("countries").on(countries.id),
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const countriesRelations = relations(countries, ({ many }) => ({
|
||||
wines: many(wines),
|
||||
regions: many(regions)
|
||||
})
|
||||
);
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user