Skip to content

Commit 2b549e5

Browse files
authored
Sedd that data!! (#57)
1 parent 5c820b8 commit 2b549e5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/api/docker-entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ fi
3939
echo "Ensuring Prisma Client is up to date..."
4040
npx 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
4347
echo "Starting application..."
4448
exec "$@"

packages/api/prisma/seed.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ const prisma = new PrismaClient();
55
async 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();

0 commit comments

Comments
 (0)