Files
TicketingSystem/server/prisma/seed.ts
T
josh d8785a964d
Build & Push / Test (client) (push) Successful in 31s
Build & Push / Test (server) (push) Successful in 38s
Build & Push / Build Client (push) Successful in 1m17s
Build & Push / Build Server (push) Successful in 1m18s
Merge SERVICE role into AGENT
Every AGENT now gets an auto-generated API key on creation, shown once
in a modal. AGENTs log in with password and authenticate to the API
with X-Api-Key. pre-push.sql defensively migrates any residual SERVICE
rows to AGENT before Prisma rewrites the enum. Goddard is no longer
baked into the seed — create agents via Admin → Users.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-18 22:44:32 -04:00

86 lines
2.2 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
const prisma = new PrismaClient();
async function main() {
console.log('Seeding database...');
// Admin user
await prisma.user.upsert({
where: { username: 'admin' },
update: {},
create: {
username: 'admin',
email: 'admin@internal',
displayName: 'Admin',
passwordHash: await bcrypt.hash('admin123', 12),
role: 'ADMIN',
},
});
// Sample CTI structure
const theWrightServer = await prisma.category.upsert({
where: { name: 'TheWrightServer' },
update: {},
create: { name: 'TheWrightServer' },
});
const homelab = await prisma.category.upsert({
where: { name: 'Homelab' },
update: {},
create: { name: 'Homelab' },
});
const automation = await prisma.type.upsert({
where: { categoryId_name: { categoryId: theWrightServer.id, name: 'Automation' } },
update: {},
create: { name: 'Automation', categoryId: theWrightServer.id },
});
const media = await prisma.type.upsert({
where: { categoryId_name: { categoryId: theWrightServer.id, name: 'Media' } },
update: {},
create: { name: 'Media', categoryId: theWrightServer.id },
});
const infrastructure = await prisma.type.upsert({
where: { categoryId_name: { categoryId: homelab.id, name: 'Infrastructure' } },
update: {},
create: { name: 'Infrastructure', categoryId: homelab.id },
});
await prisma.item.upsert({
where: { typeId_name: { typeId: automation.id, name: 'Backup' } },
update: {},
create: { name: 'Backup', typeId: automation.id },
});
await prisma.item.upsert({
where: { typeId_name: { typeId: automation.id, name: 'Sync' } },
update: {},
create: { name: 'Sync', typeId: automation.id },
});
await prisma.item.upsert({
where: { typeId_name: { typeId: media.id, name: 'Plex' } },
update: {},
create: { name: 'Plex', typeId: media.id },
});
await prisma.item.upsert({
where: { typeId_name: { typeId: infrastructure.id, name: 'Proxmox' } },
update: {},
create: { name: 'Proxmox', typeId: infrastructure.id },
});
console.log('Seed complete.');
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(() => prisma.$disconnect());