75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
import bcrypt from 'bcryptjs';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
const passwordHash = await bcrypt.hash('123456', 10);
|
|
|
|
const user = await prisma.user.upsert({
|
|
where: { phone: '13800138000' },
|
|
update: {},
|
|
create: {
|
|
phone: '13800138000',
|
|
passwordHash,
|
|
nickname: '小明',
|
|
joinDate: new Date('2026-03-01'),
|
|
},
|
|
});
|
|
|
|
const family = await prisma.family.upsert({
|
|
where: { id: 'f_preset_home' },
|
|
update: {},
|
|
create: {
|
|
id: 'f_preset_home',
|
|
name: '小明的家',
|
|
inviteCode: 'ABCDEF',
|
|
createdBy: user.id,
|
|
members: {
|
|
create: {
|
|
userId: user.id,
|
|
nickname: '小明',
|
|
role: 'owner',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
await prisma.user.update({
|
|
where: { id: user.id },
|
|
data: {
|
|
familyIds: [family.id],
|
|
activeFamilyId: family.id,
|
|
},
|
|
});
|
|
|
|
const sampleBills = [
|
|
{ type: 'expense' as const, amount: 32, category: '餐饮', emoji: '🍜', note: '午餐-兰州拉面', time: '12:30', date: new Date('2026-05-01') },
|
|
{ type: 'expense' as const, amount: 15, category: '交通', emoji: '🚇', note: '地铁通勤', time: '08:45', date: new Date('2026-05-02') },
|
|
{ type: 'expense' as const, amount: 128, category: '购物', emoji: '🛒', note: '超市采购', time: '18:20', date: new Date('2026-05-03') },
|
|
{ type: 'expense' as const, amount: 45, category: '餐饮', emoji: '☕', note: '星巴克咖啡', time: '15:00', date: new Date('2026-05-03') },
|
|
{ type: 'income' as const, amount: 15000, category: '工资', emoji: '💰', note: '5月工资', time: '10:00', date: new Date('2026-05-05') },
|
|
{ type: 'expense' as const, amount: 200, category: '居住', emoji: '🏠', note: '物业费', time: '09:00', date: new Date('2026-05-06') },
|
|
{ type: 'expense' as const, amount: 88, category: '餐饮', emoji: '🍣', note: '和朋友聚餐', time: '19:30', date: new Date('2026-05-07') },
|
|
{ type: 'expense' as const, amount: 56, category: '交通', emoji: '🚕', note: '打车回家', time: '22:15', date: new Date('2026-05-08') },
|
|
];
|
|
|
|
for (const bill of sampleBills) {
|
|
await prisma.bill.create({
|
|
data: {
|
|
userId: user.id,
|
|
familyId: family.id,
|
|
...bill,
|
|
},
|
|
});
|
|
}
|
|
|
|
console.log('✅ 种子数据已创建:');
|
|
console.log(' 预设账号: 13800138000 / 123456');
|
|
console.log(' 家庭: 小明的家');
|
|
console.log(' 账单: 8 条示例');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => { console.error(e); process.exit(1); })
|
|
.finally(() => prisma.$disconnect()); |