File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 3939echo " Ensuring Prisma Client is up to date..."
4040npx prisma generate
4141
42+ # Seed database if empty (idempotent - only runs if no products exist)
43+ echo " Seeding database if needed..."
44+ npm run db:seed
45+
4246# Start the application
4347echo " Starting application..."
4448exec " $@ "
Original file line number Diff line number Diff line change @@ -5,7 +5,16 @@ const prisma = new PrismaClient();
55async function main ( ) {
66 console . log ( 'Starting seed...' ) ;
77
8- // Clear existing data
8+ // Check if products already exist
9+ const existingProducts = await prisma . product . count ( ) ;
10+ if ( existingProducts > 0 ) {
11+ console . log ( `Database already has ${ existingProducts } products, skipping seed` ) ;
12+ return ;
13+ }
14+
15+ console . log ( 'Database is empty, seeding with initial data...' ) ;
16+
17+ // Clear existing data (for demo purposes)
918 await prisma . cartItem . deleteMany ( ) ;
1019 await prisma . order . deleteMany ( ) ;
1120 await prisma . product . deleteMany ( ) ;
You can’t perform that action at this time.
0 commit comments