From 2eac53dac38e692df3475160222ef89b7e35513a Mon Sep 17 00:00:00 2001 From: "Najjar\\NajjarV02" Date: Tue, 19 May 2026 17:46:22 +0400 Subject: [PATCH] feat(seed): update pricing item seeding to upsert on every deploy --- docker-entrypoint.sh | 2 +- prisma/lootah.db | Bin 118784 -> 118784 bytes prisma/seed.ts | 46 +++++++++++++++++++++---------------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4bd3438..9e4d5a2 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -9,7 +9,7 @@ echo "→ Syncing database schema..." # db push creates the SQLite file and syncs tables to match schema.prisma /app/node_modules/.bin/prisma db push -echo "→ Seeding database (idempotent — skips existing records)..." +echo "→ Seeding database (idempotent — pricing rows are upserted every deploy)..." /app/node_modules/.bin/tsx /app/prisma/seed.ts echo "→ Starting Next.js on port ${PORT:-3000}..." diff --git a/prisma/lootah.db b/prisma/lootah.db index 9695d4109a03bff979aad96ce1a97c5ffd772d3a..82e686beeaf4c26eb5595d00e2844159fe43bc19 100644 GIT binary patch delta 142 zcmZozz}~QceS$Qj(nJ|&My1AttqF`j=Wv>sTA7;bnHd^RPnydZ#sT4)T24POmoXeF zX=-jcU11($1dMBDJiT!qV+@RIVm$pB64%&Zy7zoWUzn_+>GXy383UkP6HCkOzveTt G82|u6eJ7a! delta 113 zcmZozz}~QceS$Qj)I=F)MybYxtqF`j=S;Vm%g8@HV=iOB^w}WRaS-blh^01z8Q(|hq{nva(HUj|Z CWG2o4 diff --git a/prisma/seed.ts b/prisma/seed.ts index 0beb894..d7ffb9d 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -47,30 +47,30 @@ async function main() { console.log('✓ JWT secret already exists, skipping.'); } - // Seed default pricing items (idempotent — only if table is empty) - const pricingCount = await prisma.pricingItem.count(); - if (pricingCount === 0) { - // Prices in AED. USD → AED at 3.6725 (CBUAE peg). - // Basic = Unitree G1 retail ($16k) + $5k markup = $21k ≈ 77,125 AED. - // EDU = $40k flat ≈ 146,900 AED. - // All persona attire = 5,000 AED each. - const defaultItems = [ - { id: 'base', label: 'G1 Robot Basic', price: 77125, sortOrder: 0 }, - { id: 'edu', label: 'G1 Robot EDU', price: 146900, sortOrder: 1 }, - { id: 'emarati-kandura', label: 'Emarati Kandura', price: 5000, sortOrder: 2 }, - { id: 'industrial-vest', label: 'Industrial Vest', price: 5000, sortOrder: 3 }, - { id: 'business-suit', label: 'Business Suit', price: 5000, sortOrder: 4 }, - { id: 'custom-color', label: 'Custom Color', price: 3500, sortOrder: 5 }, - { id: 'robot-doctor', label: 'Robot Doctor', price: 5000, sortOrder: 6 }, - { id: 'security-guard', label: 'Security Guard', price: 5000, sortOrder: 7 }, - ]; - for (const item of defaultItems) { - await prisma.pricingItem.create({ data: item }); - } - console.log(`✓ Seeded ${defaultItems.length} default pricing items.`); - } else { - console.log(`✓ ${pricingCount} pricing items already exist, skipping.`); + // Pricing items — upserted on every deploy so the code is the source of truth. + // Prices in AED. USD → AED at 3.6725 (CBUAE peg). + // Basic = Unitree G1 retail ($16k) + $5k markup = $21k ≈ 77,125 AED. + // EDU = $40k flat ≈ 146,900 AED. + // All persona attire = 5,000 AED each. + // Note: any prior admin-UI edits to these item prices/labels will be reset on each deploy. + const defaultItems = [ + { id: 'base', label: 'G1 Robot Basic', price: 77125, sortOrder: 0 }, + { id: 'edu', label: 'G1 Robot EDU', price: 146900, sortOrder: 1 }, + { id: 'emarati-kandura', label: 'Emarati Kandura', price: 5000, sortOrder: 2 }, + { id: 'industrial-vest', label: 'Industrial Vest', price: 5000, sortOrder: 3 }, + { id: 'business-suit', label: 'Business Suit', price: 5000, sortOrder: 4 }, + { id: 'custom-color', label: 'Custom Color', price: 3500, sortOrder: 5 }, + { id: 'robot-doctor', label: 'Robot Doctor', price: 5000, sortOrder: 6 }, + { id: 'security-guard', label: 'Security Guard', price: 5000, sortOrder: 7 }, + ]; + for (const item of defaultItems) { + await prisma.pricingItem.upsert({ + where: { id: item.id }, + create: item, + update: { label: item.label, price: item.price, sortOrder: item.sortOrder }, + }); } + console.log(`✓ Upserted ${defaultItems.length} pricing items from code defaults.`); console.log('Seeding complete!'); }