From 185c40f4706807e8767a54fa9494649e8e7724c5 Mon Sep 17 00:00:00 2001 From: Timo Knuth Date: Fri, 16 Jan 2026 17:40:17 +0100 Subject: [PATCH] Add missing migration for Lead table. --- .gitignore | 2 +- scripts/test-db-lead.ts | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 scripts/test-db-lead.ts diff --git a/.gitignore b/.gitignore index 2aa4a1e..4416736 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ yarn-error.log* next-env.d.ts # prisma -/prisma/migrations/ + # docker docker-compose.override.yml diff --git a/scripts/test-db-lead.ts b/scripts/test-db-lead.ts new file mode 100644 index 0000000..5c4f3ca --- /dev/null +++ b/scripts/test-db-lead.ts @@ -0,0 +1,64 @@ +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); + +async function main() { + console.log('šŸ”„ Starting Database Diagnostics...'); + + try { + // 1. Test Connection + console.log('1ļøāƒ£ Testing basic connection...'); + await prisma.$connect(); + console.log('āœ… Connected to database successfully.'); + + // 2. Test Lead Table Existence + console.log('2ļøāƒ£ Testing Lead table access...'); + try { + const count = await prisma.lead.count(); + console.log(`āœ… Lead table found. Current count: ${count}`); + } catch (e: any) { + console.error('āŒ FAILED to access Lead table.'); + if (e.code === 'P2021') { + console.error(' šŸ‘‰ Error P2021: The table "Lead" does not exist in the current database.'); + console.error(' šŸ‘‰ SOLUTION: Run "npx prisma migrate deploy"'); + } else { + console.error(' šŸ‘‰ Error:', e.message); + } + throw e; // rethrow to stop + } + + // 3. Test Writing a dummy lead (optional, rolling back transaction) + console.log('3ļøāƒ£ Testing write permission...'); + await prisma.$transaction(async (tx) => { + const lead = await tx.lead.create({ + data: { + email: 'test_diagnostic_script@example.com', + source: 'diagnostic-script', + reprintCost: 0, + updatesPerYear: 0, + annualSavings: 0 + } + }); + console.log('āœ… Successfully created test lead with ID:', lead.id); + // We purposefully throw an error to rollback this transaction so we don't dirty the DB + throw new Error('ROLLBACK_TEST'); + }).catch((e) => { + if (e.message === 'ROLLBACK_TEST') { + console.log('āœ… Transaction rollback successful (cleaning up test data).'); + } else { + throw e; + } + }); + + console.log('\nšŸŽ‰ ALL CHECKS PASSED! The database is effectively readable and writable.'); + + } catch (error) { + console.error('\nšŸ’„ DIAGNOSTICS FAILED'); + console.error(error); + process.exit(1); + } finally { + await prisma.$disconnect(); + } +} + +main();