Add missing migration for Lead table.

This commit is contained in:
Timo Knuth 2026-01-16 17:40:17 +01:00
parent 9373db8ae6
commit 185c40f470
2 changed files with 65 additions and 1 deletions

2
.gitignore vendored
View File

@ -36,7 +36,7 @@ yarn-error.log*
next-env.d.ts
# prisma
/prisma/migrations/
# docker
docker-compose.override.yml

64
scripts/test-db-lead.ts Normal file
View File

@ -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();