Files
TicketingSystem/server/prisma/seed.ts
T
josh 27d2ab0f0d Add ESLint + Prettier + EditorConfig tooling at repo root
v1.0 Phase 1.1 — repo-wide lint/format baseline.

- eslint.config.mjs (flat config) lints server, client, shared
- .prettierrc.json, .prettierignore, .editorconfig, .nvmrc
- Root package.json holds shared devDeps; per-package scripts keep
  their typecheck + test runners
- Fix 7 lint issues surfaced by the baseline run:
  - TicketDetail.tsx: replace ternary-with-side-effects with if/else
  - admin/Users.tsx: escape apostrophe in JSX
  - errorHandler.ts: typed err as unknown with ErrorLike refinement
  - users.ts: Prisma.UserUpdateInput instead of Record<string, any>
  - seed.ts: drop unused goddard binding
- Run prettier across tracked sources for a clean formatting baseline
2026-04-18 14:47:34 -04:00

106 lines
2.9 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
import crypto from 'crypto';
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',
},
});
// Goddard — n8n service account
const apiKey = `sk_${crypto.randomBytes(32).toString('hex')}`;
await prisma.user.upsert({
where: { username: 'goddard' },
update: {},
create: {
username: 'goddard',
email: 'goddard@internal',
displayName: 'Goddard',
passwordHash: await bcrypt.hash(crypto.randomBytes(32).toString('hex'), 12),
role: 'SERVICE',
apiKey,
},
});
const existingGoddard = await prisma.user.findUnique({ where: { username: 'goddard' } });
console.log(`\nGoddard API key: ${existingGoddard?.apiKey ?? apiKey}`);
console.log('(This key is only displayed once on first seed — copy it now)\n');
// 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());