add migration and config for database

This commit is contained in:
Esteban Paz 2026-08-06 19:54:50 -05:00
parent a9ca3f59f3
commit d30e57f006
3 changed files with 23 additions and 3 deletions

4
.gitignore vendored
View File

@ -30,3 +30,7 @@ prisma/dev.db
opencode/ opencode/
.opencode/ .opencode/
docs/ docs/
# scripts de migración (locales, no en producción)
scripts/migrate-sheets-to-db.ts
scripts/seed-form-config.ts

View File

@ -7,7 +7,10 @@
"build": "astro build", "build": "astro build",
"postbuild": "node scripts/send-to-n8n.js", "postbuild": "node scripts/send-to-n8n.js",
"preview": "astro preview", "preview": "astro preview",
"astro": "astro" "astro": "astro",
"db:migrate-sheets": "npx tsx scripts/migrate-sheets-to-db.ts",
"db:seed-form-config": "npx tsx scripts/seed-form-config.ts",
"db:setup": "npx tsx scripts/seed-form-config.ts && npx tsx scripts/migrate-sheets-to-db.ts"
}, },
"dependencies": { "dependencies": {
"@astrojs/markdoc": "^2.0.3", "@astrojs/markdoc": "^2.0.3",

View File

@ -1,6 +1,7 @@
import type { APIRoute } from "astro"; import type { APIRoute } from "astro";
import { appendToSheet, emailExists } from "../lib/googleSheets"; import { appendToSheet, emailExists } from "../lib/googleSheets";
import { sendEmailCf } from "../lib/email"; import { sendEmailCf } from "../lib/email";
import { prisma } from "../lib/prisma";
export const prerender = false; export const prerender = false;
export const POST: APIRoute = async ({ request }) => { export const POST: APIRoute = async ({ request }) => {
@ -41,10 +42,22 @@ export const POST: APIRoute = async ({ request }) => {
new Date().toLocaleString() new Date().toLocaleString()
]; ];
// 🔹 Enviar correo (Cloudflare) y guardar en Google Sheets // 🔹 Enviar correo (Cloudflare), guardar en Google Sheets y en PostgreSQL
await Promise.all([ await Promise.all([
sendEmailCf({ nombres, apellidos }, email, "CENTRO_DEL_REINO_PAZ_Y_JUSTICIA_POSTULACION"), sendEmailCf({ nombres, apellidos }, email, "CENTRO_DEL_REINO_PAZ_Y_JUSTICIA_POSTULACION"),
appendToSheet(valuesForSheets) appendToSheet(valuesForSheets),
prisma.formulario.create({
data: {
nombre: nombres!,
apellido: apellidos!,
pais: pais || null,
ciudad: lugar || null,
direccion: direccion || null,
telefono: telefono || null,
correo: email!,
status: "legacy",
},
}),
]); ]);
// 🔹 Redirección elegante después de enviar // 🔹 Redirección elegante después de enviar