updated schema to reflect producers and wine
This commit is contained in:
		
							parent
							
								
									8d606fd7b8
								
							
						
					
					
						commit
						6418855f4e
					
				@ -1,16 +1,13 @@
 | 
				
			|||||||
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
 | 
				
			||||||
@ -20,17 +17,46 @@ import {
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
export const createTable = pgTableCreator((name) => `wine-shop_${name}`);
 | 
					export const createTable = pgTableCreator((name) => `wine-shop_${name}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const posts = createTable(
 | 
					export const producers = createTable(
 | 
				
			||||||
  "post",
 | 
					  "producer",
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    id: uuid('id').primaryKey(),
 | 
					    id: uuid('id').primaryKey(),
 | 
				
			||||||
    post: text('post').notNull(),
 | 
					    name: text('name').notNull(),
 | 
				
			||||||
    createdAt: timestamp('createdAt').defaultNow().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 {
 | 
					    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],
 | 
				
			||||||
 | 
					  }),
 | 
				
			||||||
 | 
					}));
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user