55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import 'dotenv/config';
|
|
import { prisma } from '../src/lib/prisma';
|
|
import bcrypt from 'bcryptjs';
|
|
|
|
async function main() {
|
|
// Ensure an initial user
|
|
const username = 'admin';
|
|
const password = 'admin123';
|
|
const hash = await bcrypt.hash(password, 10);
|
|
const user = await prisma.user.upsert({
|
|
where: { username },
|
|
create: { username, password: hash },
|
|
update: {},
|
|
});
|
|
|
|
// Insert sample models
|
|
const tinyPng = Buffer.from(
|
|
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMBA7P6sGQAAAAASUVORK5CYII=',
|
|
'base64'
|
|
);
|
|
|
|
const samples = [
|
|
{
|
|
title: '直流电桥测电阻(单臂)',
|
|
desc: '使用直流电桥进行未知电阻测量的经典实验。',
|
|
model: { type: 'dc_bridge_single_arm', version: 1 },
|
|
},
|
|
{
|
|
title: 'RC 充放电实验',
|
|
desc: '研究 RC 电路的充放电过程与时间常数。',
|
|
model: { type: 'rc_charge_discharge', version: 1 },
|
|
},
|
|
];
|
|
|
|
for (const s of samples) {
|
|
await prisma.circuitModel.create({
|
|
data: {
|
|
title: s.title,
|
|
desc: s.desc,
|
|
model: s.model,
|
|
preview: tinyPng,
|
|
previewMime: 'image/png',
|
|
authorId: user.id,
|
|
},
|
|
});
|
|
}
|
|
|
|
console.log('Seed completed. Admin user:', username, 'password:', password);
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|