feat(seed): update pricing item seeding to upsert on every deploy
This commit is contained in:
parent
fe5f1ce25f
commit
2eac53dac3
@ -9,7 +9,7 @@ echo "→ Syncing database schema..."
|
|||||||
# db push creates the SQLite file and syncs tables to match schema.prisma
|
# db push creates the SQLite file and syncs tables to match schema.prisma
|
||||||
/app/node_modules/.bin/prisma db push
|
/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
|
/app/node_modules/.bin/tsx /app/prisma/seed.ts
|
||||||
|
|
||||||
echo "→ Starting Next.js on port ${PORT:-3000}..."
|
echo "→ Starting Next.js on port ${PORT:-3000}..."
|
||||||
|
|||||||
BIN
prisma/lootah.db
BIN
prisma/lootah.db
Binary file not shown.
@ -47,30 +47,30 @@ async function main() {
|
|||||||
console.log('✓ JWT secret already exists, skipping.');
|
console.log('✓ JWT secret already exists, skipping.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seed default pricing items (idempotent — only if table is empty)
|
// Pricing items — upserted on every deploy so the code is the source of truth.
|
||||||
const pricingCount = await prisma.pricingItem.count();
|
// Prices in AED. USD → AED at 3.6725 (CBUAE peg).
|
||||||
if (pricingCount === 0) {
|
// Basic = Unitree G1 retail ($16k) + $5k markup = $21k ≈ 77,125 AED.
|
||||||
// Prices in AED. USD → AED at 3.6725 (CBUAE peg).
|
// EDU = $40k flat ≈ 146,900 AED.
|
||||||
// Basic = Unitree G1 retail ($16k) + $5k markup = $21k ≈ 77,125 AED.
|
// All persona attire = 5,000 AED each.
|
||||||
// EDU = $40k flat ≈ 146,900 AED.
|
// Note: any prior admin-UI edits to these item prices/labels will be reset on each deploy.
|
||||||
// All persona attire = 5,000 AED each.
|
const defaultItems = [
|
||||||
const defaultItems = [
|
{ id: 'base', label: 'G1 Robot Basic', price: 77125, sortOrder: 0 },
|
||||||
{ id: 'base', label: 'G1 Robot Basic', price: 77125, sortOrder: 0 },
|
{ id: 'edu', label: 'G1 Robot EDU', price: 146900, sortOrder: 1 },
|
||||||
{ id: 'edu', label: 'G1 Robot EDU', price: 146900, sortOrder: 1 },
|
{ id: 'emarati-kandura', label: 'Emarati Kandura', price: 5000, sortOrder: 2 },
|
||||||
{ id: 'emarati-kandura', label: 'Emarati Kandura', price: 5000, sortOrder: 2 },
|
{ id: 'industrial-vest', label: 'Industrial Vest', price: 5000, sortOrder: 3 },
|
||||||
{ id: 'industrial-vest', label: 'Industrial Vest', price: 5000, sortOrder: 3 },
|
{ id: 'business-suit', label: 'Business Suit', price: 5000, sortOrder: 4 },
|
||||||
{ id: 'business-suit', label: 'Business Suit', price: 5000, sortOrder: 4 },
|
{ id: 'custom-color', label: 'Custom Color', price: 3500, sortOrder: 5 },
|
||||||
{ id: 'custom-color', label: 'Custom Color', price: 3500, sortOrder: 5 },
|
{ id: 'robot-doctor', label: 'Robot Doctor', price: 5000, sortOrder: 6 },
|
||||||
{ id: 'robot-doctor', label: 'Robot Doctor', price: 5000, sortOrder: 6 },
|
{ id: 'security-guard', label: 'Security Guard', price: 5000, sortOrder: 7 },
|
||||||
{ id: 'security-guard', label: 'Security Guard', price: 5000, sortOrder: 7 },
|
];
|
||||||
];
|
for (const item of defaultItems) {
|
||||||
for (const item of defaultItems) {
|
await prisma.pricingItem.upsert({
|
||||||
await prisma.pricingItem.create({ data: item });
|
where: { id: item.id },
|
||||||
}
|
create: item,
|
||||||
console.log(`✓ Seeded ${defaultItems.length} default pricing items.`);
|
update: { label: item.label, price: item.price, sortOrder: item.sortOrder },
|
||||||
} else {
|
});
|
||||||
console.log(`✓ ${pricingCount} pricing items already exist, skipping.`);
|
|
||||||
}
|
}
|
||||||
|
console.log(`✓ Upserted ${defaultItems.length} pricing items from code defaults.`);
|
||||||
|
|
||||||
console.log('Seeding complete!');
|
console.log('Seeding complete!');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user