fix: prisma migrate now runs at container startup + dotenv optional
Deploy to VPS / deploy (push) Has been cancelled
Deploy to VPS / deploy (push) Has been cancelled
Two related fixes for the deploy pipeline so DB schema changes never again leave the site half-deployed. PRISMA CONFIG (prisma.config.ts) - "import 'dotenv/config'" was hard-required, but dotenv isn't installed in the production runtime image (env vars come from docker-compose). - Wrapped in try/catch so it loads .env locally and silently no-ops in the container — `prisma migrate deploy` works in both environments. DOCKERFILE - Copies node_modules/prisma + prisma.config.ts to the runner stage so the CLI is available at runtime, not just at build. - New CMD runs `prisma migrate deploy` before booting the server. Idempotent — already-applied migrations are skipped. If the DB is unreachable, the container exits and docker-compose retries. - This means: from now on, `git pull && docker compose up -d --build app` is the entire deploy. No more "did you remember to run migrations?". DEFENSIVE TRY/CATCH (applications/[slug]/page.tsx) - prisma.application.findUnique and prisma.globalNode.findMany now have try/catch with logged errors. A transient DB hiccup or missing Application slug now degrades gracefully (renders "not found" or empty cases wall) instead of triggering a 500 Internal Server Error. DEPLOY (David, this is the recovery sequence on the VPS) cd /opt/flux-srl git pull docker compose up -d --build app # The container will run pending migrations on its own. # No need to run `prisma migrate deploy` manually anymore.
This commit is contained in:
@@ -93,9 +93,12 @@ export default async function ApplicationPage({ params }: { params: Promise<{ sl
|
||||
const { slug, locale } = resolvedParams;
|
||||
|
||||
// 1. Buscamos la Teoría General de la Aplicación
|
||||
const rawData = await prisma.application.findUnique({
|
||||
where: { slug }
|
||||
});
|
||||
let rawData: any = null;
|
||||
try {
|
||||
rawData = await prisma.application.findUnique({ where: { slug } });
|
||||
} catch (error) {
|
||||
console.error(`[applications/${slug}] DB error fetching application:`, error);
|
||||
}
|
||||
|
||||
if (!rawData) {
|
||||
return (
|
||||
@@ -110,14 +113,19 @@ export default async function ApplicationPage({ params }: { params: Promise<{ sl
|
||||
const data = getLocalizedData(rawData, locale);
|
||||
|
||||
// 2. Buscamos el "Muro de Soluciones" (Casos Reales específicos de esta app)
|
||||
const rawRealCases = await prisma.globalNode.findMany({
|
||||
where: {
|
||||
application: slug,
|
||||
isActive: true,
|
||||
projectOverview: { not: null }
|
||||
},
|
||||
orderBy: { createdAt: 'desc' }
|
||||
});
|
||||
let rawRealCases: any[] = [];
|
||||
try {
|
||||
rawRealCases = await prisma.globalNode.findMany({
|
||||
where: {
|
||||
application: slug,
|
||||
isActive: true,
|
||||
projectOverview: { not: null },
|
||||
},
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`[applications/${slug}] DB error fetching cases:`, error);
|
||||
}
|
||||
|
||||
// 🔥 TRADUCIMOS TODOS LOS CASOS DE ESTUDIO DEL MURO
|
||||
const realCases = rawRealCases.map((node: any) => getLocalizedData(node, locale));
|
||||
|
||||
Reference in New Issue
Block a user