import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); async function main() { // 分类 const apparel = await prisma.category.upsert({ where: { id: 'cat-apparel' }, update: {}, create: { id: 'cat-apparel', name: '服饰', sort: 1 }, }); const tshirt = await prisma.category.upsert({ where: { id: 'cat-tshirt' }, update: {}, create: { id: 'cat-tshirt', name: 'T恤', parentId: apparel.id, sort: 1 }, }); // 示例商品 await prisma.product.upsert({ where: { id: 'prod-demo-tshirt' }, update: {}, create: { id: 'prod-demo-tshirt', name: '示例定制 T恤', categoryId: tshirt.id, price: 99.0, images: [], description: '用于本地开发联调的示例商品,可在此设计清单中上传自定义图案。', status: 'ON_SALE', }, }); // eslint-disable-next-line no-console console.log('Seed 完成:分类 + 示例商品已写入'); } main() .catch((e) => { // eslint-disable-next-line no-console console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });