Compare commits

..

No commits in common. "3a10c0ad7e408138e7e2e07d14609b3de05490d0" and "8d606fd7b83eb054310cc7bbde79b62eee8c801f" have entirely different histories.

2 changed files with 11 additions and 37 deletions

View File

@ -10,7 +10,7 @@ Created with t3-app using:
TODO (in no particular order for now): TODO (in no particular order for now):
- [] Top nav - [] Top nav
- [x] define (and draw?) db schema (initial) - [] define (and draw?) db schemas
- [] side product nav - [] side product nav
- [] product cards - [] product cards
- [] cart - [] cart

View File

@ -1,13 +1,16 @@
import { drizzle } from 'drizzle-orm/vercel-postgres'; import { drizzle } from 'drizzle-orm/vercel-postgres';
import { sql } from "@vercel/postgres"; import { sql } from "@vercel/postgres";
import { import {
PgTimestamp,
index,
pgTableCreator, pgTableCreator,
serial,
text, text,
timestamp, timestamp,
uniqueIndex, uniqueIndex,
uuid, uuid,
varchar,
} from "drizzle-orm/pg-core"; } 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 * This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
@ -17,46 +20,17 @@ import { relations } from 'drizzle-orm';
*/ */
export const createTable = pgTableCreator((name) => `wine-shop_${name}`); export const createTable = pgTableCreator((name) => `wine-shop_${name}`);
export const producers = createTable( export const posts = createTable(
"producer", "post",
{ {
id: uuid('id').primaryKey(), id: uuid('id').primaryKey(),
name: text('name').notNull(), post: text('post').notNull(),
createdAt: timestamp('createdAt').defaultNow().notNull(), createdAt: timestamp('createdAt').defaultNow().notNull(),
country: text('country').notNull(), updatedAt: timestamp('updatedAt').defaultNow()
region: text('region').notNull(),
email: text('email').notNull()
}, },
(producers) => { (posts) => {
return { return {
uniqueIdx: uniqueIndex('email').on(producers.email), uniqueIdx: uniqueIndex('unique_idx').on(posts.id),
}; };
}, },
); );
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],
}),
}));