30 lines
858 B
TypeScript
30 lines
858 B
TypeScript
// prisma/mock-seeds-scripts/06-customers-archive.ts
|
|
import { PrismaClient } from '@prisma/client';
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
const customers = await prisma.customers.findMany({
|
|
orderBy: { id: 'asc' },
|
|
take: 5,
|
|
});
|
|
|
|
for (const c of customers) {
|
|
const invoiceId = 200000 + c.id; // déterministe, stable entre runs
|
|
|
|
await prisma.customersArchive.upsert({
|
|
where: { invoice_id: invoiceId }, // invoice_id est unique
|
|
update: {}, // idempotent
|
|
create: {
|
|
customer_id: c.id,
|
|
user_id: c.user_id,
|
|
invoice_id: invoiceId,
|
|
},
|
|
});
|
|
}
|
|
|
|
const total = await prisma.customersArchive.count();
|
|
console.log(`✓ CustomersArchive upserted for ${customers.length} customers (total=${total})`);
|
|
}
|
|
|
|
main().finally(() => prisma.$disconnect());
|