Projektstart

This commit is contained in:
2026-01-22 15:49:12 +01:00
parent 7212eb6f7a
commit 57e5f652f8
10637 changed files with 2598792 additions and 64 deletions

37
backend/prisma/seed.ts Normal file
View File

@@ -0,0 +1,37 @@
import argon2 from "argon2";
import { PrismaClient, UserRole } from "@prisma/client";
const prisma = new PrismaClient();
const tenantName = process.env.SEED_TENANT ?? "Default Tenant";
const email = process.env.SEED_EMAIL ?? "admin@example.com";
const password = process.env.SEED_PASSWORD ?? "change-me-please";
const role = (process.env.SEED_ROLE as UserRole | undefined) ?? "ADMIN";
const main = async () => {
const existing = await prisma.user.findUnique({ where: { email } });
if (existing) {
process.stdout.write("Seed user already exists.\n");
return;
}
const hash = await argon2.hash(password);
const tenant = await prisma.tenant.create({
data: { name: tenantName }
});
await prisma.user.create({
data: { tenantId: tenant.id, email, password: hash, role }
});
process.stdout.write("Seeded tenant and user.\n");
};
main()
.catch((err) => {
process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});