Vollstaendige Next.js/Prisma-E-Commerce-Anwendung fuer eine Imkerei: Shop, Warenkorb, Stripe-Checkout, Kundenkonto mit 2FA, Admin-Bereich (Produkte, Ernten, Chargen, Bestellungen, Gutscheine, admin-editierbare Website-Inhalte), i18n (DE/EN), Rate-Limiting/CSP/Audit-Log-Haertung, PostgreSQL- und MySQL-Unterstuetzung ueber austauschbare Prisma- Treiber-Adapter, Unit-/Komponenten-/E2E-Tests.
41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
// Prisma erlaubt kein env() fuer datasource.provider (nur fuer url) — dieses
|
|
// Skript schreibt die provider-Zeile in prisma/schema.prisma daher vor jedem
|
|
// generate/db push/migrate anhand von DATABASE_PROVIDER neu. Wird von den
|
|
// package.json-Skripten aufgerufen, nicht direkt.
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import path from "node:path";
|
|
|
|
const SUPPORTED_PROVIDERS = ["postgresql", "mysql"];
|
|
const DEFAULT_PROVIDER = "postgresql";
|
|
|
|
const schemaPath = path.join(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
"..",
|
|
"prisma",
|
|
"schema.prisma"
|
|
);
|
|
|
|
const provider = (process.env.DATABASE_PROVIDER ?? DEFAULT_PROVIDER).trim();
|
|
|
|
if (!SUPPORTED_PROVIDERS.includes(provider)) {
|
|
console.error(
|
|
`DATABASE_PROVIDER="${provider}" wird nicht unterstuetzt. Erlaubt: ${SUPPORTED_PROVIDERS.join(", ")}.`
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const schema = readFileSync(schemaPath, "utf8");
|
|
const updated = schema.replace(
|
|
/(datasource db \{[^}]*provider\s*=\s*")([a-z]+)(")/,
|
|
`$1${provider}$3`
|
|
);
|
|
|
|
if (updated === schema && !schema.includes(`provider = "${provider}"`)) {
|
|
console.error("datasource-Block in prisma/schema.prisma nicht gefunden — provider konnte nicht gesetzt werden.");
|
|
process.exit(1);
|
|
}
|
|
|
|
writeFileSync(schemaPath, updated);
|
|
console.log(`prisma/schema.prisma: datasource provider = "${provider}"`);
|