From 6418855f4eb6b52af22e31d31e6ccfd265c28a15 Mon Sep 17 00:00:00 2001 From: christian Date: Thu, 23 May 2024 20:55:08 +0200 Subject: [PATCH] updated schema to reflect producers and wine --- src/server/db/schema.ts | 46 ++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/server/db/schema.ts b/src/server/db/schema.ts index 3190822..03b0417 100644 --- a/src/server/db/schema.ts +++ b/src/server/db/schema.ts @@ -1,16 +1,13 @@ import { drizzle } from 'drizzle-orm/vercel-postgres'; import { sql } from "@vercel/postgres"; import { - PgTimestamp, - index, pgTableCreator, - serial, text, timestamp, uniqueIndex, uuid, - varchar, } from "drizzle-orm/pg-core"; +import { relations } from 'drizzle-orm'; /** * This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same @@ -20,17 +17,46 @@ import { */ export const createTable = pgTableCreator((name) => `wine-shop_${name}`); -export const posts = createTable( - "post", +export const producers = createTable( + "producer", { id: uuid('id').primaryKey(), - post: text('post').notNull(), + name: text('name').notNull(), createdAt: timestamp('createdAt').defaultNow().notNull(), - updatedAt: timestamp('updatedAt').defaultNow() + country: text('country').notNull(), + region: text('region').notNull(), + email: text('email').notNull() }, - (posts) => { + (producers) => { return { - uniqueIdx: uniqueIndex('unique_idx').on(posts.id), + uniqueIdx: uniqueIndex('email').on(producers.email), }; }, ); + +export const producersRelations = relations(producers, ({ many }) => ({ + wines: many(wines), +})); + +export const wines = createTable( + "wine", + { + id: uuid('id').primaryKey(), + name: text('name').notNull(), + createdAt: timestamp('createdAt').defaultNow().notNull(), + updatedAt: timestamp('updatedAt').defaultNow(), + producer: text('producer').notNull(), + }, + (wines) => { + return { + uniqueIdx: uniqueIndex('unique_idx').on(wines.id), + }; + }, +); + +export const winesRelations = relations(wines, ({ one }) => ({ + producer: one(producers, { + fields: [wines.producer], + references: [producers.id], + }), +})); \ No newline at end of file