updated schema so same region name can exist in differentcountries
This commit is contained in:
		
							parent
							
								
									f0125fd472
								
							
						
					
					
						commit
						7590e54392
					
				@ -7,6 +7,7 @@ import {
 | 
				
			|||||||
  text,
 | 
					  text,
 | 
				
			||||||
  timestamp,
 | 
					  timestamp,
 | 
				
			||||||
  uuid,
 | 
					  uuid,
 | 
				
			||||||
 | 
					  unique,
 | 
				
			||||||
} from "drizzle-orm/pg-core";
 | 
					} from "drizzle-orm/pg-core";
 | 
				
			||||||
import { relations } from "drizzle-orm";
 | 
					import { relations } from "drizzle-orm";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -95,11 +96,17 @@ export const subRegionsRelations = relations(subRegions, ({ many, one }) => ({
 | 
				
			|||||||
  }),
 | 
					  }),
 | 
				
			||||||
}));
 | 
					}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const regions = createTable("region", {
 | 
					export const regions = createTable(
 | 
				
			||||||
 | 
					  "region",
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
    id: uuid("id").primaryKey().notNull().defaultRandom(),
 | 
					    id: uuid("id").primaryKey().notNull().defaultRandom(),
 | 
				
			||||||
  name: text("name").notNull().unique(),
 | 
					    name: text("name").notNull(),
 | 
				
			||||||
    countryId: uuid("countryId").notNull(),
 | 
					    countryId: uuid("countryId").notNull(),
 | 
				
			||||||
});
 | 
					  },
 | 
				
			||||||
 | 
					  (t) => ({
 | 
				
			||||||
 | 
					    uniqueRegion: unique().on(t.name, t.countryId),
 | 
				
			||||||
 | 
					  }),
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const regionsRelations = relations(regions, ({ many, one }) => ({
 | 
					export const regionsRelations = relations(regions, ({ many, one }) => ({
 | 
				
			||||||
  wines: many(wines),
 | 
					  wines: many(wines),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user