NeahStable/scripts/verify-and-fix-prisma-client.ts
2026-01-15 12:46:55 +01:00

82 lines
2.7 KiB
TypeScript

#!/usr/bin/env ts-node
/**
* Script to verify Prisma client is up to date with schema
* Run this to check if externalEventId field is available in Prisma client
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function verifyPrismaClient() {
try {
console.log('Checking if externalEventId field is available in Prisma client...\n');
// Try to access the externalEventId field in the Event model
// If it doesn't exist, TypeScript/Prisma will throw an error at compile time
// But we can check at runtime by trying to query with it
// Check if we can select externalEventId
try {
const testEvent = await prisma.event.findFirst({
select: {
id: true,
title: true,
externalEventId: true,
externalEventUrl: true,
},
});
if (testEvent !== null) {
console.log('✅ Prisma client recognizes externalEventId and externalEventUrl fields');
console.log(' Sample event:', {
id: testEvent.id,
title: testEvent.title,
hasExternalEventId: 'externalEventId' in testEvent,
hasExternalEventUrl: 'externalEventUrl' in testEvent,
});
} else {
console.log('⚠️ No events found, but Prisma client seems to recognize the fields');
}
} catch (error: any) {
if (error.message?.includes('externalEventId') || error.message?.includes('Unknown argument')) {
console.error('❌ Prisma client does NOT recognize externalEventId field');
console.error(' Error:', error.message);
console.log('\n🔧 Solution:');
console.log(' 1. Run: npx prisma generate');
console.log(' 2. Restart your Next.js server');
} else {
throw error;
}
}
// Also check database directly
const dbColumns = await prisma.$queryRaw<Array<{ column_name: string; data_type: string }>>`
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'Event'
AND column_name IN ('externalEventId', 'externalEventUrl')
`;
console.log('\n📊 Database columns:');
if (dbColumns.length === 0) {
console.log(' ❌ externalEventId and externalEventUrl columns NOT found in database');
console.log(' 🔧 Run the migration: npx prisma migrate deploy');
} else {
console.log(' ✅ Database columns exist:');
dbColumns.forEach(col => {
console.log(` - ${col.column_name} (${col.data_type})`);
});
}
await prisma.$disconnect();
} catch (error) {
console.error('Error:', error);
await prisma.$disconnect();
process.exit(1);
}
}
verifyPrismaClient();