updated schema to reflect producers and wine

This commit is contained in:
christian 2024-05-23 20:55:08 +02:00
parent 8d606fd7b8
commit 6418855f4e

View File

@ -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],
}),
}));