2025-06-22 11:34:32 +08:00

262 lines
6.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { PrismaClient } from '@prisma/client'
import { hashPassword } from './lib/auth'
const prisma = new PrismaClient()
async function main() {
// 创建管理员用户
const adminPassword = await hashPassword('admin123')
const admin = await prisma.user.upsert({
where: { email: 'admin@pcdiy.com' },
update: {},
create: {
email: 'admin@pcdiy.com',
username: 'admin',
password: adminPassword,
name: '系统管理员',
isAdmin: true,
},
})
// 创建配件类型
const componentTypes = [
{ name: 'CPU', description: '中央处理器' },
{ name: '内存', description: '内存条' },
{ name: '硬盘', description: '存储设备' },
{ name: '主板', description: '主板' },
{ name: '显卡', description: '显卡' },
{ name: '机箱', description: '机箱' },
]
for (const type of componentTypes) {
await prisma.componentType.upsert({
where: { name: type.name },
update: {},
create: type,
})
}
// 获取已创建的配件类型
const cpuType = await prisma.componentType.findUnique({ where: { name: 'CPU' } })
const memoryType = await prisma.componentType.findUnique({ where: { name: '内存' } })
const storageType = await prisma.componentType.findUnique({ where: { name: '硬盘' } })
const motherboardType = await prisma.componentType.findUnique({ where: { name: '主板' } })
const gpuType = await prisma.componentType.findUnique({ where: { name: '显卡' } })
const caseType = await prisma.componentType.findUnique({ where: { name: '机箱' } })
// 创建示例配件
const components = [
// CPU
{
name: 'Intel Core i5-13400F',
brand: 'Intel',
model: 'i5-13400F',
price: 1299,
description: '10核16线程基础频率2.5GHz最大睿频4.6GHz',
stock: 50,
componentTypeId: cpuType!.id,
specifications: JSON.stringify({
cores: 10,
threads: 16,
baseClock: '2.5GHz',
boostClock: '4.6GHz',
socket: 'LGA1700'
})
},
{
name: 'AMD Ryzen 5 7600X',
brand: 'AMD',
model: '7600X',
price: 1599,
description: '6核12线程基础频率4.7GHz最大睿频5.3GHz',
stock: 30,
componentTypeId: cpuType!.id,
specifications: JSON.stringify({
cores: 6,
threads: 12,
baseClock: '4.7GHz',
boostClock: '5.3GHz',
socket: 'AM5'
})
},
// 内存
{
name: 'Kingston FURY Beast DDR4 3200MHz 16GB',
brand: 'Kingston',
model: 'FURY Beast',
price: 299,
description: 'DDR4 3200MHz 16GB套装8GBx2',
stock: 100,
componentTypeId: memoryType!.id,
specifications: JSON.stringify({
type: 'DDR4',
speed: '3200MHz',
capacity: '16GB',
modules: 2
})
},
{
name: 'Corsair Vengeance LPX DDR4 3600MHz 32GB',
brand: 'Corsair',
model: 'Vengeance LPX',
price: 699,
description: 'DDR4 3600MHz 32GB套装16GBx2',
stock: 60,
componentTypeId: memoryType!.id,
specifications: JSON.stringify({
type: 'DDR4',
speed: '3600MHz',
capacity: '32GB',
modules: 2
})
},
// 硬盘
{
name: 'Samsung 980 PRO 1TB NVMe SSD',
brand: 'Samsung',
model: '980 PRO',
price: 599,
description: 'PCIe 4.0 NVMe M.2 SSD读取速度7000MB/s',
stock: 80,
componentTypeId: storageType!.id,
specifications: JSON.stringify({
type: 'NVMe SSD',
capacity: '1TB',
interface: 'PCIe 4.0',
readSpeed: '7000MB/s'
})
},
{
name: 'Western Digital Blue 2TB SATA HDD',
brand: 'Western Digital',
model: 'Blue',
price: 399,
description: '2TB 7200RPM SATA 机械硬盘',
stock: 120,
componentTypeId: storageType!.id,
specifications: JSON.stringify({
type: 'HDD',
capacity: '2TB',
interface: 'SATA',
speed: '7200RPM'
})
},
// 主板
{
name: 'ASUS PRIME B660M-A',
brand: 'ASUS',
model: 'PRIME B660M-A',
price: 699,
description: 'Intel B660芯片组支持LGA1700接口',
stock: 40,
componentTypeId: motherboardType!.id,
specifications: JSON.stringify({
chipset: 'B660',
socket: 'LGA1700',
formFactor: 'mATX',
memorySlots: 4
})
},
{
name: 'MSI MAG B550M MORTAR',
brand: 'MSI',
model: 'MAG B550M MORTAR',
price: 799,
description: 'AMD B550芯片组支持AM4接口',
stock: 35,
componentTypeId: motherboardType!.id,
specifications: JSON.stringify({
chipset: 'B550',
socket: 'AM4',
formFactor: 'mATX',
memorySlots: 4
})
},
// 显卡
{
name: 'NVIDIA GeForce RTX 4060 Ti',
brand: 'NVIDIA',
model: 'RTX 4060 Ti',
price: 3299,
description: '16GB GDDR6显存支持光追和DLSS 3',
stock: 25,
componentTypeId: gpuType!.id,
specifications: JSON.stringify({
gpu: 'RTX 4060 Ti',
memory: '16GB GDDR6',
memoryBus: '128-bit',
baseClock: '2310MHz'
})
},
{
name: 'AMD Radeon RX 7600 XT',
brand: 'AMD',
model: 'RX 7600 XT',
price: 2799,
description: '16GB GDDR6显存RDNA 3架构',
stock: 20,
componentTypeId: gpuType!.id,
specifications: JSON.stringify({
gpu: 'RX 7600 XT',
memory: '16GB GDDR6',
memoryBus: '128-bit',
baseClock: '2300MHz'
})
},
// 机箱
{
name: 'Fractal Design Core 1000',
brand: 'Fractal Design',
model: 'Core 1000',
price: 299,
description: '紧凑型mATX机箱静音设计',
stock: 70,
componentTypeId: caseType!.id,
specifications: JSON.stringify({
formFactor: 'mATX',
dimensions: '390 x 175 x 350mm',
material: '钢制',
fans: '1x120mm'
})
},
{
name: 'NZXT H510',
brand: 'NZXT',
model: 'H510',
price: 599,
description: '中塔ATX机箱钢化玻璃侧板',
stock: 50,
componentTypeId: caseType!.id,
specifications: JSON.stringify({
formFactor: 'ATX',
dimensions: '435 x 210 x 460mm',
material: '钢制+钢化玻璃',
fans: '2x120mm'
})
},
]
for (const component of components) {
await prisma.component.upsert({
where: {
id: 'temp-id-' + component.name.replace(/\s+/g, '-').toLowerCase()
},
update: {},
create: component,
})
}
console.log('数据初始化完成!')
console.log('管理员账号admin@pcdiy.com')
console.log('管理员密码admin123')
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})