Unveränderter Stand von certvia/dev (a48c5fb) plus Craftvia-Spezifikation und Brandbook unter docs/craftvia/. ISMS-Module werden im Folgecommit entfernt. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
import "dotenv/config";
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { PrismaPg } from "@prisma/adapter-pg";
|
|
import { pathToFileURL } from "node:url";
|
|
import { CONTROL_DOMAIN_DEFAULTS } from "../src/lib/control-domain";
|
|
import { importProcessCatalog } from "./import-process-catalog";
|
|
|
|
/**
|
|
* Prod-tauglicher Content-Seed: die GLOBALEN, mandantenunabhängigen Inhalte der
|
|
* TISAX-Neustruktur — Control→Domain/RACI-Defaults (M3) und Prozess-Katalog (M2).
|
|
* Enthält KEINE Demo-/Mandantendaten und ist idempotent (upsert bzw.
|
|
* global-neu-setzen), also gefahrlos in jeder Umgebung mehrfach ausführbar.
|
|
*
|
|
* Wird vom Demo-Seed (`seed.ts`) wiederverwendet und ist eigenständig ausführbar:
|
|
* npm run seed:content
|
|
*/
|
|
export async function seedGlobalContent(
|
|
prisma: PrismaClient
|
|
): Promise<{ controlDomains: number; processCatalog: number }> {
|
|
// Control→Domain/RACI-Defaults (global, tenantId = null). Idempotent: die globalen
|
|
// Zeilen werden neu gesetzt; mandantenspezifische Overrides (tenantId != null) bleiben.
|
|
await prisma.controlDomainMap.deleteMany({ where: { tenantId: null } });
|
|
await prisma.controlDomainMap.createMany({
|
|
data: CONTROL_DOMAIN_DEFAULTS.map((r) => ({
|
|
tenantId: null,
|
|
control: r.control,
|
|
domain: r.domain,
|
|
raci: r.raci,
|
|
functionKey: r.functionKey ?? null,
|
|
})),
|
|
});
|
|
|
|
// Prozess-Katalog (global, upsert je code — idempotent).
|
|
const processCatalog = await importProcessCatalog(prisma);
|
|
|
|
return { controlDomains: CONTROL_DOMAIN_DEFAULTS.length, processCatalog };
|
|
}
|
|
|
|
async function main() {
|
|
const prisma = new PrismaClient({
|
|
adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL }),
|
|
});
|
|
try {
|
|
console.log("→ Globaler Content-Seed (Control→Domain-Defaults + Prozess-Katalog)…");
|
|
const { controlDomains, processCatalog } = await seedGlobalContent(prisma);
|
|
console.log(`✔ ${controlDomains} Control→Domain-Defaults`);
|
|
console.log(`✔ ${processCatalog} Prozess-Katalog-Einträge`);
|
|
console.log("✓ Globaler Content-Seed abgeschlossen.");
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
// Nur als eigenständiger Runner ausführen, nicht beim Import aus seed.ts.
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|
|
}
|